Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to force the github provider to use v4 graphql api #551

Closed
tru2dagame opened this issue Sep 16, 2020 · 5 comments
Closed

How to force the github provider to use v4 graphql api #551

tru2dagame opened this issue Sep 16, 2020 · 5 comments

Comments

@tru2dagame
Copy link

tru2dagame commented Sep 16, 2020

Hi there,

Terraform Version

Terraform v0.13.2
+ provider registry.terraform.io/hashicorp/github v3.0.0

Affected Resource(s)

Please list the resources as a list, for example:

  • github_branch_protection

Terraform Configuration Files

provider "github" {
  organization = "xxxx"
  token = "xxxxxxxxxxxxxxx"
  base_url = "https://git.xxxxxxx.xxxxx/"
}

terraform {
  required_providers {
    github = {
      source = "hashicorp/github"
      version = "= 3.0.0"
    }
  }
  required_version = "= 0.13.2"
}


resource "github_branch_protection" "ud_alpha" {
  repository     = "xxxxxx"
  branch         = "alpha"
  enforce_admins = true


  required_pull_request_reviews {
    required_approving_review_count = 1
  }
}

Debug Output

image

Expected Behavior

v4 graphql api could protect a non-existent git branch

Actual Behavior

Error: PUT https://git.xxxx.xxxx/api/v3/repos/xxxx/xxxxxxxx/branches/alpha/protection: 404 Branch not found []

Steps to Reproduce

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

  1. terraform init
  2. terraform apply

References

@majormoses
Copy link
Contributor

Hey I think its just a matter of defining another github provider and then passing that to specific resource/module invocations like so: https://github.com/terraform-providers/terraform-provider-github/issues/167#issuecomment-606375836

provider "github" {
  organization = "myorg"
  ...
}

provider "github-v4" {
  organization = "myorg"
  ...
}

resource "github_branch_protection" "master" {
  provider = github-v4 # defaults to github
  ...
}

@tru2dagame
Copy link
Author

Hi @majormoses,

Thanks for the help.

That custom provider is base on version 2.
The terraform github provider is now version 3.
There will be some errors downgrade the provider to version 2.

@tru2dagame
Copy link
Author

OK. I found the master branch has switch branch protection to v4 but not tag v3.0.0.

Tried to build the master branch locally got this error:

==> Checking that code complies with gofmt requirements...
go install
# github.com/terraform-providers/terraform-provider-github/github
github/resource_github_repository.go:305:6: undefined: err
github/resource_github_repository.go:305:43: undefined: orgName
github/resource_github_repository.go:306:6: undefined: err
github/resource_github_repository.go:307:11: undefined: err
github/resource_github_repository.go:379:81: undefined: orgName
github/resource_github_repository.go:449:43: undefined: orgName
gnumake: *** [build] Error 2

@mallyvai
Copy link

mallyvai commented Sep 20, 2020

I'm able to replicate the master branch failure:
https://github.com/terraform-providers/terraform-provider-github/issues/555

@jcudit
Copy link
Contributor

jcudit commented Nov 25, 2020

Confirmed that the implementation for this resource has changed to the v4 GraphQL API. There is ongoing discussion around supporting both previous and current implementations going forward over in https://github.com/terraform-providers/terraform-provider-github/issues/606, but not sure how it will turn out.

I'm not sure if this issue is still relevant, but please reopen and clarify what can be helped with if I've misunderstood.

@jcudit jcudit closed this as completed Nov 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants