integrations / terraform-provider-github

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

[BUG]: token/owner are ignored in provider, only env vars take into affect #2242

Open xaurx opened 5 months ago

xaurx commented 5 months ago

Expected Behavior

I initialize github provider v6.2.1 (latest at the moment) as following:

provider "github" {
  owner = "myorg"
  token = "ghp_XXX"
}

and it doesn't work, yet when I supply the same owner/token in env vars GITHUB_OWNER/GITHUB_TOKEN - it works.

I tried to debug using TF_LOG_PROVIDER=info, the only interesting messages:

2024-04-25T08:37:43.668-0400 [INFO]  provider.terraform-provider-github_v6.2.1: 2024/04/25 08:37:43 [INFO] Selecting owner  from GITHUB_OWNER environment variable: timestamp=2024-04-25T08:37:43.668-0400

and soon:

2024-04-25T08:37:45.302-0400 [INFO]  provider.terraform-provider-github_v6.2.1: 2024/04/25 08:37:45 [DEBUG] Rate limit 0 reached, sleeping for 59m59.697202s (until 2024-04-25 09:37:45.000001 -0400 EDT m=+3601.3945569
18) before retrying: timestamp=2024-04-25T08:37:45.302-0400

this seems related to the fact that no token provided.

since i want to keep token encrypted in TF files I need a way to pass it to provider not using env vars. please advise.

Actual Behavior

token/owner specified directly in provider are not used. (I verified that I don't have env vars set to any values at all)

Terraform Version

Terraform v1.5.7 on darwin_arm64

Affected Resource(s)

all

Terraform Configuration Files

provider "github" {
  owner = "myorg"
  token = "ghp_XXX"
}

Steps to Reproduce

just terraform apply:

Debug Output

No response

Panic Output

No response

Code of Conduct

xaurx commented 5 months ago

@wyatterp365 seems you forgot/lost comment you wanted to type.

dcfsc commented 4 months ago

I see the same behavior with the 5.45.0 provider. I was setting the GITHUB_TOKEN env var, AND an env var github_pat_token that was used to set the token into the provider block via TF_VAR_github_pat_token

provider "github" {
  owner = "XXXXXX"
  read_delay_ms = 500
  token = var.github_pat_token
}

What's weird is this worked with the same setup last week. Others in my team are currently able to use it. I spent 2 days figuring out that I need to comment out the token value:

provider "github" {
  owner = "XXXXX"
  read_delay_ms = 500
#   token = var.github_pat_token
}

with ONLY the GITHUB_TOKEN env var set, it works.