Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/resources/actions_runner_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ The following arguments are supported:
- `name` - (Required) Name of the runner group
- `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.
- `selected_repository_ids` - (Optional) IDs of the repositories which should be added to the runner group
- `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.
- `selected_workflows` - (Optional) Set of workflows the runner group should be allowed to run. The order of items is not significant. This setting will be ignored unless restricted_to_workflows is set to true.
- `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.
- `allows_public_repositories` - (Optional) Whether public repositories can be added to the runner group. Defaults to false.

Expand All @@ -44,7 +44,7 @@ The following arguments are supported:
- `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. 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.
- `selected_workflows` - Set of workflows the runner group should be allowed to run. The order of items is not significant. This setting will be ignored unless restricted_to_workflows is set to true.

## Import

Expand Down
2 changes: 1 addition & 1 deletion docs/resources/enterprise_actions_runner_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ The following arguments are supported:
- `selected_organization_ids` - (Optional) IDs of the organizations which should be added to the runner group
- `allows_public_repositories` - (Optional) Whether public repositories can be added to the runner group. Defaults to false.
- `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.
- `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.
- `selected_workflows` - (Optional) Set of workflows the runner group should be allowed to run. The order of items is not significant. This setting will be ignored unless restricted_to_workflows is set to true.

## Attributes Reference

Expand Down
15 changes: 12 additions & 3 deletions github/resource_github_actions_runner_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ func resourceGithubActionsRunnerGroup() *schema.Resource {
StateContext: schema.ImportStatePassthroughContext,
},

SchemaVersion: 1,
StateUpgraders: []schema.StateUpgrader{
{
Type: resourceGithubActionsRunnerGroupV0().CoreConfigSchema().ImpliedType(),
Upgrade: resourceGithubActionsRunnerGroupStateUpgradeV0,
Version: 0,
},
},

Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Expand Down Expand Up @@ -87,7 +96,7 @@ func resourceGithubActionsRunnerGroup() *schema.Resource {
Description: "If 'true', the runner group will be restricted to running only the workflows specified in the 'selected_workflows' array. Defaults to 'false'.",
},
"selected_workflows": {
Type: schema.TypeList,
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Optional: true,
Description: "List of workflows the runner group should be allowed to run. This setting will be ignored unless restricted_to_workflows is set to 'true'.",
Expand All @@ -112,7 +121,7 @@ func resourceGithubActionsRunnerGroupCreate(d *schema.ResourceData, meta any) er

selectedWorkflows := []string{}
if workflows, ok := d.GetOk("selected_workflows"); ok {
for _, workflow := range workflows.([]any) {
for _, workflow := range workflows.(*schema.Set).List() {
selectedWorkflows = append(selectedWorkflows, workflow.(string))
}
}
Expand Down Expand Up @@ -316,7 +325,7 @@ func resourceGithubActionsRunnerGroupUpdate(d *schema.ResourceData, meta any) er
selectedWorkflows := []string{}
allowsPublicRepositories := d.Get("allows_public_repositories").(bool)
if workflows, ok := d.GetOk("selected_workflows"); ok {
for _, workflow := range workflows.([]any) {
for _, workflow := range workflows.(*schema.Set).List() {
selectedWorkflows = append(selectedWorkflows, workflow.(string))
}
}
Expand Down
98 changes: 98 additions & 0 deletions github/resource_github_actions_runner_group_migration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package github

import (
"context"
"log"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

func resourceGithubActionsRunnerGroupV0() *schema.Resource {
return &schema.Resource{
SchemaVersion: 0,

Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
Description: "The ID of the runner group.",
},
"allows_public_repositories": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Whether public repositories can be added to the runner group.",
},
"default": {
Type: schema.TypeBool,
Computed: true,
Description: "Whether this is the default runner group.",
},
"etag": {
Type: schema.TypeString,
Computed: true,
Description: "An etag representing the runner group object",
},
"inherited": {
Type: schema.TypeBool,
Computed: true,
Description: "Whether the runner group is inherited from the enterprise level",
},
"name": {
Type: schema.TypeString,
Required: true,
Description: "Name of the runner group.",
},
"runners_url": {
Type: schema.TypeString,
Computed: true,
Description: "The GitHub API URL for the runner group's runners.",
},
"selected_repository_ids": {
Type: schema.TypeSet,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
Set: schema.HashInt,
Optional: true,
Description: "List of repository IDs that can access the runner group.",
},
"selected_repositories_url": {
Type: schema.TypeString,
Computed: true,
Description: "GitHub API URL for the runner group's repositories.",
},
"visibility": {
Type: schema.TypeString,
Required: true,
Description: "The visibility of the runner group.",
ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"all", "selected", "private"}, false)),
},
"restricted_to_workflows": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "If 'true', the runner group will be restricted to running only the workflows specified in the 'selected_workflows' array. Defaults to 'false'.",
},
"selected_workflows": {
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
Optional: true,
Description: "List of workflows the runner group should be allowed to run. This setting will be ignored unless restricted_to_workflows is set to 'true'.",
},
},
}
}

