(fix): add the handlers for empty values - #2404
Conversation
This commit add the control of the allowed_repositories and the allowed_actions for the actions_permission resources. Without them the API calls will fail because the allowed_actions and the allowed_repository are passed to the API with a null value. The patch removes them from the HTTP request.
|
Is there an issue that this resolves? Can you add test cases to validate this behavior for the future? |
|
@kfcampbell I created the issue for it, happy to add further details if required. #2405 |
|
👋 Hey Friends, this pull request has been automatically marked as |
|
Adding a comment here to flag this and hopefully get it re-opened. At the moment, this not being supported means the provider docs are just plain wrong. i.e. https://registry.terraform.io/providers/integrations/github/latest/docs/resources/actions_organization_permissions states that I should be a able to provide When organisations manage the entirety of their SCM in Terraform, having the ability to disable GitHub Actions in favour of another CI/CD Platform they already utilise is a valuable and necessary thing. The alternative is tool creep. Especially if Terraform is being used to spin up multiple organisations within an Enterprise, and you want the ability to toggle if GitHub Actions is allowed on a per-organisation basis. Please may I request either:
|
|
Hey @mauromedda |
| if allowedActions != "" { | ||
| _, _, err = client.Actions.EditActionsPermissions(ctx, | ||
| orgName, | ||
| github.ActionsPermissions{ | ||
| AllowedActions: &allowedActions, | ||
| EnabledRepositories: &enabledRepositories, | ||
| }) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } else { | ||
| _, _, err = client.Actions.EditActionsPermissions(ctx, | ||
| orgName, | ||
| github.ActionsPermissions{ | ||
| EnabledRepositories: &enabledRepositories, | ||
| }) | ||
| if err != nil { | ||
| return err | ||
| } |
There was a problem hiding this comment.
We can reduce duplication here by setting AllowedActions conditionally
| if allowedActions != "" { | |
| _, _, err = client.Actions.EditActionsPermissions(ctx, | |
| orgName, | |
| github.ActionsPermissions{ | |
| AllowedActions: &allowedActions, | |
| EnabledRepositories: &enabledRepositories, | |
| }) | |
| if err != nil { | |
| return err | |
| } | |
| } else { | |
| _, _, err = client.Actions.EditActionsPermissions(ctx, | |
| orgName, | |
| github.ActionsPermissions{ | |
| EnabledRepositories: &enabledRepositories, | |
| }) | |
| if err != nil { | |
| return err | |
| } | |
| actionsPermissions := github.ActionsPermissions{ | |
| EnabledRepositories: github.Ptr(enabledRepositories), | |
| } | |
| allowedActions, ok := d.GetOk("allowed_actions") | |
| if ok { | |
| actionsPermissions.AllowedActions = github.Ptr(allowedActions.(string)) | |
| } | |
| _, _, err = client.Actions.EditActionsPermissions(ctx, | |
| orgName, | |
| actionsPermissions) | |
| if err != nil { | |
| return err | |
| } |
| t.Run("with an organization account", func(t *testing.T) { | ||
| testCase(t, organization) | ||
| }) | ||
| }) |
There was a problem hiding this comment.
| }) | |
| resource.Test(t, resource.TestCase{ | |
| PreCheck: func() { skipUnlessOrgs(t) }, | |
| ProviderFactories: providerFactories, | |
| Steps: []resource.TestStep{ | |
| { | |
| Config: config, | |
| Check: check, | |
| }, | |
| }, | |
| }) | |
This commit add the control of the allowed_repositories and the allowed_actions for the actions_permission resources. Without them the API calls will fail because the allowed_actions and the allowed_repository are passed to the API with a null value.
The patch removes them from the HTTP request.
Resolves #2405
Before the change?
After the change?
Pull request checklist
Does this introduce a breaking change?
Please see our docs on breaking changes to help!