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

[BUG]: Repository 'security_and_analysis' settings are being sent even if they are unset, unchanged, or part of 'lifecycle.ignore_changes' #2252

Open
1 task done
fushi opened this issue May 3, 2024 · 5 comments · May be fixed by #2368
Labels
Status: Up for grabs Issues that are ready to be worked on by anyone Type: Bug Something isn't working as documented

Comments

@fushi
Copy link

fushi commented May 3, 2024

Expected Behavior

If the 'security_and_analysis' block is either unset, unchanged, or ignored by Terraform by using the ignore_changes list in the lifecycle block of a github_repository, then terraform apply should not send that block to the GitHub API.

Actual Behavior

The block above is sent to the GitHub API, which causes an issue even if it isn't a change.

This becomes an issue if/when the repository has an enterprise policy that prevents modifying the advanced security enablement:

│ Error: PATCH https://api.github.com/repos/$ORG_REDACTED/$REPO_REDACTED: 422 An enterprise policy prevented modifying advanced security enablement. Contact your enterprise owner for details. [] │ │ with github_repository.all['$REPO_REDACTED'], │ on main.tf line 1, in resource "github_repository" "all": │ 1: resource "github_repository" "all" {

Terraform Version

Terraform v1.8.2
on darwin_arm64

  • provider registry.terraform.io/hashicorp/aws v5.48.0
  • provider registry.terraform.io/integrations/github v6.2.1

Affected Resource(s)

github_repository

Terraform Configuration Files

resource "github_repository" "all" {
  for_each = var.REPOSITORIES
  
  name                  = each.key
  description           = each.value.description

    lifecycle {
    ignore_changes = [
      # Cannot control these: "An enterprise policy prevented modifying advanced security enablement."
      security_and_analysis
    ]
  }

Steps to Reproduce

No response

Debug Output

2024-05-03T16:11:08.912-0700 [ERROR] provider.terraform-provider-github_v6.2.1: Response contains error diagnostic: @caller=github.com/hashicorp/terraform-plugin-go@v0.22.0/tfprotov5/internal/diag/diagnostics.go:58 tf_req_id=b55abc6e-0f96-7365-adb8-1979a52d852e tf_rpc=ApplyResourceChange tf_resource_type=github_repository @module=sdk.proto diagnostic_detail="" diagnostic_severity=ERROR diagnostic_summary="PATCH https://api.github.com/repos/$ORG_REDACTED/$REPO_REDACTED: 422 An enterprise policy prevented modifying advanced security enablement. Contact your enterprise owner for details. []" tf_proto_version=5.4 tf_provider_addr=provider timestamp=2024-05-03T16:11:08.912-0700

Panic Output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@fushi fushi added Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented labels May 3, 2024
@fushi
Copy link
Author

fushi commented May 3, 2024

curl -L \ -X PATCH \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer $GH_TOKEN" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/$ORG/$REPO \ -d '{"security_and_analysis":{"advanced_security":{"status":"enabled"}}}'

This is the equivalent cURL, and if an enterprise policy prohibits setting this, it will fail with a HTTP 422 even if the "new" setting matches the extant setting

@mukta-puri
Copy link

We are also seeing this issue when destroying a github_repository resource with archive_on_destroy set to true.

@kfcampbell kfcampbell added Status: Up for grabs Issues that are ready to be worked on by anyone and removed Status: Triage This is being looked at and prioritized labels Jun 17, 2024
@chrisharrison
Copy link

We are seeing this issue arise when running a terraform apply that requires modification to the repositories. Weirdly, running the apply again seems to bypass the issue.

@fushi
Copy link
Author

fushi commented Aug 23, 2024

We are seeing this issue arise when running a terraform apply that requires modification to the repositories. Weirdly, running the apply again seems to bypass the issue.

If the resource (repository) is up to date, no change is sent, so it won't complain. It only complains when the repository itself is updated, because it tacks on the extra bit.

@fushi fushi linked a pull request Aug 26, 2024 that will close this issue
4 tasks
@fushi
Copy link
Author

fushi commented Oct 3, 2024

There is a PR that will fix this issue, and it has been available for over 5 weeks without any input from the maintainers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Up for grabs Issues that are ready to be worked on by anyone Type: Bug Something isn't working as documented
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants