terraform-provider-github: unable to update branch_protections for github repos
Hi there,
We were trying to enable enforce_admins = true and we see a TF plan like the following but when we apply we get an error. As you can see below there are no changes to required_status_checks but we are not able to apply it.
# module.repositories.github_branch_protection_v3.managed["REPO_NAME:BRANCH_NAME"] will be updated in-place
~ resource "github_branch_protection_v3" "managed" {
~ enforce_admins = false -> true
id = "REPO_NAME:BRANCH_NAME"
# (5 unchanged attributes hidden)
# (2 unchanged blocks hidden)
}
Terraform Version
1.0.9- terraform-provider-github:
v4.24.1
Affected Resource(s)
Please list the resources as a list, for example:
- github_branch_protection_v3
If this issue appears to affect multiple resources, it may be an issue with Terraform’s core, so please mention this.
Terraform Configuration Files
resource "github_branch_protection_v3" "example" {
repository = github_repository.example.name
branch = "main"
enforce_admins = true
required_status_checks {
strict = true
contexts = []
}
}
Debug Output
unfortunately I’m not allowed to share full debug output due to company policy, here’s some relevant debug logs:
2022-05-12T09:24:17.198-0700 [DEBUG] provider.terraform-provider-github_v4.24.1: {
2022-05-12T09:24:17.198-0700 [DEBUG] provider.terraform-provider-github_v4.24.1: "message": "Invalid request.\n\nNo subschema in \"anyOf\" matched.\nNo subschema in \"oneOf\" matched.\nNot all subschemas of \"allOf\" matched.\nFor 'anyOf/1', {\"strict\"=>true} is not a null.",
2022-05-12T09:24:17.198-0700 [DEBUG] provider.terraform-provider-github_v4.24.1: "documentation_url": "https://docs.github.com/rest/reference/repos#update-branch-protection"
2022-05-12T09:24:17.198-0700 [DEBUG] provider.terraform-provider-github_v4.24.1: }
│ Error: PUT https://api.github.com/repos/ORG_NAME/REPO_NAME/branches/BRANCH_NAME/protection: 422 Invalid request.
│
│ No subschema in "anyOf" matched.
│ No subschema in "oneOf" matched.
│ Not all subschemas of "allOf" matched.
│ For 'anyOf/1', {"strict"=>true} is not a null. []
│
│ with module.repositories.github_branch_protection_v3.managed["REPO_NAME:BRANCH_NAME"],
│ on ../../../modules/repositories/repository-branch-protection.tf line 1, in resource "github_branch_protection_v3" "managed":
│ 1: resource "github_branch_protection_v3" "managed" {
│
╵
Expected Behavior
- able to update branch protection
Actual Behavior
- seeing above errors
Steps to Reproduce
Please list the steps required to reproduce the issue, for example:
terraform apply
Important Factoids
- we use atlantis but the same error happens locally as well
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 19
- Comments: 21 (4 by maintainers)
Commits related to this issue
- known issue (https://github.com/integrations/terraform-provider-github/issues/1147), trying this workaround before changing the provider version — committed to ministryofjustice/opg-terraform-github-repository by charlesmmarshall a year ago
- Fix to the branch protection setup (#16) * known issue (https://github.com/integrations/terraform-provider-github/issues/1147), trying this workaround before changing the provider version * change t... — committed to ministryofjustice/opg-terraform-github-repository by charlesmmarshall a year ago
This is not fixed. Passing null for
contextsstill throws the same error as passing an empty list. This was working in~> 5.0previously but broke again in v5.7.0.EDIT: when passing
[]as the value forcontexts, the following error is returned by the API:Seems like the provider is perhaps converting the empty list to nil? I tried as well by explicitly setting
contexts = nulland the same error is returned.:This is on v5.7.0 of the provider using the
"github_branch_protection_v3"resource.We downgraded the provider to
4.22.0and it appears to have resolved the issue for us. Hopefully that helps yougit bisectit. 😃Can confirm, we’re using
4.22.0and the branch protection error doesn’t appear.I think
4.22.0should work.I’m also seeing this issue. My data point that I can contribute is that updated my pinned version for the provider from version
~> 4.19.2to~> 4.26.1. I’m not sure if that is directly related or a red herring.This seems to be a dupe of #1307, which a fix is in-progress for. I’m going to close this out and we should continue further discourse there.
We have resolved this issue on a few dozen repositories by switching from
github_branch_protection_v3togithub_branch_protection(v4) in https://github.com/mineiros-io/terraform-github-repository. No changes except renamingbranchtopatternwere necessary to get all our branch protections working again via Terraform.Downgrading to a lower version doesn’t seem like a good long term solution. Are there any plans to fix this in later versions?
This seems to be a problem with
github.com/google/go-github/v47I’m also experiencing this issue at my organisation, out of no-where much like @iniinikoski.
Has anyone had much success at a workaround or fix?
Unsure if this is related, but in the GitHub API docs under the “Body Parameters” section, it states that the
contextsproperty is both REQUIRED and DEPRECATED (which seems contradictory) and has been replaced bychecks. Is this a recent change?