Skip to content

feat: add github_client_config data source#3419

Open
jaredfholgate wants to merge 3 commits into
integrations:mainfrom
jaredfholgate:feat/client-config-data-source
Open

feat: add github_client_config data source#3419
jaredfholgate wants to merge 3 commits into
integrations:mainfrom
jaredfholgate:feat/client-config-data-source

Conversation

@jaredfholgate
Copy link
Copy Markdown

@jaredfholgate jaredfholgate commented May 12, 2026

Resolves #3418


Before the change?

  • There is no way to inspect the resolved provider configuration from
    HCL. In particular, when owner is supplied via the GITHUB_OWNER
    environment variable it is not visible in configuration, and there is
    no first-class way to discover the login of the user the provider is
    authenticating as.

After the change?

  • A new github_client_config data source exposes:
    • owner — the resolved owner (provider argument / GITHUB_OWNER
      env var, falling back to the authenticated user's login).
    • is_organization — whether the resolved owner is an organization.
    • username — the login of the user the provider is authenticated as.
    • base_url — the GitHub API base URL the provider is using.
  • The data source takes no arguments and matches the pattern used by
    other providers (e.g. azurerm_client_config,
    google_client_config).

Test evidence

Authenticated (organization) mode — the authenticated sub-test runs and
the anonymous sub-test skips:

$ make testacc T='^TestAccGithubClientConfigDataSource$'
==> Running acceptance tests on branch: 🌿 feat/client-config-data-source 🌿...
TF_ACC=1 CGO_ENABLED=0 go test ./github/... -v -run '^TestAcc' -run='^TestAccGithubClientConfigDataSource$'  -timeout 120m -count=1
=== RUN   TestAccGithubClientConfigDataSource
=== RUN   TestAccGithubClientConfigDataSource/reads_provider_configuration_without_error
=== RUN   TestAccGithubClientConfigDataSource/reads_provider_configuration_in_anonymous_mode
    data_source_github_client_config_test.go:35: Skipping as test mode is not anonymous
--- PASS: TestAccGithubClientConfigDataSource (3.13s)
    --- PASS: TestAccGithubClientConfigDataSource/reads_provider_configuration_without_error (3.13s)
    --- SKIP: TestAccGithubClientConfigDataSource/reads_provider_configuration_in_anonymous_mode (0.00s)
PASS
ok      github.com/integrations/terraform-provider-github/v6/github     3.145s

Anonymous mode — the anonymous sub-test runs and the authenticated
sub-test skips:

$ GH_TEST_AUTH_MODE=anonymous make testacc T='^TestAccGithubClientConfigDataSource$'
==> Running acceptance tests on branch: 🌿 feat/client-config-data-source 🌿...
TF_ACC=1 CGO_ENABLED=0 go test ./github/... -v -run '^TestAcc' -run='^TestAccGithubClientConfigDataSource$'  -timeout 120m -count=1
=== RUN   TestAccGithubClientConfigDataSource
=== RUN   TestAccGithubClientConfigDataSource/reads_provider_configuration_without_error
    acc_test.go:291: Skipping as test mode not authenticated
=== RUN   TestAccGithubClientConfigDataSource/reads_provider_configuration_in_anonymous_mode
--- PASS: TestAccGithubClientConfigDataSource (1.57s)
    --- SKIP: TestAccGithubClientConfigDataSource/reads_provider_configuration_without_error (0.00s)
    --- PASS: TestAccGithubClientConfigDataSource/reads_provider_configuration_in_anonymous_mode (1.57s)
PASS
ok      github.com/integrations/terraform-provider-github/v6/github     1.590s

Together the two runs cover both sub-tests.

Manual local test

Built the provider locally and verified end-to-end with terraform plan
against the following configuration:

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

# Configure the GitHub Provider with environment variables
# export GITHUB_TOKEN="github_pat_******"
# export GITHUB_OWNER="alz-plz-001"
provider "github" {}

data "github_client_config" "current" {}

output "owner" {
  value = data.github_client_config.current.owner
}

output "username" {
  value = data.github_client_config.current.username
}

output "is_organization" {
  value = data.github_client_config.current.is_organization
}

output "base_url" {
  value = data.github_client_config.current.base_url
}

Output:

$ terraform plan
╷
│ Warning: Provider development overrides are in effect
│
│ The following provider development overrides are set in the CLI configuration:
│  - integrations/github in /home/jaredholgate/go/bin
│
│ The behavior may therefore not match any released version of the provider and applying changes may cause the state to become incompatible with published releases.
╵
data.github_client_config.current: Reading...
data.github_client_config.current: Read complete after 0s [id=alz-plz-001]

Changes to Outputs:
  + base_url        = "https://api.github.com/"
  + is_organization = true
  + owner           = "alz-plz-001"
  + username        = "jaredfholgate"

You can apply this plan to save these new output values to the Terraform state, without changing any real infrastructure.

Pull request checklist

  • Schema migrations have been created if needed (example)
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)

Does this introduce a breaking change?

  • Yes
  • No

Adds a new `github_client_config` data source that exposes the
provider's effective configuration: the resolved `owner`, whether
that owner is an organization, the authenticated `username`, and the
configured `base_url`.

This is useful when `owner` is supplied via the `GITHUB_OWNER`
environment variable (and therefore not visible in HCL) or when callers
need the login of the user the provider is authenticating as.

Resolves integrations#3418
@github-actions
Copy link
Copy Markdown

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

@github-actions github-actions Bot added the Type: Feature New feature or request label May 12, 2026
@doughlass
Copy link
Copy Markdown

Lovely addition, fills a real gap. The GITHUB_OWNER env var being invisible to HCL has always been annoying for reusable modules. Follows the azurerm_client_config pattern perfectly. Hope this gets merged so I could implement it into my infra! 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT]: Add github_client_config data source

2 participants