Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fixed repository resource churn #2501

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

stevehipwell
Copy link
Contributor

Resolves #2489
Resolves #2495


Before the change?

  • The github_repository resource churned on vulnerability_alerts
  • The github_repository resource churned on pages if build type was workflow

After the change?

  • No churning on the github_repository resource

Pull request checklist

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)

Does this introduce a breaking change?

Please see our docs on breaking changes to help!

  • Yes
  • No

@@ -320,6 +320,7 @@ func resourceGithubRepository() *schema.Resource {
"vulnerability_alerts": {
Type: schema.TypeBool,
Optional: true,
Computed: true,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the documentation, "Computed is often used to represent values that are not user configurable or can not be known at time of terraform plan or apply, such as date of creation or a service specific UUID."

I suppose that Computed is appropriate here since it could be enabled by default at the org level.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is also required in combination with optional if an optional value will be persisted even if it's not been explicitly set.

@@ -619,6 +619,11 @@ func resourceGithubRepositoryCreate(d *schema.ResourceData, meta interface{}) er
}
}

err := updateVulnerabilityAlerts(d, client, ctx, owner, repoName)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems wrong, the return resourceGithubRepositoryRead(d, meta) line below can end up calling updateVulnerabilityAlerts again. Is this change actually needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part of the TF provider is a bit of a mess, AFAIK 3 months later this is required.


func updateVulnerabilityAlerts(d *schema.ResourceData, client *github.Client, ctx context.Context, owner, repoName string) error {
updateVulnerabilityAlerts := client.Repositories.DisableVulnerabilityAlerts
if vulnerabilityAlerts, ok := d.GetOk("vulnerability_alerts"); ok && vulnerabilityAlerts.(bool) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not new behavior, but this treats the absense of vulnerability_alerts = "true" as an alias for vulnerability_alerts = "false".

That is not true when a global org-level policy enables vulnerability alerts by default. Is this desirable behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Lekensteyn this is a pattern used throughout the provider, the GetOk() function is intended to only respond if the value has been set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants