Skip to content

Adding the provider GitHub App to the branch protection exception list causes an error #1156

Closed

Description

@MattMencel

GitHub recently added the ability to put GitHub Apps in the branch protection exception list so the GitHub App can bypass branch protection rules. This is useful if I want to drop GitHub Action workflow templates into repos in my organization without requiring a PR, or use the FluxCD provider to bootstrap flux manifests in repos.

https://github.blog/changelog/2022-05-17-consistently-allow-github-apps-as-exceptions-to-branch-protection-rules/

However, when I tested this new feature I noticed it caused an error when Terraform attempted to create the plan.

As soon as I removed the GitHub App from the branch protection rule exception list, the plan worked correctly again.

Terraform Version

# terraform -v
Terraform v1.1.8
on linux_amd64

Affected Resource(s)

  • github_branch_protection

Terraform Configuration Files

resource "github_branch_protection" "this" {
  for_each = { for branch in local.settings.protected_branches : branch.pattern => branch }

  repository_id                   = github_repository.this.node_id
  pattern                         = each.value.pattern
  enforce_admins                  = try(each.value.enforce_admins, true)
  allows_deletions                = try(each.value.allows_deletions, false)
  allows_force_pushes             = try(each.value.allows_force_pushes, false)
  required_linear_history         = try(each.value.required_linear_history, false)
  require_conversation_resolution = try(each.value.require_conversation_resolution, true)

  required_pull_request_reviews {
    dismiss_stale_reviews           = try(each.value.dismiss_stale_reviews, true)
    required_approving_review_count = try(each.value.required_approving_review_count, 1)
    require_code_owner_reviews      = try(each.value.require_code_owner_reviews, false)

    pull_request_bypassers = try(data.github_users.pull_request_bypassers[each.key].node_ids, [])
  }

  required_status_checks {
    strict   = try(each.value.strict, true)
    contexts = each.value.contexts
  }

}

Expected Behavior

A plan should have been created.

Actual Behavior

╷
│ Error: Something went wrong while executing your query. Please include `0681:9080:C14D4:D695D:62879F7D` when reporting this issue.
│ 
│   with module.repos["flux-system"].github_branch_protection.this["main"],
│   on ../modules/gh-repo/main.tf line 63, in resource "github_branch_protection" "this":
│   63: resource "github_branch_protection" "this" {
│ 
╵

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. Add the provider GitHub App to a branch protection exception list on a repo.
  2. Attempt to plan that will trigger a GET on the branch protection rules (github_branch_protection resource)
  3. terraform plan

Activity

  1. vgrigoruk commented on Jun 23, 2022

    @vgrigoruk

    I experienced the same issue today. After a small investigation I've found out that Github apps were not added in the original PR which added support for pull_request_bypassers attribute:
    https://github.com/integrations/terraform-provider-github/pull/1030/files#diff-b5b3ae3d317e4c199b2bc55f4806ecb01a0f7764638d573587d9d680229145b9R23-R29

  2. devopsrick commented on Jun 27, 2022

    @devopsrick

    Yeah github apps weren't an option when this feature was rolled out.

  3. github-actions commented on Mar 25, 2023

    @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!

  4. added
    Status: Stale
    on Mar 25, 2023
  5. paymand commented on Mar 25, 2023

    @paymand

    Looks like this was implemented here: #1453
    And the fix was released in https://github.com/integrations/terraform-provider-github/releases/tag/v5.13.0
    This issue can be closed I think.

  6. removed
    Status: Stale
    on Mar 26, 2023
  7. julien-michaud commented on Mar 27, 2023

    @julien-michaud

    still getting error Error: Could not resolve to a node with the global id of '' when trying to allow a GitHub App to bypass branch protection.

  8. kfcampbell commented on Apr 10, 2023

    @kfcampbell
    Contributor

    @julien-michaud do you mind creating a new issue with an appropriate description and a snippet of HCL to reproduce it?

  9. mering commented on Jul 7, 2023

    @mering

    @julien-michaud did you create a new issue?

    In case anyone else arrives here , I found help for this error in #1248.

  10. Invincibear commented on Sep 3, 2025

    @Invincibear

    @mering THANK YOU!

    To save somebody else, this worked for me:

    data "github_app" "my_app_name" {
      slug = "my_app_name" # do NOT prefix this org/*
    }
    
    resource "github_branch_protection" "master_branch" {
      restrict_pushes {
        push_allowances  = [data.github_app.my_app_name.node_id]
      }
    }
    

    You might need to enable read Enterprise -> Enterprise organization installations permission on whatever you're using to auth Terraform with GitHub

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions