terraform-provider-github: [BUG] Provider config not being loaded when passed directly in config block

Terraform Version

Terraform v1.2.4
on linux_amd64

Affected Resource(s)

Provider config can affect resources indirectly, for example:

  • github_repository -> The owner can be implicitly set via the PAT token passed to the provider.

If this issue appears to affect multiple resources, it may be an issue with Terraform’s core, so please mention this.

Terraform Configuration Files

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

provider "github" {
  token = "<PAT>"
}

resource "github_repository" "project_repository" {
  name        = "testing"
  description = "test description"

  visibility = "public"

  template {
    owner      = "IgorAssuncao"
    repository = "igor-nodejs-boilerplate"
  }
}

Debug Output

Gist link

Panic Output

N/A

Expected Behavior

According to the documentation we can set the PAT directly in the provider config and the owner of the provided PAT will be used implicitly.

Actual Behavior

The owner isn’t being set up accordingly but only when I provide the PAT in the provider config. If I use the PAT as an environment variable then everything works as expected.

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. Configure the provider providing a PAT directly in the provider config block.
  2. Define a github_repository resource.
  3. Run TF_LOG="DEBUG" terraform apply , provide yes when requested and check the request section of the output of the failed creation (should be the same as in the gist).

Important Factoids

N/A

References

N/A

Extras

Maybe if this is the desired behaviour then it should be documented that you can only provide a PAT as an environment variable.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 5
  • Comments: 18 (7 by maintainers)

Most upvoted comments

For anyone that comes across this, the issue seems to be if you don’t specify the provider in a sub-module it tries to default a hashicorp provider that no longer exists. To resolve the issue make sure your sub-module has a terraform block like this:

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

@kfcampbell it seems that you are right, I have moved the config block to the module and it worked