Closed kiddom-kq closed 3 years ago
just hit the same issue on a terratest run:
TestRepositoryValidity 2021-01-25T19:58:34Z logger.go:66: module.repositories["repositories/test-dummy-repo-1"].github_branch_default.default_branch: Destroying... [id=test-dummy-repo-1]
TestRepositoryValidity 2021-01-25T19:58:35Z logger.go:66:
TestRepositoryValidity 2021-01-25T19:58:35Z logger.go:66: Error: PATCH https://api.github.com/repos/xxxx/test-dummy-repo-1: 422 Visibility is already private. []
TestRepositoryValidity 2021-01-25T19:58:35Z logger.go:66:
TestRepositoryValidity 2021-01-25T19:58:35Z logger.go:66:
TestRepositoryValidity 2021-01-25T19:58:35Z retry.go:80: Returning due to fatal error: FatalError{Underlying: error while running command: exit status 1;
Error: PATCH https://api.github.com/repos/xxxx/test-dummy-repo-1: 422 Visibility is already private. []
}
destroy.go:11:
Error Trace: destroy.go:11
terratest.go:56
tests_test.go:50
Error: Received unexpected error:
FatalError{Underlying: error while running command: exit status 1;
Error: PATCH https://api.github.com/repos/xxxx/test-dummy-repo-1: 422 Visibility is already private. []
}
Seems like the fix released in https://github.com/integrations/terraform-provider-github/pull/666 only corrected the create / update operations. We'll need to follow up with the delete operation to finalize the fix. Thanks for reporting @onurg.
Can anyone else confirm the v4.3.1 release is not sufficient here?
hi @jcudit @kiddom-kq, just verified v4.3.1 fixes it. if somebody else also wants to confirm that the fix was sufficient, feel free to do so.
here's the destroy output from the same run I posted prior:
TestRepositoryValidity 2021-01-26T13:24:28-05:00 retry.go:72: terraform [destroy -auto-approve -input=false -lock=false]
TestRepositoryValidity 2021-01-26T13:24:28-05:00 logger.go:66: Running command terraform with args [destroy -auto-approve -input=false -lock=false]
TestRepositoryValidity 2021-01-26T13:24:29-05:00 logger.go:66: module.teams["teams/dummy-team"].github_team.create_team: Refreshing state... [id=4465638]
TestRepositoryValidity 2021-01-26T13:24:29-05:00 logger.go:66: module.teams["teams/dummy-team"].github_team_membership.add_member["Whitening-McClean"]: Refreshing state... [id=4465638:Whitening-McClean]
TestRepositoryValidity 2021-01-26T13:24:29-05:00 logger.go:66: module.repositories["repositories/test-dummy-repo-1"].github_repository.create_repo: Refreshing state... [id=test-dummy-repo-1]
TestRepositoryValidity 2021-01-26T13:24:29-05:00 logger.go:66: module.repositories["repositories/test-dummy-repo-1"].github_team_repository.team_membership["dummy-team"]: Refreshing state... [id=4465638:test-dummy-repo-1]
TestRepositoryValidity 2021-01-26T13:24:29-05:00 logger.go:66: module.repositories["repositories/test-dummy-repo-1"].github_branch_default.default_branch: Refreshing state... [id=test-dummy-repo-1]
TestRepositoryValidity 2021-01-26T13:24:30-05:00 logger.go:66: module.repositories["repositories/test-dummy-repo-1"].github_repository_file.codeowners: Refreshing state... [id=test-dummy-repo-1/.github/CODEOWNERS]
TestRepositoryValidity 2021-01-26T13:24:31-05:00 logger.go:66: module.repositories["repositories/test-dummy-repo-1"].github_team_repository.team_membership["dummy-team"]: Destroying... [id=4465638:test-dummy-repo-1]
TestRepositoryValidity 2021-01-26T13:24:31-05:00 logger.go:66: module.repositories["repositories/test-dummy-repo-1"].github_repository_file.codeowners: Destroying... [id=test-dummy-repo-1/.github/CODEOWNERS]
TestRepositoryValidity 2021-01-26T13:24:31-05:00 logger.go:66: module.repositories["repositories/test-dummy-repo-1"].github_team_repository.team_membership["dummy-team"]: Destruction complete after 1s
TestRepositoryValidity 2021-01-26T13:24:33-05:00 logger.go:66: module.repositories["repositories/test-dummy-repo-1"].github_repository_file.codeowners: Destruction complete after 3s
TestRepositoryValidity 2021-01-26T13:24:33-05:00 logger.go:66: module.repositories["repositories/test-dummy-repo-1"].github_branch_default.default_branch: Destroying... [id=test-dummy-repo-1]
TestRepositoryValidity 2021-01-26T13:24:34-05:00 logger.go:66: module.repositories["repositories/test-dummy-repo-1"].github_branch_default.default_branch: Destruction complete after 1s
TestRepositoryValidity 2021-01-26T13:24:34-05:00 logger.go:66: module.repositories["repositories/test-dummy-repo-1"].github_repository.create_repo: Destroying... [id=test-dummy-repo-1]
TestRepositoryValidity 2021-01-26T13:24:36-05:00 logger.go:66: module.repositories["repositories/test-dummy-repo-1"].github_repository.create_repo: Destruction complete after 1s
TestRepositoryValidity 2021-01-26T13:24:36-05:00 logger.go:66: module.teams["teams/dummy-team"].github_team_membership.add_member["Whitening-McClean"]: Destroying... [id=4465638:Whitening-McClean]
TestRepositoryValidity 2021-01-26T13:24:37-05:00 logger.go:66: module.teams["teams/dummy-team"].github_team_membership.add_member["Whitening-McClean"]: Destruction complete after 2s
TestRepositoryValidity 2021-01-26T13:24:37-05:00 logger.go:66: module.teams["teams/dummy-team"].github_team.create_team: Destroying... [id=4465638]
TestRepositoryValidity 2021-01-26T13:24:39-05:00 logger.go:66: module.teams["teams/dummy-team"].github_team.create_team: Destruction complete after 1s
TestRepositoryValidity 2021-01-26T13:24:39-05:00 logger.go:66:
TestRepositoryValidity 2021-01-26T13:24:39-05:00 logger.go:66: Destroy complete! Resources: 6 destroyed.
I've found an issue that seems to crop up on repo deletion. The issue appears to be with private repos that have a `` resource set.
Terraform Version
This issue is reproducible on the latest versions. (as of today; 2020-12-04)
Affected Resource(s)
Terraform Configuration Files
Here is a simple test-case that is identical to the test case I used to find/document this bug. I have stripped out org/personal information and substituted generic tokens in place:
Debug Output
Please provide a link to a GitHub Gist containing the complete debug output: https://www.terraform.io/docs/internals/debugging.html. Please do NOT paste the debug output in the issue; just paste a link to the Gist.
Here is a short version:
Note: I get the same result if I comment out only the
github_branch_default
resource and then run a normalterraform apply
. I just used--target
to hone which resource caused the error.I am more than happy to provide the full
TF_LOG=TRACE
output, but it's 3K lines long with the--target
flag. I've included the relevant bits below:Panic Output
No panic produced.
Expected Behavior
I would expect the default branch configuration to be deleted w/o the
422
API error.Actual Behavior
I get this error returned from GH API:
Steps to Reproduce
(see
note2
below) comment out thegithub_branch_default
resource in the above 'test case' configuration.run
tf apply
against the config and observe that 4 resources are created, one of which is the repo.un-comment out the
github_branch_default
resource in the above 'test-case' config.use either the web UI or
git checkout -b && git push
to make the branch calledMyNonMainDefaultBranch
in the new reporun
tf apply
against the config and observe that one new resource will be createddetermine that the repo and associated resources created in the test config must now be deleted
comment out all the resources in the above test case
run
tf apply
against the config and observe that 5 resources will be destroyedobserve that some resources have been deleted:
(see
note1
below). Manually remove thegithub_branch_default
resource from the state filerun
tf apply
against the config and observe that the remaining resource (thegithub_repository.myOrg_testing
) will be destroyedNote1:: If, instead of manually removing the
github_branch_default
resource from the state file as in step 10, you leave ONLY thegithub_repository
resource un-commented, terraform will still only destroy thegithub_branch_default.myOrg_testing
resource. This tells me that the dependency resolution is logically correct but inefficient/un-optimized; the deletion of thegithub_branch_default
does not matter if thegithub_repository
is to be deleted. Deleting the repo necessarily deletes the default branch config.Note2: Failure to comment out the
github_branch_default
resource in step 1 will result in an error:Important Factoids
I can reproduce this behavior with the token that was allocated specifically for our automated Terraform ci/cd pipeline and with my personal token which has 'Owner' level permissions attached to it.
The workaround is to:
comment out / delete the
github_branch_default
resource from the*.tf
file(s).manually remove the
github_branch_default
resource from the state file:terraform state rm github_branch_default.myOrg_testing
:terraform apply
and let it observe that thegithub_repository
is missing and thus should be deleted. Deleting the repo necessarily deletes the repos' default branch config.References
These issues seem related:
https://github.com/terraform-providers/terraform-provider-github/issues/580