Conversation
Enables a GitHub App as a custom deployment protection rule on an environment (the deployment_protection_rule gate), which the provider previously could not express declaratively — resolves integrations#2225. CRUD + import over go-github's Create/Get/DisableCustomDeploymentProtectionRule; schema is repository + environment + integration_id, mirroring the existing github_repository_environment_deployment_policy resource. Based on v6.13.0.
|
👋 Hi, and thank you for this contribution! This repo is maintained by GitHub and community members on a best-effort basis. We'll get to this as soon as we can. You can help us prioritize by joining the discussion on open issues and PRs, sharing details on the changes you need, and reviewing other contributions. 🤖 This is an automated message. |
InternalValidate rejects the resource: with no UpdateContext, every attribute must be ForceNew. repository was Required-only. Mark it ForceNew and drop the now-redundant diffRepository CustomizeDiff (it keys off a repository_id this resource doesn't have). `go test -run TestProvider` (InternalValidate) passes.
main upgraded go-github v88 -> v89; the CreateCustomDeploymentProtectionRule request type moved packages. Match the rest of the provider.
| @@ -0,0 +1,67 @@ | |||
| --- | |||
There was a problem hiding this comment.
The documentation should be generated through templates after running make generatedocs.
I've tested locally and deleting it is actually not working.
I would expect the following templates:
- templates/resources/repository_environment_deployment_protection_rule.md.tmpl
- examples/resources/repository_environment_deployment_protection_rule/example_1.tf (usage)
- examples/resources/repository_environment_deployment_protection_rule/example_2.tf (import block)
Look into templates/resources/repository_environment_deployment_policy.md.tmpl for example
There was a problem hiding this comment.
Missing tests resource_github_repository_environment_deployment_protection_rule_test.go with TestAccGithubRepositoryEnvironmentDeploymentProtectionRule
| } | ||
| d.SetId(id) | ||
|
|
||
| return resourceGithubRepositoryEnvironmentDeploymentProtectionRuleRead(ctx, d, m) |
There was a problem hiding this comment.
// Never call Read at end of Create, set any Computed fields in Create
| ) | ||
|
|
||
| func resourceGithubRepositoryEnvironmentDeploymentProtectionRule() *schema.Resource { | ||
| return &schema.Resource{ |
There was a problem hiding this comment.
This resource is missing a Description field used for the documentation generation
| func resourceGithubRepositoryEnvironmentDeploymentProtectionRule() *schema.Resource { | ||
| return &schema.Resource{ | ||
| Schema: map[string]*schema.Schema{ | ||
| "repository": { |
There was a problem hiding this comment.
You should have a computed repository_id to be resilient to repository name changes
| rule, _, err := client.Repositories.GetCustomDeploymentProtectionRule(ctx, owner, repoName, url.PathEscape(envName), ruleID) | ||
| if err != nil { | ||
| var ghErr *github.ErrorResponse | ||
| if errors.As(err, &ghErr) { |
There was a problem hiding this comment.
Please use errors.AsType*github.ErrorResponse instead
| return diag.FromErr(err) | ||
| } | ||
| if rule.App != nil { | ||
| if err := d.Set("integration_id", int(rule.App.GetID())); err != nil { |
There was a problem hiding this comment.
In case of error, this would keep the old value in state?
| return diag.FromErr(fmt.Errorf("invalid rule id: %s", ruleIDStr)) | ||
| } | ||
|
|
||
| _, err = client.Repositories.DisableCustomDeploymentProtectionRule(ctx, owner, repoName, url.PathEscape(envName), ruleID) |
There was a problem hiding this comment.
You should treat 404 as deleted
|
@stockmaj let me know if you are willing to continue this pull request. |
Summary
Adds a
github_repository_environment_deployment_protection_ruleresource that enables a GitHub App as a custom deployment protection rule on an environment — thedeployment_protection_rulegate. The provider can currently manage required reviewers and branch policies on an environment, but has no way to declaratively attach an App-based deployment protection rule.Resolves #2225.
Details
CreateCustomDeploymentProtectionRule/GetCustomDeploymentProtectionRule/DisableCustomDeploymentProtectionRule.repository+environment+integration_id(the App's ID), mirroring the existinggithub_repository_environment_deployment_policyresource for consistency.<repository>:<environment>:<rule_id>.docs/resources/.Branch is cut from the
v6.13.0release.