integrations / integrations/terraform-provider-github

[BUG]: changing branch name with protection rules set fails

Open
#3,552 5 comments 1 reaction 0 assignees View on GitHub
Awaiting response Status: Needs info Status: Triage Type: Bug
Dominant language
Go
Stars
1.2k
Forks
1k
Avg merge
1d 14h
Merged PRs (30d)
8

Description

### Expected Behavior

on changing branch name that has protection rules set by terraform, its expected for the apply to work normally

### Actual Behavior

branch name changes, however, protection rule modification fail with error : Could not resolve to a node with the global id of xxxxxxx

### Terraform Version

Terraform v1.15.7
on linux_amd64
+ provider registry.terraform.io/hashicorp/github v6.13.0

### GitHub Installation Type

- [x] GitHub.com (Free, Pro, or Team)
- [ ] GitHub Enterprise Server (on-premises)
- [ ] GitHub Enterprise Cloud with Personal Accounts (github.com)
- [ ] GitHub Enterprise Cloud with Managed Users/EMU (github.com)
- [ ] GitHub Enterprise Cloud with Data Residency (*.ghe.com)
- [ ] I don't know

### Affected Resource(s)

- github_branch_protection
- github_branch

### Terraform Configuration Files

```hcl
resource "github_repository" "terraform_lab" {
name = "tf-lab-practice"
description = "Can I change this?"

visibility = "public"
auto_init = true
allow_merge_commit = true
allow_squash_merge = true
topics = ["terraform", "iac"]

}

resource "github_branch" "terraform_lab" {
repository = github_repository.terraform_lab.name
branch = "master3"
}

resource "github_branch" "terraform_lab_dev" {
repository = github_repository.terraform_lab.name
branch = "dev3"
}
resource "github_branch_default" "terraform_lab" {
repository = github_repository.terraform_lab.name
branch = github_branch.terraform_lab.branch
}

resource "github_branch_protection" "terraform_lab" {
repository_id = github_repository.terraform_lab.name

pattern = github_branch_default.terraform_lab.branch
enforce_admins = true
allows_deletions = true

required_pull_request_reviews {
require_code_owner_reviews = true
dismiss_stale_reviews = true
restrict_dismissals = true
required_approving_review_count = 1
}
}

resource "github_branch_protection" "terraform_lab_dev" {
repository_id = github_repository.terraform_lab.name

pattern = github_branch.terraform_lab_dev.branch
enforce_admins = true
allows_deletions = true

required_pull_request_reviews {
require_code_owner_reviews = true
dismiss_stale_reviews = true
restrict_dismissals = true
required_approving_review_count = 1
}
}

output "repo_data" {
value = github_repository.terraform_lab
}
output "default_branch_data" {
value = github_branch_default.terraform_lab
}

terraform {
required_version = ">= 1.12.2" # Replace with your installed version
required_providers {
github = {
source = "hashicorp/github"
version = "~> 6.13"
}

}
}

provider "github" {}
```

### Steps to Reproduce

```
export GITHUB_TOKEN
terraform apply #the code provided
#change any branch name
terraform apply
```

### Debug Output

```shell
github_branch.terraform_lab_dev: Modifying... [id=tf-lab-practice:dev2]
github_branch_protection.terraform_lab: Modifying... [id=BPR_kwDOTcwWwc4Ey13a]
github_branch.terraform_lab_dev: Modifications complete after 4s [id=tf-lab-practice:dev3]
github_branch_protection.terraform_lab_dev: Modifying... [id=BPR_kwDOTcwWwc4Ey13b]
github_branch_protection.terraform_lab: Modifications complete after 8s [id=BPR_kwDOTcwWwc4Ey13a]

│ Error: Could not resolve to a node with the global id of 'BPR_kwDOTcwWwc4Ey13b'.

│ with github_branch_protection.terraform_lab_dev,
│ on main.tf line 44, in resource "github_branch_protection" "terraform_lab_dev":
│ 44: resource "github_branch_protection" "terraform_lab_dev" {


```

### Code of Conduct

- [x] I agree to follow this project's Code of Conduct

Contributor guide

Open the contributing guide

Research direction

Start with the github_branch and github_branch_protection resource implementations and reproduce the supplied Terraform configuration while tracing the protection rule's global ID after a branch rename. Done means renaming a protected branch applies successfully without the global-ID error and the existing protection remains correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, terraform
Domain
devops, infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.