integrations / terraform-provider-github

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

[BUG]: Terraform import/plan differences for some github_branch_protection attributes #2122

Open GMZwinge opened 9 months ago

GMZwinge commented 9 months ago

Expected Behavior

After a terraform import of a github_branch_protection resource, a terraform plan should not show update of attribute like force_push_bypassers, push_restrictions and dismiss_stale_reviews, dismissal_restrictions, pull_request_bypassers, require_code_owner_reviews and restrict_dismissals in required_pull_request_reviews.

Actual Behavior

After a terraform import of a github_branch_protection resource, a terraform plan updates empty attribute arrays force_push_bypassers, push_restrictions and dismissal_restrictions, pull_request_bypassers in required_pull_request_reviews from [] to null and boolean attribute dismiss_stale_reviews, require_code_owner_reviews and restrict_dismissals from false to null. Eg:

  # github_branch_protection.branch_protection must be replaced
-/+ resource "github_branch_protection" "branch_protection" {
      - force_push_bypassers            = [] -> null
      ~ id                              = "BPR_kwDOLLRQgs4Cw5Jz" -> (known after apply)
      - push_restrictions               = [] -> null
      ~ repository_id                   = "R_kgDOLLRQgg" -> "<repoName>" # forces replacement
        # (9 unchanged attributes hidden)

      ~ required_pull_request_reviews {
          - dismiss_stale_reviews           = false -> null
          - dismissal_restrictions          = [] -> null
          - pull_request_bypassers          = [] -> null
          - require_code_owner_reviews      = false -> null
          - restrict_dismissals             = false -> null
            # (2 unchanged attributes hidden)
        }
    }

Terraform Version

Terraform v1.7.1 on Windows + Provider registry.terraform.io/integrations/github v6.0.0-beta

Affected Resource(s)

Terraform Configuration Files

terraform {
  required_providers {
    github = {
      source  = "integrations/github"
      version = "= 6.0.0-beta"
    }
  }
  required_version = "= 1.7.1"
}
variable "github_owner" {
  type    = string
}
variable "github_token" {
  sensitive = true
  type      = string
}
variable "github_repo" {
  type    = string
}
provider "github" {
  owner          = var.github_owner
  token          = var.github_token
}
resource "github_repository" "repo" {
  name = var.github_repo
}
resource "github_branch_protection" "branch_protection" {
  repository_id = github_repository.repo.name
  pattern = "main"
  # No difference with any of those:
  #force_push_bypassers = []
  #force_push_bypassers = null
  required_pull_request_reviews {
  }
}

Steps to Reproduce

terraform init
terraform plan
terraform apply -auto-approve
# This shows no changes:
terraform plan
terraform state rm github_branch_protection.branch_protection
terraform import github_branch_protection.branch_protection <repoName>:main
# This shows changes [] -> null and false -> null:
terraform plan
terraform apply -auto-approve
# This shows no changes:
terraform plan
terraform destroy -auto-approve

Debug Output

No response

Panic Output

No response

Code of Conduct

zibenua commented 9 months ago

Looks like in v6.0.0-rc1 the problem were solved

github-actions[bot] commented 1 week ago

👋 Hey Friends, this issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Please add the Status: Pinned label if you feel that this issue needs to remain open/active. Thank you for your contributions and help in keeping things tidy!