Skip to content

Commit 0f4221f

Browse files
authored
Make allows_public_repositories attribute on github_actions_runner_group modifiable (#1705)
* fix merge conflict * make allows_public_repositories settable as argument * fix formatting * added test, fixed test for selected_workflows * fix formatting
1 parent f280fb5 commit 0f4221f

3 files changed

+70
-18
lines changed

github/resource_github_actions_runner_group.go

+15-10
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ func resourceGithubActionsRunnerGroup() *schema.Resource {
2525
Schema: map[string]*schema.Schema{
2626
"allows_public_repositories": {
2727
Type: schema.TypeBool,
28-
Computed: true,
28+
Optional: true,
29+
Default: false,
2930
Description: "Whether public repositories can be added to the runner group.",
3031
},
3132
"default": {
@@ -101,6 +102,7 @@ func resourceGithubActionsRunnerGroupCreate(d *schema.ResourceData, meta interfa
101102
restrictedToWorkflows := d.Get("restricted_to_workflows").(bool)
102103
visibility := d.Get("visibility").(string)
103104
selectedRepositories, hasSelectedRepositories := d.GetOk("selected_repository_ids")
105+
allowsPublicRepositories := d.Get("allows_public_repositories").(bool)
104106

105107
selectedWorkflows := []string{}
106108
if workflows, ok := d.GetOk("selected_workflows"); ok {
@@ -128,11 +130,12 @@ func resourceGithubActionsRunnerGroupCreate(d *schema.ResourceData, meta interfa
128130
runnerGroup, resp, err := client.Actions.CreateOrganizationRunnerGroup(ctx,
129131
orgName,
130132
github.CreateRunnerGroupRequest{
131-
Name: &name,
132-
Visibility: &visibility,
133-
RestrictedToWorkflows: &restrictedToWorkflows,
134-
SelectedRepositoryIDs: selectedRepositoryIDs,
135-
SelectedWorkflows: selectedWorkflows,
133+
Name: &name,
134+
Visibility: &visibility,
135+
RestrictedToWorkflows: &restrictedToWorkflows,
136+
SelectedRepositoryIDs: selectedRepositoryIDs,
137+
SelectedWorkflows: selectedWorkflows,
138+
AllowsPublicRepositories: &allowsPublicRepositories,
136139
},
137140
)
138141
if err != nil {
@@ -254,17 +257,19 @@ func resourceGithubActionsRunnerGroupUpdate(d *schema.ResourceData, meta interfa
254257
visibility := d.Get("visibility").(string)
255258
restrictedToWorkflows := d.Get("restricted_to_workflows").(bool)
256259
selectedWorkflows := []string{}
260+
allowsPublicRepositories := d.Get("allows_public_repositories").(bool)
257261
if workflows, ok := d.GetOk("selected_workflows"); ok {
258262
for _, workflow := range workflows.([]interface{}) {
259263
selectedWorkflows = append(selectedWorkflows, workflow.(string))
260264
}
261265
}
262266

263267
options := github.UpdateRunnerGroupRequest{
264-
Name: &name,
265-
Visibility: &visibility,
266-
RestrictedToWorkflows: &restrictedToWorkflows,
267-
SelectedWorkflows: selectedWorkflows,
268+
Name: &name,
269+
Visibility: &visibility,
270+
RestrictedToWorkflows: &restrictedToWorkflows,
271+
SelectedWorkflows: selectedWorkflows,
272+
AllowsPublicRepositories: &allowsPublicRepositories,
268273
}
269274

270275
runnerGroupID, err := strconv.ParseInt(d.Id(), 10, 64)

github/resource_github_actions_runner_group_test.go

+49-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package github
22

33
import (
44
"fmt"
5+
"github.com/hashicorp/terraform-plugin-sdk/terraform"
56
"testing"
67

78
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
@@ -21,13 +22,38 @@ func TestAccGithubActionsRunnerGroup(t *testing.T) {
2122
resource "github_repository" "test" {
2223
name = "tf-acc-test-%s"
2324
vulnerability_alerts = false
25+
auto_init = true
26+
}
27+
28+
resource "github_branch" "test" {
29+
repository = github_repository.test.name
30+
branch = "test"
31+
}
32+
33+
resource "github_branch_default" "default"{
34+
repository = github_repository.test.name
35+
branch = github_branch.test.branch
36+
}
37+
38+
resource "github_repository_file" "workflow_file" {
39+
depends_on = [github_branch_default.default]
40+
repository = github_repository.test.name
41+
file = ".github/workflows/test.yml"
42+
content = ""
43+
commit_message = "Managed by Terraform"
44+
commit_author = "Terraform User"
45+
commit_email = "[email protected]"
46+
overwrite_on_create = true
2447
}
2548
2649
resource "github_actions_runner_group" "test" {
50+
depends_on = [github_repository_file.workflow_file]
51+
2752
name = github_repository.test.name
2853
visibility = "all"
2954
restricted_to_workflows = true
30-
selected_workflows = [".github/workflows/test.yml"]
55+
selected_workflows = ["${github_repository.test.full_name}/.github/workflows/test.yml@refs/heads/${github_branch.test.branch}"]
56+
allows_public_repositories = true
3157
}
3258
`, randomID)
3359

@@ -48,8 +74,28 @@ func TestAccGithubActionsRunnerGroup(t *testing.T) {
4874
"true",
4975
),
5076
resource.TestCheckResourceAttr(
51-
"github_actions_runner_group.test", "selected_workflows",
52-
"[\".github/workflows/test.yml\"]",
77+
"github_actions_runner_group.test", "selected_workflows.#",
78+
"1",
79+
),
80+
func(state *terraform.State) error {
81+
82+
githubRepository := state.RootModule().Resources["github_repository.test"].Primary
83+
fullName := githubRepository.Attributes["full_name"]
84+
85+
runnerGroup := state.RootModule().Resources["github_actions_runner_group.test"].Primary
86+
workflowActual := runnerGroup.Attributes["selected_workflows.0"]
87+
88+
workflowExpected := fmt.Sprintf("%s/.github/workflows/test.yml@refs/heads/test", fullName)
89+
90+
if workflowActual != workflowExpected {
91+
return fmt.Errorf("actual selected workflows %s not the same as expected selected workflows %s",
92+
workflowActual, workflowExpected)
93+
}
94+
return nil
95+
},
96+
resource.TestCheckResourceAttr(
97+
"github_actions_runner_group.test", "allows_public_repositories",
98+
"true",
5399
),
54100
)
55101

website/docs/r/actions_runner_group.html.markdown

+6-5
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ resource "github_actions_runner_group" "example" {
2828

2929
The following arguments are supported:
3030

31-
* `name` - (Required) Name of the runner group
32-
* `restricted_to_workflows` - (Optional) If true, the runner group will be restricted to running only the workflows specified in the selected_workflows array. Defaults to false.
33-
* `selected_repository_ids` - (Optional) IDs of the repositories which should be added to the runner group
34-
* `selected_workflows` - (Optional) List of workflows the runner group should be allowed to run. This setting will be ignored unless restricted_to_workflows is set to true.
35-
* `visibility` - (Optional) Visibility of a runner group. Whether the runner group can include `all`, `selected`, or `private` repositories. A value of `private` is not currently supported due to limitations in the GitHub API.
31+
* `name` - (Required) Name of the runner group
32+
* `restricted_to_workflows` - (Optional) If true, the runner group will be restricted to running only the workflows specified in the selected_workflows array. Defaults to false.
33+
* `selected_repository_ids` - (Optional) IDs of the repositories which should be added to the runner group
34+
* `selected_workflows` - (Optional) List of workflows the runner group should be allowed to run. This setting will be ignored unless restricted_to_workflows is set to true.
35+
* `visibility` - (Optional) Visibility of a runner group. Whether the runner group can include `all`, `selected`, or `private` repositories. A value of `private` is not currently supported due to limitations in the GitHub API.
36+
* `allows_public_repositories` - (Optional) Whether public repositories can be added to the runner group. Defaults to false.
3637

3738
## Attributes Reference
3839

0 commit comments

Comments
 (0)