Repository navigation
Closed as not planned
Labels
Status: StaleUsed by stalebot to clean houseStatus: Up for grabsIssues that are ready to be worked on by anyoneType: BugSomething isn't working as documented
Description
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
Reacted by Iiro Niinikoski, Sam Jackson, Martin M, Joey Jonko, Hugo Lesta, Martin Smith, Jono Spiro, Futa HIRAKOBA, Ben McClain, widogg and 9 more
Metadata
Metadata
Assignees
Labels
Status: StaleUsed by stalebot to clean houseStatus: Up for grabsIssues that are ready to be worked on by anyoneType: BugSomething isn't working as documented
Type
Projects
- StatusShow more project fields🆕 Triage
- StatusShow more project fieldsDone
Activity
caylent-mariano-sanfilippo commentedon May 16, 2022
I was facing the same issue a few moments ago. Try adding context.
required_status_checks { strict = true contexts = [ "acontext" ] }stanislavsapov commentedon May 17, 2022
@balusarakesh if you don't need to enable checks, then you can try to provide
nullinstead of an empty list.iniinikoski commentedon May 17, 2022
I'm not sure if this works, here's the full (non-working) example:
I'm also a bit puzzled what broke here (why did this surface now; did GitHub update their API on this or what). The best option for us to get this sorted seems to just create the required_status_checks block with dynamic now - but only when the "contexts" have been configured - as otherwise - for reason X - GitHub gives the error.
But, we should be able to set the "strict" without the "contexts" - so - it seems to be a bug...
balusarakesh commentedon May 17, 2022
FYI: it's not the
contextsvariable, it'sstrictvariable which is having issues as you ca see from the logsTheJackson commentedon May 25, 2022
I'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?geancarlo commentedon Jun 10, 2022
Having the same issue over here. Apparently it worked fine 21 days ago from our terraform/CI logs...
highb commentedon Jun 15, 2022
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.highb commentedon Jun 17, 2022
We downgraded the provider to
4.22.0and it appears to have resolved the issue for us. Hopefully that helps yougit bisectit. :)luisdavim commentedon Sep 17, 2022
This seems to be a problem with
github.com/google/go-github/v47luisdavim commentedon Sep 18, 2022
Actually, it seems like
github.com/google/go-github/v47is used in other parts of this provider, but the branch protection usesgithub.com/shurcooL/githubv4, I've opened a PR to fix the issue ongithub.com/google/go-github/v47(google/go-github#2468) the fix on the other lib is probably similar, removingomitemptyfrom https://github.com/shurcooL/githubv4/blob/master/input.go#L604update: actually, there are 2 versions of the resource, one uses
github.com/google/go-github/v47(https://github.com/integrations/terraform-provider-github/blob/main/github/resource_github_branch_protection_v3.go) the other usesgithub.com/shurcooL/githubv4(https://github.com/integrations/terraform-provider-github/blob/main/github/resource_github_branch_protection.go)gfoligna-nyshex commentedon Oct 3, 2022
@luisdavim which version can we use meanwhile this gets resolved? I'm using
github_branch_protection_v3with provider version~> 4.0luisdavim commentedon Oct 3, 2022
I think
4.22.0should work.grrywlsn commentedon Oct 4, 2022
Can confirm, we're using
4.22.0and the branch protection error doesn't appear.cfisher281 commentedon Oct 20, 2022
Downgrading to a lower version doesn't seem like a good long term solution. Are there any plans to fix this in later versions?
kfcampbell commentedon Oct 27, 2022
This should already be fixed in github_branch_protection_v3 since this PR was merged in and released.
@luisdavim for github_branch_protection, the githubv4 schema has been updated a couple of times recently. Do you mind checking if the relevant
omitemptystill exists?16 remaining items
known issue (integrations/terraform-provider-github#1147), trying thi…
Fix to the branch protection setup (#16)
ljw4010 commentedon May 14, 2024
still get the same issue in v6.2.1
github-actions commentedon Mar 15, 2025
👋 Hey Friends, this issue has been automatically marked as
stalebecause it has no recent activity. It will be closed if no further activity occurs. Please add theStatus: Pinnedlabel if you feel that this issue needs to remain open/active. Thank you for your contributions and help in keeping things tidy!mriedem commentedon Mar 15, 2025
Still hitting this with provider version
~> 6.6.0. We have a change that's trying to setenforce_adminsfromtruetofalseand getting theError: branch is not protectederror. The plan says it's trying to do an update in place of the resource but also create it (even though it already exists and we're just trying to change thatenforce_adminsflag).github-actions commentedon Dec 11, 2025
👋 Hey Friends, this issue has been automatically marked as
stalebecause it has no recent activity. It will be closed if no further activity occurs. Please add theStatus: Pinnedlabel if you feel that this issue needs to remain open/active. Thank you for your contributions and help in keeping things tidy!