fix: prefer provider block attributes over environment variables - #103
Conversation
Configure() previously seeded host/api_key from DEVHUB_HOST/DEVHUB_API_KEY and only fell back to the provider-block values when the env vars were empty. That gave environment variables precedence over explicitly-set host/api_key attributes, the inverse of the Terraform Plugin Framework convention. Invert both conditions so an explicitly-set config value wins and the env var is only a fallback, matching the framework's canonical Configure example (https://developer.hashicorp.com/terraform/plugin/framework/providers). The acceptance test providerConfig previously hardcoded host/api_key and relied on the old env-wins behavior for CI to override them. It now sources host from DEVHUB_HOST and omits api_key so it falls through to DEVHUB_API_KEY, preserving the CI-provided host/key under the corrected precedence.
PR Summary by QodoFix provider config precedence (provider block overrides env vars)
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
Code Review by Qodo
1. Env baked into providerConfig
|
fix: prefer provider block attributes over environment variables
Problem
Configure()seededhost/api_keyfromDEVHUB_HOST/DEVHUB_API_KEYand onlyfell back to the provider-block values when those env vars were empty. This gave
environment variables precedence over explicitly-set provider-block attributes —
the inverse of the Terraform Plugin Framework convention.
Behavior change
DEVHUB_HOST/DEVHUB_API_KEYoverride an explicitly-sethost/api_keyin theprovider "devhub"block. The block value is used only when theenv var is empty.
host/api_keyin the provider block wins; theenv var is used only as a fallback when the attribute is unset/empty.
Justification
This matches the Plugin Framework's canonical
Configureexample, which seeds fromthe env var and then overrides with the config value when set:
https://developer.hashicorp.com/terraform/plugin/framework/providers
This is a behavior change for anyone who relied on the old env-wins ordering — e.g.
setting
DEVHUB_HOST/DEVHUB_API_KEYin the environment to override a value writtenin the provider block. After this change the provider-block value takes precedence.
To keep env-based configuration, leave the corresponding provider-block attribute
unset so the env var is used as the fallback.
Tests
The acceptance test
providerConfigpreviously hardcodedhost = "http://localhost:4000"and
api_key = "test", relying on the old env-wins behavior for CI to override them viaDEVHUB_HOST/DEVHUB_API_KEY. Sincehostis a Required attribute, the block can't beempty, so it now sources
hostfromDEVHUB_HOSTand omitsapi_key(falling through toDEVHUB_API_KEY) — preserving the CI-provided host/key under the corrected precedence.Verification
gofmt -s,go build ./...,go vet ./...all cleango generate ./...produces no generated-docs driftTF_ACC+ a real Devhub host/secret)🤖 Generated with Claude Code