terraform-provider-github
terraform-provider-github copied to clipboard
resource/github_repository: Renaming forces new resource
Terraform Version
v0.10.2
Affected Resource(s)
github_repository
Terraform Configuration Files
resource "github_repository" "example" {
name = "example-rename" # Change this
}
Expected Behavior
The repository should have been renamed without triggering the "forces new resource" behavior.
Actual Behavior
The plan shows the repository as requiring recreation.
Output
-/+ github_repository.example (new resource required)
full_name: "Example/example-rename" => "<computed>"
git_clone_url: "git://github.com/Example/example-rename.git" => "<computed>"
http_clone_url: "https://github.com/Example/example-rename.git" => "<computed>"
name: "example-rename" => "example" (forces new resource)
could anyone please review the linked PR? Thanks
This would definitely be preferable to having to remove the state, rename the repo in GH, and then re-import the state, which is what we're doing now.
https://github.com/terraform-providers/terraform-provider-github/issues/17#issuecomment-310893940
@radeksimko I saw you closed some of the other versions of this, we probably should leave at least one of them open as people keep creating new issues and we might as well keep one open with the context.
This is the current workaround https://gist.github.com/macropin/49f8a3c72afc157fa0d81688d26af677
This is the current workaround https://gist.github.com/macropin/49f8a3c72afc157fa0d81688d26af677
I do something similar but with a terraform state mv [old] [new] instead of a remove and import. See the docs for full usage. I do a remove from state is when deleting repos (as we dont give our bots the ability to delete) or when I need to switch the provider associated with it (less common with github than say aws), Keep in mind that it won't move child objects which I think is probably true in the case of sub objects (such as permissions, branch protections, etc) as well with an import.
@radeksimko I believe Github's API provides renaming support https://developer.github.com/v3/repos/#edit. I haven't verified it myself yet, but there are multiple stackoverflow answers confirming this behavior https://stackoverflow.com/questions/4777535/how-do-i-rename-a-github-repository-via-their-api.
Do you accept PRs supporting renaming?
there is relevant discussion on #65 that would be useful to anyone looking to submit a PR it requires a bit of refactor to leverage the repository id (not documented) internally with terraform so it can know the difference between a rename and a delete and create.
Indeed, any resource which can be renamed should be identified by its permanent identifier inside Terraform (and in the Terraform configuration); I've done a bunch of work in that area for identifying users already, but it could be done for repositories as well.
Is the idea to pass around the repository id and look up what name the id is associated with (give all APIs are org/name based), while using the id in place of the repository name? Are calls cached by default? Happy to kick off this refactor if this is the way to go.
(id being node_id from which we derive the id from)
Is this still an issue?
Doesn't seem so as the nameattribute doesn't have ForceNew: true anymore and with the latest version 4.29.0 it seem to work out of the box.
Can somebody confirm that this is intentionally working?
It seems to work as of version 4.59.0, I could update in-place. Only the resource github_branch_protection_v3 was replaced.
Sounds good; I'll close this now. Please feel free to reopen or create a new issue if you continue to see issues with this behavior.