|
| 1 | +package github |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "log" |
| 6 | + |
| 7 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
| 8 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" |
| 9 | +) |
| 10 | + |
| 11 | +func resourceGithubActionsRunnerGroupV0() *schema.Resource { |
| 12 | + return &schema.Resource{ |
| 13 | + SchemaVersion: 0, |
| 14 | + |
| 15 | + Schema: map[string]*schema.Schema{ |
| 16 | + "id": { |
| 17 | + Type: schema.TypeString, |
| 18 | + Computed: true, |
| 19 | + Description: "The ID of the runner group.", |
| 20 | + }, |
| 21 | + "allows_public_repositories": { |
| 22 | + Type: schema.TypeBool, |
| 23 | + Optional: true, |
| 24 | + Default: false, |
| 25 | + Description: "Whether public repositories can be added to the runner group.", |
| 26 | + }, |
| 27 | + "default": { |
| 28 | + Type: schema.TypeBool, |
| 29 | + Computed: true, |
| 30 | + Description: "Whether this is the default runner group.", |
| 31 | + }, |
| 32 | + "etag": { |
| 33 | + Type: schema.TypeString, |
| 34 | + Computed: true, |
| 35 | + Description: "An etag representing the runner group object", |
| 36 | + }, |
| 37 | + "inherited": { |
| 38 | + Type: schema.TypeBool, |
| 39 | + Computed: true, |
| 40 | + Description: "Whether the runner group is inherited from the enterprise level", |
| 41 | + }, |
| 42 | + "name": { |
| 43 | + Type: schema.TypeString, |
| 44 | + Required: true, |
| 45 | + Description: "Name of the runner group.", |
| 46 | + }, |
| 47 | + "runners_url": { |
| 48 | + Type: schema.TypeString, |
| 49 | + Computed: true, |
| 50 | + Description: "The GitHub API URL for the runner group's runners.", |
| 51 | + }, |
| 52 | + "selected_repository_ids": { |
| 53 | + Type: schema.TypeSet, |
| 54 | + Elem: &schema.Schema{ |
| 55 | + Type: schema.TypeInt, |
| 56 | + }, |
| 57 | + Set: schema.HashInt, |
| 58 | + Optional: true, |
| 59 | + Description: "List of repository IDs that can access the runner group.", |
| 60 | + }, |
| 61 | + "selected_repositories_url": { |
| 62 | + Type: schema.TypeString, |
| 63 | + Computed: true, |
| 64 | + Description: "GitHub API URL for the runner group's repositories.", |
| 65 | + }, |
| 66 | + "visibility": { |
| 67 | + Type: schema.TypeString, |
| 68 | + Required: true, |
| 69 | + Description: "The visibility of the runner group.", |
| 70 | + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"all", "selected", "private"}, false)), |
| 71 | + }, |
| 72 | + "restricted_to_workflows": { |
| 73 | + Type: schema.TypeBool, |
| 74 | + Optional: true, |
| 75 | + Default: false, |
| 76 | + Description: "If 'true', the runner group will be restricted to running only the workflows specified in the 'selected_workflows' array. Defaults to 'false'.", |
| 77 | + }, |
| 78 | + "selected_workflows": { |
| 79 | + Type: schema.TypeList, |
| 80 | + Elem: &schema.Schema{Type: schema.TypeString}, |
| 81 | + Optional: true, |
| 82 | + 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'.", |
| 83 | + }, |
| 84 | + }, |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +func resourceGithubActionsRunnerGroupStateUpgradeV0(_ context.Context, rawState map[string]any, _ any) (map[string]any, error) { |
| 89 | + log.Printf("[DEBUG] GitHub Actions Runner Group Attributes before migration: %#v", rawState) |
| 90 | + |
| 91 | + // No transformation needed. The SDK re-encodes selected_workflows from |
| 92 | + // TypeList (index-based keys) to TypeSet (hash-based keys) automatically |
| 93 | + // when it persists the state with the new schema version. |
| 94 | + |
| 95 | + log.Printf("[DEBUG] GitHub Actions Runner Group Attributes after migration: %#v", rawState) |
| 96 | + |
| 97 | + return rawState, nil |
| 98 | +} |
0 commit comments