Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT]: Allow renaming repositories without causing github_branch recreation #1926

Open
1 task done
brettswan opened this issue Sep 29, 2023 · 5 comments
Open
1 task done
Labels
hacktoberfest Issues for participation in Hacktoberfest Status: Up for grabs Issues that are ready to be worked on by anyone Type: Feature New feature or request

Comments

@brettswan
Copy link

Describe the need

Currently, if you create a repository and a branch, referencing the repository in the branch resource definition, you're unable to rename the repository without causing the branch to be recreated (destroyed and rebuilt). Example code below:

resource "github_repository" "this" {
  name = var.name
  description = var.description
  visibility = "internal"
  auto_init = true
  allow_update_branch = true
  
  has_downloads = false
  has_issues = false
  has_discussions = false
  has_projects = false
  has_wiki = true
}

resource "github_branch" "default" {
  repository = github_repository.this.id
  branch = var.default_branch
}

This is because the github_branch resource uses the repository name instead of the repository id, and repository is currently setup with ForceNew set to true. As a result, if you change the name of the repository, Terraform thinks it needs to destroy the existing branch and replace it with a new resource. Considering the repository itself hasn't changed, only the name, this is super undesirable behavior because Terraform will attempt to destroy a branch that may have commits already, or if the branch is protected, prevent Terraform from ever executing successfully to make the change.

I propose that the github_branch resource optionally take a repository id or name, and only recreate the resource if the repository id has changed.

SDK Version

No response

API Version

No response

Relevant log output

# module.repositories["MyRepo"].github_branch.default must be replaced
-/+ resource "github_branch" "default" {
      ~ etag          = "W/\"<etag>\"" -> (known after apply)
      ~ id            = "MyRepoOldName:master" -> (known after apply)
      ~ ref           = "refs/heads/master" -> (known after apply)
      ~ repository    = "MyRepoOldName" -> "MyRepoNewName" # forces replacement
      ~ sha           = "<sha>" -> (known after apply)
      + source_sha    = (known after apply)
        # (2 unchanged attributes hidden)
    }

Code of Conduct

  • I agree to follow this project's Code of Conduct
@brettswan brettswan added Status: Triage This is being looked at and prioritized Type: Feature New feature or request labels Sep 29, 2023
@nickfloyd nickfloyd added Status: Up for grabs Issues that are ready to be worked on by anyone hacktoberfest Issues for participation in Hacktoberfest and removed Status: Triage This is being looked at and prioritized labels Oct 3, 2023
@TechDawg270
Copy link

if this is considered a good first issue, i would love to give it a shot for hacktoberfest

@brettswan
Copy link
Author

I'd think this should be pretty straight forward to implement, just don't have bandwidth to take this on myself right now

@TechDawg270
Copy link

TechDawg270 commented Oct 4, 2023

I was able to reproduce the error and am working on a fix now

@athenaroa
Copy link

@TechDawg270 Any updates on this?

@TechDawg270
Copy link

I won't have the time now or for the foreseeable future

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest Issues for participation in Hacktoberfest Status: Up for grabs Issues that are ready to be worked on by anyone Type: Feature New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants