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

[BUG]: 403 Resource not accessible by integration [] #2226

Open
1 task done
garysassano opened this issue Apr 11, 2024 · 3 comments
Open
1 task done

[BUG]: 403 Resource not accessible by integration [] #2226

garysassano opened this issue Apr 11, 2024 · 3 comments
Labels
Status: Up for grabs Issues that are ready to be worked on by anyone Type: Bug Something isn't working as documented

Comments

@garysassano
Copy link

garysassano commented Apr 11, 2024

Expected Behavior

Be able to create a repository using ${{ secrets.GITHUB_TOKEN }} instead of ${{ secrets.MY_PAT }}.

Actual Behavior

Can only create a github_repository resource using ${{ secrets.MY_PAT }}, since even a ${{ secrets.GITHUB_TOKEN }} with full write permissions doesn't have the rights to create a new repository when used with the integrations/github Terraform provider.

│ Error: POST https://api.github.com/user/repos: 403 Resource not accessible by integration []
│ 
│   with github_repository.SampleRepo,
      + allow_merge_commit          = false
      + allow_rebase_merge          = false
│   on main.tf line 14, in resource "github_repository" "SampleRepo":
│   14: resource "github_repository" "SampleRepo" {
│ 
jobs:
  apply:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: ${{ env.tf_actions_working_dir }}
    steps:
    - uses: actions/checkout@v4
    
    - uses: hashicorp/setup-terraform@v3

    - name: Terraform Init
      id: init
      run: terraform init -input=false

    - name: Terraform Apply
      run: terraform apply -input=false -auto-approve
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

image

Terraform Version

Terraform v1.8.0 on linux_amd64 + provider registry.terraform.io/integrations/github v6.2.1

Affected Resource(s)

  • github_repository
  • github_branch_protection

Terraform Configuration Files

terraform {
  required_providers {
    github = {
      version = "6.2.1"
      source  = "integrations/github"
    }
  }
}

provider "github" {}

resource "github_repository" "SampleRepo" {
  name                        = "todelete_sample"
  visibility                  = "private"
  allow_auto_merge            = false
  allow_merge_commit          = false
  allow_rebase_merge          = false
  allow_squash_merge          = true
  allow_update_branch         = true
  auto_init                   = true
  delete_branch_on_merge      = true
  has_discussions             = false
  has_downloads               = true
  has_issues                  = true
  has_projects                = true
  has_wiki                    = true
  merge_commit_message        = "PR_TITLE"
  merge_commit_title          = "MERGE_MESSAGE"
  squash_merge_commit_message = "COMMIT_MESSAGES"
  squash_merge_commit_title   = "PR_TITLE"
}

resource "github_branch_protection" "MainBranchProtection" {
  repository_id                   = github_repository.SampleRepo.node_id
  pattern                         = "main"
  allows_deletions                = false
  allows_force_pushes             = false
  enforce_admins                  = true
  require_conversation_resolution = true
  required_pull_request_reviews {
    dismiss_stale_reviews           = true
    required_approving_review_count = 1
  }
  required_status_checks {
    strict = true
  }
}

Steps to Reproduce

No response

Debug Output

No response

Panic Output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@garysassano garysassano added Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented labels Apr 11, 2024
@kfcampbell kfcampbell added Status: Up for grabs Issues that are ready to be worked on by anyone and removed Status: Triage This is being looked at and prioritized labels Apr 15, 2024
@cb-krishnapatel
Copy link

Hi, We are facing the same issue. when can we expect this to be fixed?

@dcfsc
Copy link
Contributor

dcfsc commented May 15, 2024

I saw the same error with provider 5.45.0 and found I could fix it by using ONLY the GITHUB_TOKEN env var, and not the "token" value in the provider block. See #2242. Until that was changed I don't think I was using the correct token.

Something is weird but that might be a workaround. YMMV.

@garysassano
Copy link
Author

IIRC, I fixed the issue by giving the GitHub App the administration: write permission. Definitely not intuitive, I couldn't find any reference in the official documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Up for grabs Issues that are ready to be worked on by anyone Type: Bug Something isn't working as documented
Projects
None yet
Development

No branches or pull requests

4 participants