terraform-provider-github icon indicating copy to clipboard operation
terraform-provider-github copied to clipboard

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

Open xaurx opened this issue 1 year ago • 3 comments

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

  • provider registry.terraform.io/hashicorp/github v6.2.1
  • provider registry.terraform.io/hashicorp/google v5.26.0
  • provider registry.terraform.io/integrations/github v6.2.1

Affected Resource(s)

all

Terraform Configuration Files

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

Steps to Reproduce

just terraform apply:

  • with token/owner specified in provider -- doesn't work
  • with token/owner specified in env vars -- works fine

Debug Output

No response

Panic Output

No response

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

xaurx avatar Apr 25 '24 12:04 xaurx

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

xaurx avatar Apr 25 '24 18:04 xaurx

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.

dcfsc avatar May 15 '24 20:05 dcfsc

I'm encountering this in provider version 6.4.0. I have GITHUB_TOKEN set and the owner set via the provider configuration block and:

2024-11-21T01:29:18.194Z [INFO]  provider.terraform-provider-github_v6.4.0: 2024/11/21 01:29:18 [INFO] Selecting owner  from GITHUB_OWNER environment variable: timestamp=2024-11-21T01:29:18.194Z

babelfish avatar Nov 21 '24 01:11 babelfish

I think the root cause is co-existing of hashicorp/github and integrations/github. The arguments token/owner are not ignored, but input into only one or the other.

cf. https://github.com/integrations/terraform-provider-github/issues/652#issuecomment-1202721383

mikutas avatar Mar 10 '25 09:03 mikutas