integrations / terraform-provider-github

Terraform GitHub provider
https://www.terraform.io/docs/providers/github/
MIT License
863 stars 708 forks source link

[BUG]: github_repository_ruleset can create bypass_actors but cannot delete #2269

Open Trikenstein opened 1 month ago

Trikenstein commented 1 month ago

Expected Behavior

Using Terraform provider integrations/github version 6.2.1

A github_repository_ruleset resource has been created with a bypass_actors attribute. Later on, the bypass_actors attribute is removed. The Terraform plan confirm the deletion:

# module.CITest.github_repository_ruleset.protection-on-default will be updated in-place
~ resource "github_repository_ruleset" "protection-on-default" {
     id          = "791751"
    name        = "Protections (Default Branch)"
    # (6 unchanged attributes hidden)

    - bypass_actors {
        - actor_id    = 123456789 -> null
        - actor_type  = "Team" -> null
        - bypass_mode = "always" -> null
      }
}

The Terraform apply confirm modification successful

module.CITest.github_repository_ruleset.protection-on-default: Modifications complete after 2s [id=791751]

Using Github UI on the "CITest" repo, Settings, Rules/Ruleset. Select the ruleset. The bypasser still exists.

Actual Behavior

Terraform apply was not able to delete the bypass_actors attribute. And yet the output showed the operation as successful. Re-running a Terraform plan shows the same "updated in-place" shown above. Which means the terraform apply did not change the github_repository_ruleset to remove the existing value in bypass_actors.

The workaround is to use Github UI to delete the bypasser manually.

Terraform Version

Terraform v1.8.3
on linux_amd64
+ provider registry.terraform.io/hashicorp/azurerm v3.103.1
+ provider registry.terraform.io/integrations/github v6.2.1

Affected Resource(s)

Terraform Configuration Files

resource "github_repository_ruleset" "protection-on-default" {
  name        = "Protections (Default Branch)"
  repository  = github_repository.repository.name
  target      = "branch"
  enforcement = "active"

  conditions {
    ref_name {
      include = ["~DEFAULT_BRANCH"]
      exclude = []
    }
  }

  rules {
    deletion                = true
    required_linear_history = true
    non_fast_forward        = true
  }

  bypass_actors {
    # actor_id get your team id by
    # curl -sSL -H "Authorization: Bearer $MY_GH_PAT" https://api.github.com/orgs/Tracktrace-NGTT/teams/myteam-name
    actor_id    = 123456789 
    actor_type  = "Team"
    bypass_mode = "always"
  }
}

Steps to Reproduce

Debug Output

No response

Panic Output

No response

Code of Conduct

o-sama commented 1 month ago

I'm aware of this issue but the limitation actually lies in the go-github client, last I checked was a few months ago and the issue still existed. I'll check in the next few days and if it's been fixed I'll make the change to fix this here.