func resourceGithubActionsRunnerGroupStateUpgradeV0(_ context.Context, rawState map[string]any, _ any) (map[string]any, error) {
log.Printf("[DEBUG] GitHub Actions Runner Group Attributes before migration: %#v", rawState)

// No transformation needed. The SDK re-encodes selected_workflows from
// TypeList (index-based keys) to TypeSet (hash-based keys) automatically
// when it persists the state with the new schema version.

log.Printf("[DEBUG] GitHub Actions Runner Group Attributes after migration: %#v", rawState)

return rawState, nil
}
11 changes: 3 additions & 8 deletions github/resource_github_actions_runner_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,11 @@ func TestAccGithubActionsRunnerGroup(t *testing.T) {
githubRepository := state.RootModule().Resources["github_repository.test"].Primary
fullName := githubRepository.Attributes["full_name"]

runnerGroup := state.RootModule().Resources["github_actions_runner_group.test"].Primary
workflowActual := runnerGroup.Attributes["selected_workflows.0"]

workflowExpected := fmt.Sprintf("%s/.github/workflows/test.yml@refs/heads/main", fullName)

if workflowActual != workflowExpected {
return fmt.Errorf("actual selected workflows %s not the same as expected selected workflows %s",
workflowActual, workflowExpected)
}
return nil
return resource.TestCheckTypeSetElemAttr(
"github_actions_runner_group.test", "selected_workflows.*", workflowExpected,
)(state)
},
resource.TestCheckResourceAttr(
"github_actions_runner_group.test", "allows_public_repositories",
Expand Down
15 changes: 12 additions & 3 deletions github/resource_github_enterprise_actions_runner_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ func resourceGithubActionsEnterpriseRunnerGroup() *schema.Resource {
State: resourceGithubActionsEnterpriseRunnerGroupImport,
},

SchemaVersion: 1,
StateUpgraders: []schema.StateUpgrader{
{
Type: resourceGithubActionsEnterpriseRunnerGroupV0().CoreConfigSchema().ImpliedType(),
Upgrade: resourceGithubActionsEnterpriseRunnerGroupStateUpgradeV0,
Version: 0,
},
},

Schema: map[string]*schema.Schema{
"enterprise_slug": {
Type: schema.TypeString,
Expand Down Expand Up @@ -69,7 +78,7 @@ func resourceGithubActionsEnterpriseRunnerGroup() *schema.Resource {
Description: "If 'true', the runner group will be restricted to running only the workflows specified in the 'selected_workflows' array. Defaults to 'false'.",
},
"selected_workflows": {
Type: schema.TypeList,
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Optional: true,
Description: "List of workflows the runner group should be allowed to run. This setting will be ignored unless restricted_to_workflows is set to 'true'.",
Expand Down Expand Up @@ -104,7 +113,7 @@ func resourceGithubActionsEnterpriseRunnerGroupCreate(d *schema.ResourceData, me

selectedWorkflows := []string{}
if workflows, ok := d.GetOk("selected_workflows"); ok {
for _, workflow := range workflows.([]any) {
for _, workflow := range workflows.(*schema.Set).List() {
selectedWorkflows = append(selectedWorkflows, workflow.(string))
}
}
Expand Down Expand Up @@ -291,7 +300,7 @@ func resourceGithubActionsEnterpriseRunnerGroupUpdate(d *schema.ResourceData, me
selectedWorkflows := []string{}
allowsPublicRepositories := d.Get("allows_public_repositories").(bool)
if workflows, ok := d.GetOk("selected_workflows"); ok {
for _, workflow := range workflows.([]any) {
for _, workflow := range workflows.(*schema.Set).List() {
selectedWorkflows = append(selectedWorkflows, workflow.(string))
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package github

import (
"context"
"log"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

func resourceGithubActionsEnterpriseRunnerGroupV0() *schema.Resource {
return &schema.Resource{
SchemaVersion: 0,

Schema: map[string]*schema.Schema{
"enterprise_slug": {
Type: schema.TypeString,
Required: true,
Description: "The slug of the enterprise.",
},
"allows_public_repositories": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Whether public repositories can be added to the runner group.",
},
"default": {
Type: schema.TypeBool,
Computed: true,
Description: "Whether this is the default runner group.",
},
"etag": {
Type: schema.TypeString,
Computed: true,
Description: "An etag representing the runner group object",
},
"name": {
Type: schema.TypeString,
Required: true,
Description: "Name of the runner group.",
},
"runners_url": {
Type: schema.TypeString,
Computed: true,
Description: "The GitHub API URL for the runner group's runners.",
},
"visibility": {
Type: schema.TypeString,
Required: true,
Description: "The visibility of the runner group.",
ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"all", "selected"}, false)),
},
"restricted_to_workflows": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "If 'true', the runner group will be restricted to running only the workflows specified in the 'selected_workflows' array. Defaults to 'false'.",
},
"selected_workflows": {
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
Optional: true,
Description: "List of workflows the runner group should be allowed to run. This setting will be ignored unless restricted_to_workflows is set to 'true'.",
},
"selected_organization_ids": {
Type: schema.TypeSet,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
Set: schema.HashInt,
Optional: true,
Description: "List of organization IDs that can access the runner group.",
},
"selected_organizations_url": {
Type: schema.TypeString,
Computed: true,
Description: "GitHub API URL for the runner group's organizations.",
},
},
}
}

func resourceGithubActionsEnterpriseRunnerGroupStateUpgradeV0(_ context.Context, rawState map[string]any, _ any) (map[string]any, error) {
log.Printf("[DEBUG] GitHub Enterprise Actions Runner Group Attributes before migration: %#v", rawState)

// No transformation needed. The SDK re-encodes selected_workflows from
// TypeList (index-based keys) to TypeSet (hash-based keys) automatically
// when it persists the state with the new schema version.

log.Printf("[DEBUG] GitHub Enterprise Actions Runner Group Attributes after migration: %#v", rawState)

return rawState, nil
}