integrations / terraform-provider-github

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

[BUG]: Provider fails to use the authentication token with data resources #2306

Closed jchancellor-ms closed 4 days ago

jchancellor-ms commented 4 days ago

Expected Behavior

I'm trying to return a registration token using data resources and both are failing. data.github_actions_registration_token and data.github_rest_api. When I do this with the rest API, a valid token is returned.

Actual Behavior

The API returns a 404 not found error when using the terraform provider logged in via the CLI. However, when I use the CLI token and call the rest API directly a token is returned. A gh auth status shows me logged in with a valid token.

Terraform Version

terraform 1.8.3 on linux_amd64 with github 6.2.2

Affected Resource(s)

data.github_actions_registration_token and data.github_rest_api

Terraform Configuration Files

terraform {
  required_providers {
    github = {
      source  = "integrations/github"
      version = "~> 6.0"
    }
  }
}

# Configure the GitHub Provider
provider "github" {
    owner = "my_user_name"
}

data "github_rest_api" "test" {
    endpoint = "repos/my_user_name/my_repo_name/actions/runners/registration-token"
}

data "github_actions_registration_token" "test_token" {
  repository = "my_repo_name"
}

output "test" {
    value = data.github_actions_registration_token.test_token.token
}

output "test2" {
    value = data.github_rest_api.test.body
}

Steps to Reproduce

gh auth login terraform init terraform apply

Debug Output

+ test2 = jsonencode(
        {
          + documentation_url = "https://docs.github.com/rest/actions/self-hosted-runners#get-a-self-hosted-runner-for-a-repository"
          + message           = "Not Found"
          + status            = "404"
        }
    )

│ Error: error creating a GitHub Actions repository registration token for my_user_name/my_repo: POST https://api.github.com/repos/my_user_name/my_repo/actions/runners/registration-token: 404 Not Found []

Panic Output

No response

Code of Conduct

jchancellor-ms commented 4 days ago

I determined that the gh version I was using was quite old. Upgraded to the latest version and re-tested and I'm now able to get a token with the github_actions_registration_token data resource. Still having issues with the api version, but I'll close this since the standard way appears to work.