hashicorp/terraform · critical
Unable to determine if provider %s is reattached while initi
Error message
Unable to determine if provider %s is reattached while initializing the state store. This is a bug in Terraform and should be reported: %v
What it means
Programmer-error panic in getProviderSupplyModeForStateStore: reattach.IsProviderReattached returned an error when parsing TF_REATTACH_PROVIDERS for the state-store provider address. Rather than propagating the error, the code panics with the provider display name and the wrapped error. The message labels it a Terraform bug.
Source
Thrown at internal/command/meta_config.go:496
if m.View != nil {
m.View.SetConfigSources(loader.Sources)
}
}
return m.configLoader, nil
}
// registryClient instantiates and returns a new Terraform Registry client.
func (m *Meta) registryClient() *registry.Client {
return registry.NewClient(m.Services, nil)
}
func (m *Meta) getProviderSupplyModeForStateStore(config *configs.Module) getproviders.ProviderSupplyMode {
if config == nil || config.StateStore == nil {
return getproviders.Unset
}
isReattached, err := reattach.IsProviderReattached(config.StateStore.ProviderAddr, os.Getenv("TF_REATTACH_PROVIDERS"))
if err != nil {
panic(fmt.Sprintf("Unable to determine if provider %s is reattached while initializing the state store. This is a bug in Terraform and should be reported: %v", config.StateStore.ProviderAddr.ForDisplay(), err))
}
return getproviders.DetermineProviderSupplyMode(m.isProviderDevOverride(config.StateStore.ProviderAddr), isReattached, config.StateStore.ProviderAddr.IsBuiltIn())
}
// configValueFromCLI parses a configuration value that was provided in a
// context in the CLI where only strings can be provided, such as on the
// command line or in an environment variable, and returns the resulting
// value.
func configValueFromCLI(synthFilename, rawValue string, wantType cty.Type) (cty.Value, tfdiags.Diagnostics) {
var diags tfdiags.Diagnostics
switch {
case wantType.IsPrimitiveType():
// Primitive types are handled as conversions from string.
val := cty.StringVal(rawValue)
var err error
val, err = convert.Convert(val, wantType)
if err != nil {View on GitHub (pinned to d32a084675)
Solutions
- Unset or correct TF_REATTACH_PROVIDERS (ensure it is valid JSON with the right provider source address and protocol/port).
- If not developing a state-store provider, remove the env var entirely.
- Regenerate the reattach config using the provider's dev tooling.
Example fix
# before
export TF_REATTACH_PROVIDERS='{malformed json'
# after
unset TF_REATTACH_PROVIDERS
# or, valid:
export TF_REATTACH_PROVIDERS='{"registry.terraform.io/hashicorp/local":{"Protocol":"grpc","ProtocolVersion":6,"Pid":12345,"Test":true,"Addr":{"Network":"unix","String":"/tmp/plugin"}}}' Defensive patterns
Strategy: validation
Validate before calling
// Validate the reattach env var before relying on it.
if raw := os.Getenv("TF_REATTACH_PROVIDERS"); raw != "" {
if _, err := reattach.ParseProviders(raw); err != nil {
return getproviders.Unset, fmt.Errorf("invalid TF_REATTACH_PROVIDERS: %w", err)
}
} Prevention
- Unset TF_REATTACH_PROVIDERS when not developing providers.
- Regenerate the env var from provider dev tooling rather than editing by hand.
- Validate the JSON before launching Terraform in dev mode.
When it happens
Trigger: TF_REATTACH_PROVIDERS environment variable is set (provider dev mode) but contains malformed JSON for the state-store provider entry, causing IsProviderReattached to return a non-nil err.
Common situations: Provider development workflow with a malformed TF_REATTACH_PROVIDERS payload; leftover/stale reattach env var pointing at a non-existent provider; editing the env var by hand introducing a syntax error.
Related errors
- nil config passed to StateStoreProviderFactoryFromConfigStat
- init (determineIfProviderTrusted): unexpected provider locat
- Unexpected command type in confirmProviderIsTrusted; this is
- When installing providers described in the config Terraform
- errStateStoreInitDiag requires a non-nil reason argument
AI-assisted analysis of hashicorp/terraform@d32a084675 (2026-08-11).
Data as JSON: /api/errors/ad1d90c80337004f.
Report an issue: GitHub.