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

github_branch_protection: empty context has no effect on configuration

Open rrey-aviatrix opened this issue 4 years ago • 7 comments

Terraform Version

Terraform v1.1.6
on darwin_amd64
+ provider registry.terraform.io/hashicorp/aws v4.9.0
+ provider registry.terraform.io/integrations/github v4.23.0

Edit: Provider version:

4.26.1

Affected Resource(s)

Please list the resources as a list, for example:

  • github_branch_protection

Terraform Configuration Files

resource "github_repository" "example" {
  name        = "test-checks"
  description = "My awesome codebase"

  auto_init  = true
  visibility = "internal"
}

resource "github_branch_protection" "example" {
  repository_id = github_repository.example.node_id

  pattern          = "main"
  enforce_admins   = true
  allows_deletions = true

  required_status_checks {
    strict = false
    contexts = [
      "ci/travis",
    ]
  }
}```

### Expected Behavior
When having a `github_branch_protection` already applied with at least 1 check, applying a new configuration with an empty context properly reports in the `plan` than the check shall be removed but the  `apply` is actually not changing anything.


### Actual Behavior
Nothing is modified on the branch protection even if the plan properly reported that a check should be removed:

Terraform will perform the following actions:

github_branch_protection.example will be updated in-place

~ resource "github_branch_protection" "example" { id = "BPR_kwDOHmnqNs4BmImO" # (9 unchanged attributes hidden)

  ~ required_status_checks {
      ~ contexts = [
          - "ci/travis",
        ]
        # (1 unchanged attribute hidden)
    }
}

Plan: 0 to add, 1 to change, 0 to destroy.

Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve.

Enter a value: yes

github_branch_protection.example: Modifying... [id=BPR_kwDOHmnqNs4BmImO] github_branch_protection.example: Modifications complete after 3s [id=BPR_kwDOHmnqNs4BmImO]

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.


After the `apply` if you check the repo config from the WUI, the check is still configured on the branch protection.

### Steps to Reproduce
Please list the steps required to reproduce the issue, for example:
1. `terraform apply` with code snippet provided without the "ci/travis" check commented.
2. `terraform apply` with code snippet provided and "ci/travis" commented

rrey-aviatrix avatar Jul 04 '22 07:07 rrey-aviatrix

Hi, same issue with provider registry.terraform.io/integrations/github v4.26.1

ViacheslavKudinov avatar Jul 04 '22 14:07 ViacheslavKudinov

I got the same issue even with the old v4.22.0 release. Only re-creating github_branch_protection helped.

rvoitenko avatar Jul 04 '22 14:07 rvoitenko

We've been debugging this issue as well and it seems that this provider is sending a null value to the GitHub API which is being interpreted as no-change on GitHub's side. Sending an empty array [] to GitHub does achieve the desired result.

cstavro avatar Oct 24 '22 12:10 cstavro

@cstavro is that something you would consider opening up a PR to fix in the provider?

kfcampbell avatar Oct 27 '22 21:10 kfcampbell

It's on my list of things to do. 😀

Currently navigating my org's open source contribution policies before I can get involved.

If someone gets to it before me I certainly won't be upset.

cstavro avatar Oct 27 '22 21:10 cstavro

@nickfloyd @kfcampbell FYI, this issue appears to be a duplicate of #1083.

cwthrivent avatar Dec 15 '22 18:12 cwthrivent

@cwthrivent thanks for the heads up; let's close this issue and continue the conversation there.

kfcampbell avatar Dec 28 '22 06:12 kfcampbell