integrations / terraform-provider-github

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

[BUG]: Project disabled for this repository #2119

Open gilacost opened 8 months ago

gilacost commented 8 months ago

Expected Behavior

A GitHub repository is created with a project according to the following Terraform configuration:

resource "github_repository" "main" {
  name                   = local.repository_name
  visibility             = "private"
  has_issues             = true
  has_projects           = true
  auto_init              = true
}

I expect the project to be created because the repository resource has the has_projects=true attribute.

Actual Behavior

The project is not created. The project resource that I am using has the depends_on attribute so that it is only created after the repo resource. However, I received an error that said that the project could not be created because projects have not been enabled for the repository.

I'm not sure if this is a Terraform provider issue or an issue with the GitHub API itself. I wonder how I can see the request that the provider makes to the API?

Terraform Version

Terraform v1.4.6 on darwin_arm64

Affected Resource(s)

Terraform Configuration Files

terraform {
  required_providers {
    github = {
      source  = "integrations/github"
      version = "6.0.0-beta"
    }
  }
}

locals {
  repository_name = "project-test"
  github_owner    = "OWNER"
  columns         = ["TODO", "IN PROGRESS", "DONE"]
}

resource "github_repository" "main" {
  name                   = local.repository_name
  visibility             = "private"
  has_issues             = true
  has_projects           = true
  auto_init              = true
  gitignore_template     = "Terraform"
  delete_branch_on_merge = true
}

variable "issues" {
  type = list(object({
    title     = string
    body      = string
    labels    = list(string)
    milestone = string
  }))
}

resource "github_project_card" "cards" {
  count        = length(github_issue.tasks)
  column_id    = github_project_column.columns["TODO"].column_id
  content_id   = github_issue.tasks[count.index].issue_id
  content_type = "Issue"
}

resource "github_repository_project" "project" {
  depends_on = [github_repository.main]
  name       = "my name"
  repository = github_repository.main.id  
  body = "my body"
}

resource "github_project_column" "columns" {
  for_each   = toset(local.columns)
  project_id = github_repository_project.project.id
  name       = each.value
}

provider "github" {
  owner = local.github_owner
}

Steps to Reproduce

cat << EOF >> .auto.tfvars
issues = [
  {
    title     = "The TITLE"
    body      = <<EOT
The BODY
EOT
    labels    = ["one-label", "another-label"]
    milestone = "a milestone"
  }
]
EOF

$ terraform apply

Debug Output

Error:

╷
│ Error: POST https://api.github.com/repos/BeamOps/project-test/projects: 410 Projects are disabled for this repository []
│ 
│   with github_repository_project.project,
│   on main.tf line 101, in resource "github_repository_project" "project":
│  101: resource "github_repository_project" "project" {
│ 
╵

Panic Output

No response

Code of Conduct

kfcampbell commented 7 months ago

@gilacost you can follow our instructions here in the CONTRIBUTING.md file to debug the provider using VS Code, which will let you inspect and step through the requests.

It may be easier, however, to set the TF_LOG environment variable to DEBUG, which will print out each request and response made in the course of invoking the provider.

gonzape27 commented 7 months ago

Hey i am having the same issue:


# Create a custom action repository
resource "github_repository" "action_build_repo" {
  name         = "test-action-build"
  description  = "Custom action repository"
  auto_init = true
  visibility      = "internal"
}

github_repository_project.project: Creating... 2024-02-17T17:11:39.084-0300 [INFO] Starting apply for github_repository_project.project 2024-02-17T17:11:39.085-0300 [DEBUG] github_repository_project.project: applying the planned Create change 2024-02-17T17:11:39.325-0300 [ERROR] provider.terraform-provider-github_v6.0.0: Response contains error diagnostic: @module=sdk.proto tf_req_id=1f84db87-4b84-4e98-2e58-2983d12aa923 @caller=github.com/hashicorp/terraform-plugin-go@v0.20.0/tfprotov5/internal/diag/diagnostics.go:62 diagnostic_summary="POST https://api.github.com/repos/xxxx-org/test-action-build/projects: 410 Projects are disabled for this repository []" tf_proto_version=5.4 tf_resource_type=github_repository_project tf_rpc=ApplyResourceChange diagnostic_detail="" diagnostic_severity=ERROR tf_provider_addr=provider timestamp=2024-02-17T17:11:39.325-0300 2024-02-17T17:11:39.354-0300 [DEBUG] State storage *statemgr.Filesystem declined to persist a state snapshot 2024-02-17T17:11:39.355-0300 [ERROR] vertex "github_repository_project.project" error: POST https://api.github.com/repos/Xxxxxxx/test-action-build/projects: 410 Projects are disabled for this repository [] ╷ │ Error: POST https://api.github.com/repos/xxxxx/test-action-build/projects: 410 Projects are disabled for this repository [] │ │ with github_repository_project.project, │ on main.tf line 35, in resource "github_repository_project" "project": │ 35: resource "github_repository_project" "project" { │ ╵ 2024-02-17T17:11:39.363-0300 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF" 2024-02-17T17:11:39.365-0300 [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/hashicorp/github/6.0.0/linux_amd64/terraform-provider-github_v6.0.0 pid=2541 2024-02-17T17:11:39.365-0300 [DEBUG] provider: plugin exited

StephenWithPH commented 6 months ago

I stumbled upon this issue while searching for https://github.com/integrations/terraform-provider-github/issues/1910 .

I speculate that the errors seen above might be related to https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository#has_projects :

Per the GitHub documentation when in an organization that has disabled repository projects it will default to false and will otherwise default to true. If you specify true when it has been disabled it will return an error.