Skip to content

Cannot create github_branch_protection_v3 after update to v5.3.0 #1307

Closed

Description

@jtsaito

Terraform Version

v5.3.0

Affected Resource(s)

  • github_branch_protection_v3
  • github_branch_default
  • github_branch_default

The issue occures when creating a new github_branch_protection_v3 resource with attributes referenced from github_branch_default and github_branch_protection_v3 resources.

Debug Output

github_branch_protection_v3.<MY_REPO_NAME_REDACTED>: Creating...
╷
│ Error: PUT https://api.github.com/repos/<MY_ORG_REDACTED>/<MY_REPO_NAME_REDACTED>/branches/main/protection: 422 Invalid request.
│
│ No subschema in "anyOf" matched.
│ For 'properties/checks', nil is not an array.
│ Not all subschemas of "allOf" matched.
│ For 'anyOf/1', {"strict"=>true, "contexts"=>["build"], "checks"=>nil} is not a null. []

Expected Behavior

The branch protection v3 resource should be created.

Actual Behavior

Terraform errors out with message above.

Steps to Reproduce

Step 1

Create a repo with terraform apply.

resource "github_repository" "test-repo" {
  name        = "test-repo"
  description = "This repo is a test"

  has_downloads = true
  has_issues    = false
  has_projects  = false
  has_wiki      = false

  visibility = "private"

  auto_init = true

  vulnerability_alerts = false
}

resource "github_branch_default" "test-repo" {
  repository = github_repository.test-repo.name
  branch     = "main"
}

Step 2

Terraform apply the following change:

resource "github_branch_protection_v3" "test-repo" {
  repository     = github_repository.test-repo.name
  branch         = github_branch_default.test-repo.branch
  enforce_admins = true

  required_status_checks {
    strict   = true
    contexts = ["build"]
  }

  required_pull_request_reviews {
    dismiss_stale_reviews      = true
    require_code_owner_reviews = true
  }
}

Important Factoids

This works up to GitHub provider version v5.2.0 without errors and errors in v5.3.0.

This seems to be linked to the go client update in the release diff where the API Client is updated as follows.

Checks []*RequiredStatusCheck `json:"checks"`

From

Checks []*RequiredStatusCheck `json:"checks,omitempty"

To

Checks []*RequiredStatusCheck `json:"checks"`

References

Activity

  1. iniinikoski commented on Sep 29, 2022

    @iniinikoski

    Can confirm this. Thanks for reporting @jtsaito !

    Update: and we've also locked ourselves to v5.2.0 and this one works supersmooth...

  2. jtsaito commented on Sep 29, 2022

    @jtsaito
    ContributorAuthor

    @iniinikoski Thanks for looking into it and confirming the bug.

  3. soerenmartius commented on Nov 3, 2022

    @soerenmartius

    same here

  4. added
    Type: Bug
    on Nov 3, 2022
  5. kfcampbell commented on Nov 10, 2022

    @kfcampbell
    Contributor

    Oh no! What a hassle. It looks like that was introduced to google/go-github in this PR, based off of this issue. Interestingly enough, that issue references #1147.

    Looking at our relevant code here and here, I'm not sure what we could do to fix this on our side...perhaps the appropriate course of action is an upstream revert?

    Perhaps experimenting with setting something other than []interface{}{} when protection.GetRequiredStatusChecks is nil could prove fruitful as well.

    Is anybody interested in exploring this further in a PR?

  6. added
    Status: Up for grabs
    on Nov 10, 2022
  7. TheQueenIsDead commented on Dec 4, 2022

    @TheQueenIsDead
    Contributor

    @kfcampbell I've opened a draft PR with a potential solution here:
    #1409

    It simply adds in an empty for the missing Checks attribute, which should resolve the issue as proposed by the issue reporter in google/go-github#2467

    If this seems like a viable path forwards, I'll look at building the module and testing it when I get the chance :-) (Untested currently hence the draft)

  8. moved this to 🔥 Backlog in 🧰 Octokit Activeon Dec 5, 2022
  9. kfcampbell commented on Dec 6, 2022

    @kfcampbell
    Contributor

    I responded on the PR, which looks good! I can't wait to resolve this issue.

  10. moved this from 🔥 Backlog to 🏗 In progress in 🧰 Octokit Activeon Jan 5, 2023
  11. jtsaito commented on Jan 23, 2023

    @jtsaito
    ContributorAuthor

    @TheQueenIsDead and everyone else who contributed. The issue was fixed by release 5.16.0 which included #1415.

  12. moved this from 🏗 In progress to ✅ Done in 🧰 Octokit Activeon Jan 23, 2023
  13. ekhaydarov commented on Jan 30, 2023

    @ekhaydarov

    EDIT: was not using _v3. the pr was fine

    im not so sure that this works? I am on 5.16.0 and hit the nil issue, adding checks just gave me this

    Error: Unsupported argument 
    ...
    An argument named "checks" is not expected here.
    
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: Up for grabsType: Bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions