terraform-provider-github icon indicating copy to clipboard operation
terraform-provider-github copied to clipboard

fix: fix persistent drift in github branch protection resource

Open RoseSecurity opened this issue 10 months ago • 1 comments

Resolves #2243


Before the change?

Within the github_branch_protection resource, I have a restrict_pushes block that allows pushes to the protected branch by fetching the github_user node_id.

  restrict_pushes {
    blocks_creations = var.restrict_pushes_blocks_creations
    push_allowances = var.push_restrictions_enabled ? [
      join("", data.github_user.allowed_user[*].node_id),
    ] : []
  }

Every time I run a plan or apply, it shows drift and that the resource needs to be updated in place although the value remains the same.

Actual Behavior

This is how each plan and apply appears:

  # github_branch_protection.default[0] will be updated in-place
  ~ resource "github_branch_protection" "default" {
        id                              = "BPR_XXXXXXXXXXXX"
        # (10 unchanged attributes hidden)

      ~ restrict_pushes {
          ~ push_allowances  = [
              + "U_XXXXXXXX",
            ]
            # (1 unchanged attribute hidden)
        }

        # (1 unchanged block hidden)
    }

Terraform Version

Terraform v1.5.6 on M1 Mac with integrations/github v6.2.1

Affected Resource(s)

  • github_branch_protection

Terraform Configuration Files

# github_branch_protection.default[0] will be updated in-place
  ~ resource "github_branch_protection" "default" {
        id                              = "BPR_XXXXXXXXXXXX"
        # (10 unchanged attributes hidden)

      ~ restrict_pushes {
          ~ push_allowances  = [
              + "U_XXXXXXXX",
            ]
            # (1 unchanged attribute hidden)
        }

        # (1 unchanged block hidden)
    }

After the change?

No changes. Your infrastructure matches the configuration.

Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.

Pull request checklist

[!NOTE] Existing tests cover this drift fix

  • [ ] Tests for the changes have been added (for bug fixes / features)
  • [X] 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
  • [X] No

RoseSecurity avatar Jan 27 '25 17:01 RoseSecurity

@kfcampbell Any thoughts on this PR?

RoseSecurity avatar May 22 '25 17:05 RoseSecurity