integrations / terraform-provider-github

Terraform GitHub provider
https://www.terraform.io/docs/providers/github/
MIT License
886 stars 721 forks source link

[BUG]: Not able to create GitHub Repository using Private template #1667

Closed ritik-gupta-bzy closed 7 months ago

ritik-gupta-bzy commented 1 year ago

Describe the need

Hi, I am not able to create a new repository using a private template. It is throwing a 404 error.

Changed template POST https://api.github.com/repos/ORG/REPO_NAME/generate: 404 Not Found []

This is my code for reference:

terraform {
  required_version = "~> 1.0"

  required_providers {
    github = {
      source  = "integrations/github"
      version = ">= 4.20, < 6.0"
    }
  }
}

provider "github" {
  owner = "ORG"
# token is being passed an env variable GITHUB_TOKEN
}

resource "github_repository" "test" {
  name        = "test-repo"
  description = "Repo to test tempalates"

  visibility = "private"
  auto_init    = "true" 

  template {
    owner                = "ORG"
    repository           = "REPO_NAME"
  }
}

The template repo is marked as a template on github:

image

SDK Version

No response

API Version

No response

Relevant log output

2023-04-25T11:34:03.969Z [DEBUG] github_repository.this: applying the planned Create change
2023-04-25T11:34:03.971Z [DEBUG] provider.terraform-provider-github_v5.23.0: 2023/04/25 11:34:03 [DEBUG] setting computed for "security_and_analysis" from ComputedKeys
2023-04-25T11:34:03.971Z [DEBUG] provider.terraform-provider-github_v5.23.0: 2023/04/25 11:34:03 [DEBUG] GitHub API Request Details:
2023-04-25T11:34:03.971Z [DEBUG] provider.terraform-provider-github_v5.23.0: ---[ REQUEST ]---------------------------------------
2023-04-25T11:34:03.971Z [DEBUG] provider.terraform-provider-github_v5.23.0: POST /repos/beazley/devops-azure-terraform-module-template/generate HTTP/1.1
2023-04-25T11:34:03.971Z [DEBUG] provider.terraform-provider-github_v5.23.0: Host: api.github.com
2023-04-25T11:34:03.971Z [DEBUG] provider.terraform-provider-github_v5.23.0: User-Agent: go-github/v51.0.0
2023-04-25T11:34:03.971Z [DEBUG] provider.terraform-provider-github_v5.23.0: Content-Length: 118
2023-04-25T11:34:03.971Z [DEBUG] provider.terraform-provider-github_v5.23.0: Accept: application/vnd.github.baptiste-preview+json,application/vnd.github.stone-crop-preview+json
2023-04-25T11:34:03.971Z [DEBUG] provider.terraform-provider-github_v5.23.0: Content-Type: application/json
2023-04-25T11:34:03.971Z [DEBUG] provider.terraform-provider-github_v5.23.0: X-Github-Api-Version: 2022-11-28
2023-04-25T11:34:03.971Z [DEBUG] provider.terraform-provider-github_v5.23.0: Accept-Encoding: gzip
2023-04-25T11:34:03.971Z [DEBUG] provider.terraform-provider-github_v5.23.0: 
2023-04-25T11:34:03.971Z [DEBUG] provider.terraform-provider-github_v5.23.0: {
2023-04-25T11:34:03.971Z [DEBUG] provider.terraform-provider-github_v5.23.0:  "name": "test-repo",
2023-04-25T11:34:03.971Z [DEBUG] provider.terraform-provider-github_v5.23.0:  "owner": "",
2023-04-25T11:34:03.971Z [DEBUG] provider.terraform-provider-github_v5.23.0:  "description": "Repo to test the pipeline",
2023-04-25T11:34:03.971Z [DEBUG] provider.terraform-provider-github_v5.23.0:  "include_all_branches": false,
2023-04-25T11:34:03.971Z [DEBUG] provider.terraform-provider-github_v5.23.0:  "private": true
2023-04-25T11:34:03.971Z [DEBUG] provider.terraform-provider-github_v5.23.0: }
2023-04-25T11:34:03.971Z [DEBUG] provider.terraform-provider-github_v5.23.0: 
2023-04-25T11:34:03.971Z [DEBUG] provider.terraform-provider-github_v5.23.0: -----------------------------------------------------
2023-04-25T11:34:04.121Z [DEBUG] provider.terraform-provider-github_v5.23.0: 2023/04/25 11:34:04 [DEBUG] GitHub API Response Details:
2023-04-25T11:34:04.122Z [DEBUG] provider.terraform-provider-github_v5.23.0: ---[ RESPONSE ]--------------------------------------
2023-04-25T11:34:04.122Z [DEBUG] provider.terraform-provider-github_v5.23.0: HTTP/2.0 404 Not Found
2023-04-25T11:34:04.122Z [DEBUG] provider.terraform-provider-github_v5.23.0: Access-Control-Allow-Origin: *
2023-04-25T11:34:04.122Z [DEBUG] provider.terraform-provider-github_v5.23.0: Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset
2023-04-25T11:34:04.122Z [DEBUG] provider.terraform-provider-github_v5.23.0: Content-Security-Policy: default-src 'none'
2023-04-25T11:34:04.122Z [DEBUG] provider.terraform-provider-github_v5.23.0: Content-Type: application/json; charset=utf-8
2023-04-25T11:34:04.122Z [DEBUG] provider.terraform-provider-github_v5.23.0: Date: Tue, 25 Apr 2023 11:34:04 GMT
2023-04-25T11:34:04.122Z [DEBUG] provider.terraform-provider-github_v5.23.0: Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
2023-04-25T11:34:04.122Z [DEBUG] provider.terraform-provider-github_v5.23.0: Server: GitHub.com
2023-04-25T11:34:04.122Z [DEBUG] provider.terraform-provider-github_v5.23.0: Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
2023-04-25T11:34:04.122Z [DEBUG] provider.terraform-provider-github_v5.23.0: Vary: Accept-Encoding, Accept, X-Requested-With
2023-04-25T11:34:04.122Z [DEBUG] provider.terraform-provider-github_v5.23.0: X-Content-Type-Options: nosniff
2023-04-25T11:34:04.122Z [DEBUG] provider.terraform-provider-github_v5.23.0: X-Frame-Options: deny
2023-04-25T11:34:04.122Z [DEBUG] provider.terraform-provider-github_v5.23.0: X-Github-Api-Version-Selected: 2022-11-28
2023-04-25T11:34:04.122Z [DEBUG] provider.terraform-provider-github_v5.23.0: X-Github-Media-Type: github.v3; param=baptiste-preview; format=json, github.stone-crop-preview; format=json
2023-04-25T11:34:04.122Z [DEBUG] provider.terraform-provider-github_v5.23.0: X-Github-Request-Id: 2083:1438:166A969:2E06185:6447BAAC
2023-04-25T11:34:04.122Z [DEBUG] provider.terraform-provider-github_v5.23.0: X-Ratelimit-Limit: 60
2023-04-25T11:34:04.122Z [DEBUG] provider.terraform-provider-github_v5.23.0: X-Ratelimit-Remaining: 58
2023-04-25T11:34:04.122Z [DEBUG] provider.terraform-provider-github_v5.23.0: X-Ratelimit-Reset: 1682423936
2023-04-25T11:34:04.122Z [DEBUG] provider.terraform-provider-github_v5.23.0: X-Ratelimit-Resource: core
2023-04-25T11:34:04.122Z [DEBUG] provider.terraform-provider-github_v5.23.0: X-Ratelimit-Used: 2
2023-04-25T11:34:04.122Z [DEBUG] provider.terraform-provider-github_v5.23.0: X-Xss-Protection: 0
2023-04-25T11:34:04.122Z [DEBUG] provider.terraform-provider-github_v5.23.0: 
2023-04-25T11:34:04.122Z [DEBUG] provider.terraform-provider-github_v5.23.0: {
2023-04-25T11:34:04.122Z [DEBUG] provider.terraform-provider-github_v5.23.0:  "message": "Not Found",
2023-04-25T11:34:04.122Z [DEBUG] provider.terraform-provider-github_v5.23.0:  "documentation_url": "https://docs.github.com/rest/reference/repos#create-a-repository-using-a-template"
2023-04-25T11:34:04.122Z [DEBUG] provider.terraform-provider-github_v5.23.0: }
2023-04-25T11:34:04.122Z [DEBUG] provider.terraform-provider-github_v5.23.0: -----------------------------------------------------
Error: -25T11:34:04.124Z [ERROR] vertex "github_repository.this" error: POST https://api.github.com/repos/beazley/devops-azure-terraform-module-template/generate: 404 Not Found []

Error: POST https://api.github.com/repos/beazley/devops-azure-terraform-module-template/generate: 404 Not Found []

  with github_repository.this,
  on main.tf line 1, in resource "github_repository" "this":
   1: resource "github_repository" "this" {

Code of Conduct

michaelkacher commented 1 year ago

To provide additional input, I receive this same 404 error with 'internal' templates.

Here is the setup:

This leads me to believe it might not be due to the visibility setting but perhaps it is an Enterprise Managed User issue?

Sample usage:

resource "github_repository" "this" {
  name        = local.repo_name
  description = "Repository for ${var.app_name}. This ...."
  visibility  = var.repo_visibility # internal

  template {
    owner                = var.org
    repository           = "starterTemplate"
    include_all_branches = false
  }
}
Mctalian commented 8 months ago

I just tried to use the provider to create a repo from a template (version 5.42) and it created the repo from the template as expected.

Unsure if there are other nuances that @michaelkacher is alluding to, or if this was unexpectedly fixed in the past month or 2.

kfcampbell commented 7 months ago

I also cannot reproduce the issue, and I'm going to close it accordingly. Please feel free to comment/reopen if this still persists.