From 7f832eaf3262c8992aec8807de00c8bc5e3045a0 Mon Sep 17 00:00:00 2001 From: bob-bins Date: Sun, 6 Nov 2022 21:32:43 -0800 Subject: [PATCH 1/5] issue #1332: support workflow restrictions in github_actions_runner_group --- github/resource_github_actions_runner_group.go | 4 ++++ go.mod | 1 + 2 files changed, 5 insertions(+) diff --git a/github/resource_github_actions_runner_group.go b/github/resource_github_actions_runner_group.go index 2abbed1ba9..55b36f8bc2 100644 --- a/github/resource_github_actions_runner_group.go +++ b/github/resource_github_actions_runner_group.go @@ -118,6 +118,8 @@ func resourceGithubActionsRunnerGroupCreate(d *schema.ResourceData, meta interfa d.Set("selected_repositories_url", runnerGroup.GetSelectedRepositoriesURL()) d.Set("visibility", runnerGroup.GetVisibility()) d.Set("selected_repository_ids", selectedRepositoryIDs) // Note: runnerGroup has no method to get selected repository IDs + d.Set("restricted_to_workflows", runnerGroup.GetRestrictedToWorkflows()) + d.Set("selected_workflows", runnerGroup.SelectedWorkflows) return resourceGithubActionsRunnerGroupRead(d, meta) } @@ -173,6 +175,8 @@ func resourceGithubActionsRunnerGroupRead(d *schema.ResourceData, meta interface d.Set("runners_url", runnerGroup.GetRunnersURL()) d.Set("selected_repositories_url", runnerGroup.GetSelectedRepositoriesURL()) d.Set("visibility", runnerGroup.GetVisibility()) + d.Set("restricted_to_workflows", runnerGroup.GetRestrictedToWorkflows()) + d.Set("selected_workflows", runnerGroup.SelectedWorkflows) selectedRepositoryIDs := []int64{} options := github.ListOptions{ diff --git a/go.mod b/go.mod index f481cc7b28..3541fb4eb6 100644 --- a/go.mod +++ b/go.mod @@ -75,6 +75,7 @@ require ( github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4 // indirect github.com/google/go-cmp v0.5.9 // indirect github.com/google/go-querystring v1.1.0 // indirect + github.com/google/go-github/v48 v48.1.0 github.com/google/uuid v1.3.0 // indirect github.com/googleapis/gax-go/v2 v2.4.0 // indirect github.com/gordonklaus/ineffassign v0.0.0-20210914165742-4cc7213b9bc8 // indirect From c86eb450d46aaf270962dfc08461b03c4b5fac7d Mon Sep 17 00:00:00 2001 From: bob-bins Date: Wed, 4 Jan 2023 16:52:38 -0800 Subject: [PATCH 2/5] add test and fix unrelated typo --- CONTRIBUTING.md | 4 ++-- github/resource_github_actions_runner_group_test.go | 10 ++++++++++ go.mod | 1 - website/docs/r/repository.html.markdown | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d22ad02d36..d424d3547c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -34,7 +34,7 @@ Once you have the repository cloned, there's a couple of additional steps you'll - If you haven't already, [create a GitHub organization you can use for testing](#github-organization). - Optional: some may find it beneficial to create a test user as well in order to avoid potential rate-limiting issues on your main account. - - Your organization _must_ have a repository called `terraform-module-template`. The [terraformtesting/terraform-template-module](https://github.com/terraformtesting/terraform-template-module) repo is a good, re-usable example. + - Your organization _must_ have a repository called `terraform-template-module`. The [terraformtesting/terraform-template-module](https://github.com/terraformtesting/terraform-template-module) repo is a good, re-usable example. - You _must_ make sure that the "Template Repository" item in Settings is checked for this repo. - If you haven't already, [generate a Personal Access Token (PAT) for authenticating your test runs](#github-personal-access-token). - Export the necessary configuration for authenticating your provider with GitHub @@ -218,7 +218,7 @@ Once the token has been created, it must be exported in your environment as `GIT If you do not have an organization already that you are comfortable running tests against, you will need to [create one](https://help.github.com/en/articles/creating-a-new-organization-from-scratch). The free "Team for Open Source" org type is fine for these tests. The name of the organization must then be exported in your environment as `GITHUB_ORGANIZATION`. -Make sure that your organization has a `terraform-module-template` repository ([terraformtesting/terraform-template-module](https://github.com/terraformtesting/terraform-template-module) is an example you can clone) and that its "Template repository" item in Settings is checked. +Make sure that your organization has a `terraform-template-module` repository ([terraformtesting/terraform-template-module](https://github.com/terraformtesting/terraform-template-module) is an example you can clone) and that its "Template repository" item in Settings is checked. If you are interested in using and/or testing Github's [Team synchronization](https://help.github.com/en/github/setting-up-and-managing-organizations-and-teams/synchronizing-teams-between-your-identity-provider-and-github) feature, please contact a maintainer as special arrangements can be made for your convenience. diff --git a/github/resource_github_actions_runner_group_test.go b/github/resource_github_actions_runner_group_test.go index 43a258c770..600e11786e 100644 --- a/github/resource_github_actions_runner_group_test.go +++ b/github/resource_github_actions_runner_group_test.go @@ -26,6 +26,8 @@ func TestAccGithubActionsRunnerGroup(t *testing.T) { resource "github_actions_runner_group" "test" { name = github_repository.test.name visibility = "all" + restricted_to_workflows = true + selected_workflows = [".github/workflows/test.yml"] } `, randomID) @@ -41,6 +43,14 @@ func TestAccGithubActionsRunnerGroup(t *testing.T) { "github_actions_runner_group.test", "visibility", "all", ), + resource.TestCheckResourceAttr( + "github_actions_runner_group.test", "restricted_to_workflows", + "true", + ), + resource.TestCheckResourceAttr( + "github_actions_runner_group.test", "selected_workflows", + "[\".github/workflows/test.yml\"]", + ), ) testCase := func(t *testing.T, mode string) { diff --git a/go.mod b/go.mod index 3541fb4eb6..f481cc7b28 100644 --- a/go.mod +++ b/go.mod @@ -75,7 +75,6 @@ require ( github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4 // indirect github.com/google/go-cmp v0.5.9 // indirect github.com/google/go-querystring v1.1.0 // indirect - github.com/google/go-github/v48 v48.1.0 github.com/google/uuid v1.3.0 // indirect github.com/googleapis/gax-go/v2 v2.4.0 // indirect github.com/gordonklaus/ineffassign v0.0.0-20210914165742-4cc7213b9bc8 // indirect diff --git a/website/docs/r/repository.html.markdown b/website/docs/r/repository.html.markdown index 5c0c8802d2..957a0dc5eb 100644 --- a/website/docs/r/repository.html.markdown +++ b/website/docs/r/repository.html.markdown @@ -21,7 +21,7 @@ resource "github_repository" "example" { template { owner = "github" - repository = "terraform-module-template" + repository = "terraform-template-module" include_all_branches = true } } From 8c7edb644ffe7db823ce21f6358ac14ef22763fb Mon Sep 17 00:00:00 2001 From: bob-bins Date: Sat, 7 Jan 2023 11:51:12 -0800 Subject: [PATCH 3/5] * update resourceGithubActionsRunnerGroup schema * update documentation with new params --- github/resource_github_actions_runner_group.go | 9 +++++++++ website/docs/r/actions_runner_group.html.markdown | 2 ++ 2 files changed, 11 insertions(+) diff --git a/github/resource_github_actions_runner_group.go b/github/resource_github_actions_runner_group.go index 55b36f8bc2..8939b12bc0 100644 --- a/github/resource_github_actions_runner_group.go +++ b/github/resource_github_actions_runner_group.go @@ -64,6 +64,15 @@ func resourceGithubActionsRunnerGroup() *schema.Resource { Required: true, ValidateFunc: validation.StringInSlice([]string{"all", "selected", "private"}, false), }, + "restricted_to_workflows": { + Type: schema.TypeBool, + Computed: true, + }, + "selected_workflows": { + Type: schema.TypeList, + Elem: &schema.Schema{Type: schema.TypeString}, + Computed: true, + }, }, } } diff --git a/website/docs/r/actions_runner_group.html.markdown b/website/docs/r/actions_runner_group.html.markdown index 941c6eef6c..f4b341b9e6 100644 --- a/website/docs/r/actions_runner_group.html.markdown +++ b/website/docs/r/actions_runner_group.html.markdown @@ -42,6 +42,8 @@ The following arguments are supported: * `selected_repository_ids` - List of repository IDs that can access the runner group * `selected_repositories_url` - Github API URL for the runner group's repositories * `visibility` - The visibility of the runner group +* `restricted_to_workflows` - If true, the runner group will be restricted to running only the workflows specified in the selected_workflows array +* `selected_workflows` - List of workflows the runner group should be allowed to run. This setting will be ignored unless restricted_to_workflows is set to true. ## Import From 995019fd11cfca77b0de3986035ed0f842d9c6ad Mon Sep 17 00:00:00 2001 From: bob-bins Date: Wed, 11 Jan 2023 17:28:26 -0800 Subject: [PATCH 4/5] update restricted_to_workflows description --- website/docs/r/actions_runner_group.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/actions_runner_group.html.markdown b/website/docs/r/actions_runner_group.html.markdown index f4b341b9e6..9aa233208a 100644 --- a/website/docs/r/actions_runner_group.html.markdown +++ b/website/docs/r/actions_runner_group.html.markdown @@ -42,7 +42,7 @@ The following arguments are supported: * `selected_repository_ids` - List of repository IDs that can access the runner group * `selected_repositories_url` - Github API URL for the runner group's repositories * `visibility` - The visibility of the runner group -* `restricted_to_workflows` - If true, the runner group will be restricted to running only the workflows specified in the selected_workflows array +* `restricted_to_workflows` - If true, the runner group will be restricted to running only the workflows specified in the selected_workflows array. Defaults to false. * `selected_workflows` - List of workflows the runner group should be allowed to run. This setting will be ignored unless restricted_to_workflows is set to true. ## Import From 216906ca1ba2983ece19df2effe938d32e950f37 Mon Sep 17 00:00:00 2001 From: bob-bins Date: Wed, 11 Jan 2023 17:31:26 -0800 Subject: [PATCH 5/5] minor formatting --- github/resource_github_actions_runner_group_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/github/resource_github_actions_runner_group_test.go b/github/resource_github_actions_runner_group_test.go index 600e11786e..9cacb7c0b4 100644 --- a/github/resource_github_actions_runner_group_test.go +++ b/github/resource_github_actions_runner_group_test.go @@ -26,8 +26,8 @@ func TestAccGithubActionsRunnerGroup(t *testing.T) { resource "github_actions_runner_group" "test" { name = github_repository.test.name visibility = "all" - restricted_to_workflows = true - selected_workflows = [".github/workflows/test.yml"] + restricted_to_workflows = true + selected_workflows = [".github/workflows/test.yml"] } `, randomID)