Skip to content
Merged
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
24 changes: 20 additions & 4 deletions github/resource_github_actions_organization_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ func resourceGithubActionsOrganizationPermissions() *schema.Resource {
},
},
},
"sha_pinning_required": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "Whether pinning to a specific SHA is required for all actions and reusable workflows in an organization.",
},
},
}
}
Expand Down Expand Up @@ -147,12 +153,18 @@ func resourceGithubActionsOrganizationPermissionsCreateOrUpdate(d *schema.Resour
allowedActions := d.Get("allowed_actions").(string)
enabledRepositories := d.Get("enabled_repositories").(string)

actionsPermissions := github.ActionsPermissions{
AllowedActions: &allowedActions,
EnabledRepositories: &enabledRepositories,
}

if v, ok := d.GetOk("sha_pinning_required"); ok {
actionsPermissions.SHAPinningRequired = github.Ptr(v.(bool))
}

_, _, err = client.Actions.UpdateActionsPermissions(ctx,
orgName,
github.ActionsPermissions{
AllowedActions: &allowedActions,
EnabledRepositories: &enabledRepositories,
})
actionsPermissions)
if err != nil {
return err
}
Expand Down Expand Up @@ -280,6 +292,10 @@ func resourceGithubActionsOrganizationPermissionsRead(d *schema.ResourceData, me
return err
}

if err = d.Set("sha_pinning_required", actionsPermissions.GetSHAPinningRequired()); err != nil {
return err
}

return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func TestAccGithubActionsOrganizationPermissions(t *testing.T) {
enabledRepositories := "selected"
githubOwnedAllowed := true
verifiedAllowed := true
shaPinningRequired := true
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
repoName := fmt.Sprintf("%srepo-act-org-perm-%s", testResourcePrefix, randomID)

Expand All @@ -64,11 +65,12 @@ func TestAccGithubActionsOrganizationPermissions(t *testing.T) {
patterns_allowed = ["actions/cache@*", "actions/checkout@*"]
verified_allowed = %t
}
sha_pinning_required = %t
enabled_repositories_config {
repository_ids = [github_repository.test.repo_id]
}
}
`, repoName, allowedActions, enabledRepositories, githubOwnedAllowed, verifiedAllowed)
`, repoName, allowedActions, enabledRepositories, githubOwnedAllowed, verifiedAllowed, shaPinningRequired)

check := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
Expand Down
14 changes: 14 additions & 0 deletions github/resource_github_actions_repository_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ func resourceGithubActionsRepositoryPermissions() *schema.Resource {
Description: "The GitHub repository.",
ValidateDiagFunc: toDiagFunc(validation.StringLenBetween(1, 100), "repository"),
},
"sha_pinning_required": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "Whether pinning to a specific SHA is required for all actions and reusable workflows in a repository.",
},
},
}
}
Expand Down Expand Up @@ -125,6 +131,10 @@ func resourceGithubActionsRepositoryPermissionsCreateOrUpdate(d *schema.Resource
repoActionPermissions.AllowedActions = &allowedActions
}

if v, ok := d.GetOk("sha_pinning_required"); ok {
repoActionPermissions.SHAPinningRequired = github.Ptr(v.(bool))
}

_, _, err := client.Repositories.UpdateActionsPermissions(ctx,
owner,
repoName,
Expand Down Expand Up @@ -210,6 +220,10 @@ func resourceGithubActionsRepositoryPermissionsRead(d *schema.ResourceData, meta
return err
}

if err = d.Set("sha_pinning_required", actionsPermissions.GetSHAPinningRequired()); err != nil {
return err
}

return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func TestAccGithubActionsRepositoryPermissions(t *testing.T) {
allowedActions := "selected"
githubOwnedAllowed := true
verifiedAllowed := true
shaPinningRequired := true
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
repoName := fmt.Sprintf("%srepo-act-perms-%s", testResourcePrefix, randomID)

Expand All @@ -66,9 +67,10 @@ func TestAccGithubActionsRepositoryPermissions(t *testing.T) {
patterns_allowed = ["actions/cache@*", "actions/checkout@*"]
verified_allowed = %t
}
sha_pinning_required = %t
repository = github_repository.test.name
}
`, repoName, allowedActions, githubOwnedAllowed, verifiedAllowed)
`, repoName, allowedActions, githubOwnedAllowed, verifiedAllowed, shaPinningRequired)

check := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
Expand Down