Repository navigation
Description
Terraform Version
v1.1.9 (though this has nothing to do with the terraform version)
Provider Version
v5.7.0 (though I believe it is also broken in latest)
Affected Resource(s)
github_repository
Terraform Configuration Files
resource "github_repository" "internal-repo-test" {
name = "internal-repo-test"
visibility = "internal"
}Output
from terraform apply
Terraform will perform the following actions:
# github_repository.internal-repo-test will be created
+ resource "github_repository" "internal-repo-test" {
+ allow_auto_merge = false
+ allow_merge_commit = true
+ allow_rebase_merge = true
+ allow_squash_merge = true
+ archived = false
+ default_branch = (known after apply)
+ delete_branch_on_merge = false
+ etag = (known after apply)
+ full_name = (known after apply)
+ git_clone_url = (known after apply)
+ html_url = (known after apply)
+ http_clone_url = (known after apply)
+ id = (known after apply)
+ merge_commit_message = "PR_TITLE"
+ merge_commit_title = "MERGE_MESSAGE"
+ name = "internal-repo-test"
+ node_id = (known after apply)
+ private = (known after apply)
+ repo_id = (known after apply)
+ squash_merge_commit_message = "COMMIT_MESSAGES"
+ squash_merge_commit_title = "COMMIT_OR_PR_TITLE"
+ ssh_clone_url = (known after apply)
+ svn_url = (known after apply)
+ visibility = "internal"
}
Plan: 1 to add, 0 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
github_repository.internal-repo-test: Creating...
╷
│ Error: PATCH https://api.github.com/repos/myorg/internal-repo-test: 422 Visibility can't be changed by this user. and Visibility is already internal. []
│
│ with github_repository.internal-repo-test,
│ on main.tf line 17, in resource "github_repository" "internal-repo-test":
│ 17: resource "github_repository" "internal-repo-test" {
│
╵
Releasing state lock. This may take a few moments...Expected Behaviour
Repository creation should have completed successfully.
Actual Behaviour
Repository creation failed. The following steps occurred:
- The code initially creates the repository with the correct visibility
- after creating the repository, the code updates the repository
- the update sets the visibility to nil so that it always updates
- that fails with a 422 (unprocessable entity) because its trying to update the visibility from
internaltointernal - the code expects the error message to contain
422 Visibility is already internaland returns an error otherwise - it appears that the GitHub api route has changed the 422 error message to
422 Visibility can't be changed by this user. and Visibility is already internal.so the match fails.
Steps to Reproduce
Using the configuration above, run:
terraform apply
Current Workaround
As the resource is currently tainted (because terraform taints resources when creation fails), rerunning terraform will delete/recreate the resource (because that's how terraform treats tainted resources) and run into the same issue.
Since visibility is one of the last edited properties for the repository (meaning the repository creation has actually fully completed) it is currently appears to be safe to untaint the resource and reapply
terraform untaint github_repository.internal-repo-test
terraform apply
Activity
mbarany commentedon Nov 16, 2022
I am seeing this issue as well
n0rad commentedon Nov 16, 2022
Same here on 5.8.0. It's broken and our teams cannot create repositories without manual actions.
Is it github api that is broken? or a breaking change that need to be supported by the provider?
chapurlatn commentedon Nov 17, 2022
Hello,
There is a test that ignore this error in the TF code. It's based on the error message returns by github API.
But this message changed.
Today, when trying to update visiblity from private to private, and when someone can't update the repo, github returns:
422 Visibility can't be changed by this user. and Visibility is already privateBut in the code:
https://github.com/integrations/terraform-provider-github/blob/main/github/resource_github_repository.go#L690
if !strings.Contains(err.Error(), fmt.Sprintf("422 Visibility is already %s", n.(string))) {We should provide a fix (for example, contains "422" and contains "Visibility is already%s") and everybody will have to use the latest version.
chapurlatn commentedon Nov 17, 2022
Note that we found a bypass for visibility "private" only: use the deprecated property "private: true" instead of using the "visibility" property. Before updating a lot of terraform plan to use a deprecated property, we'd like to wait for a fix... 🙏
Luis-3M commentedon Nov 18, 2022
we're experiencing the same issue
chapurlatn commentedon Nov 21, 2022
We need a maintainer to review the PR that is blocked #1368
chapurlatn commentedon Nov 21, 2022
Eventually @kfcampbell , could you please take a look at this PR to make sure it's properly handled?
mungojam commentedon Nov 21, 2022
This impacts previously working workflows and only started happening last week. Presumably due to a GitHub API change or something
jhaumont commentedon Nov 21, 2022
Hello
I'm very interested by the fix, any ideas from when we can have this one?
jtgrohn commentedon Nov 21, 2022
If you're blocked while waiting for the fix, you can use the work around in the issue description OR you can build @chapurlatn's fix in #1368 and use it in your workflows by dropping the built binary into a
bindirectory, adding the following to your.terraformrcfile, and setting theTF_CLI_CONFIG_FILEenvironment variable to.terraformrcchapurlatn commentedon Nov 22, 2022
I'm wondering if we should add a way to change the bypass condition by configuration in addition to the fix. For example by using an environment variable. It would be pretty ugly but will offer people a way to bypass without waiting for a fix or deploying local build. wdyt @jtgrohn?
Also, I will warn GitHub support about this API "error", cause this is the root cause of the custom behaviour and it's pretty weird: "you've got an error cause you try to didn't change something we can't change"...