Skip to content

unable to update branch_protections for github repos #1147

Closed as not planned
Closed as not planned

Description

@balusarakesh

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:

  1. terraform apply

Important Factoids

  • we use atlantis but the same error happens locally as well

Activity

  1. caylent-mariano-sanfilippo commented on May 16, 2022

    @caylent-mariano-sanfilippo

    I was facing the same issue a few moments ago. Try adding context.
    required_status_checks { strict = true contexts = [ "acontext" ] }

  2. stanislavsapov commented on May 17, 2022

    @stanislavsapov

    @balusarakesh if you don't need to enable checks, then you can try to provide null instead of an empty list.

    resource "github_branch_protection_v3" "example" {
      repository     = github_repository.example.name
      branch         = "main"
      enforce_admins = true
    
      required_status_checks {
        strict   = true
        contexts = null
      }
    
    }
    
  3. iniinikoski commented on May 17, 2022

    @iniinikoski

    @balusarakesh if you don't need to enable checks, then you can try to provide null instead of an empty list.

    resource "github_branch_protection_v3" "example" {
      repository     = github_repository.example.name
      branch         = "main"
      enforce_admins = true
    
      required_status_checks {
        strict   = true
        contexts = null
      }
    
    }
    

    I'm not sure if this works, here's the full (non-working) example:

    resource "github_repository" "example" {
      name        = "terraform-test-repo"
      description = "Terraform acceptance tests"
    
      auto_init = true
    }
    
    resource "github_branch_protection_v3" "example" {
      repository = github_repository.example.name
      # branch         = "main"
      branch         = github_repository.example.default_branch
      enforce_admins = true
    
      required_status_checks {
        strict   = true
        contexts = null
      }
    
    }
    
    

    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...

  4. balusarakesh commented on May 17, 2022

    @balusarakesh
    Author

    FYI: it's not the contexts variable, it's strict variable which is having issues as you ca see from the logs

    │ For 'anyOf/1', {"strict"=>true} is not a null. []
    
  5. TheJackson commented on May 25, 2022

    @TheJackson

    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 contexts property is both REQUIRED and DEPRECATED (which seems contradictory) and has been replaced by checks. Is this a recent change?

  6. geancarlo commented on Jun 10, 2022

    @geancarlo

    Having the same issue over here. Apparently it worked fine 21 days ago from our terraform/CI logs...

  7. highb commented on Jun 15, 2022

    @highb

    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.2 to ~> 4.26.1. I'm not sure if that is directly related or a red herring.

  8. highb commented on Jun 17, 2022

    @highb

    We downgraded the provider to 4.22.0 and it appears to have resolved the issue for us. Hopefully that helps you git bisect it. :)

  9. luisdavim commented on Sep 17, 2022

    @luisdavim

    This seems to be a problem with github.com/google/go-github/v47

  10. luisdavim commented on Sep 18, 2022

    @luisdavim

    This seems to be a problem with github.com/google/go-github/v47

    Actually, it seems like github.com/google/go-github/v47 is used in other parts of this provider, but the branch protection uses github.com/shurcooL/githubv4, I've opened a PR to fix the issue on github.com/google/go-github/v47 (google/go-github#2468) the fix on the other lib is probably similar, removing omitempty from https://github.com/shurcooL/githubv4/blob/master/input.go#L604

    update: 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 uses github.com/shurcooL/githubv4 (https://github.com/integrations/terraform-provider-github/blob/main/github/resource_github_branch_protection.go)

  11. gfoligna-nyshex commented on Oct 3, 2022

    @gfoligna-nyshex

    @luisdavim which version can we use meanwhile this gets resolved? I'm using github_branch_protection_v3 with provider version ~> 4.0

  12. luisdavim commented on Oct 3, 2022

    @luisdavim

    I think 4.22.0 should work.

  13. grrywlsn commented on Oct 4, 2022

    @grrywlsn

    Can confirm, we're using 4.22.0 and the branch protection error doesn't appear.

  14. cfisher281 commented on Oct 20, 2022

    @cfisher281

    Downgrading to a lower version doesn't seem like a good long term solution. Are there any plans to fix this in later versions?

  15. kfcampbell commented on Oct 27, 2022

    @kfcampbell
    Contributor

    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 omitempty still exists?

  16. 16 remaining items

  17. ljw4010 commented on May 14, 2024

    @ljw4010

    still get the same issue in v6.2.1

    │ No subschema in "oneOf" matched.
    │ Not all subschemas of "allOf" matched.
    │ For 'anyOf/1', {"strict"=>true} is not a null. []```
    
  18. moved this from ✅ Done to 🆕 Triage in 🧰 Octokit Activeon Jun 17, 2024
  19. github-actions commented on Mar 15, 2025

    @github-actions

    👋 Hey Friends, this issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Please add the Status: Pinned label if you feel that this issue needs to remain open/active. Thank you for your contributions and help in keeping things tidy!

  20. added
    Status: Stale
    on Mar 15, 2025
  21. mriedem commented on Mar 15, 2025

    @mriedem

    Still hitting this with provider version ~> 6.6.0. We have a change that's trying to set enforce_admins from true to false and getting the Error: branch is not protected error. 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 that enforce_admins flag).

  22. removed
    Status: Stale
    on Mar 16, 2025
  23. github-actions commented on Dec 11, 2025

    @github-actions

    👋 Hey Friends, this issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Please add the Status: Pinned label if you feel that this issue needs to remain open/active. Thank you for your contributions and help in keeping things tidy!

  24. added
    Status: Stale
    on Dec 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: StaleStatus: Up for grabsType: Bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions