hashicorp/terraform · error
Failed to set state store provider configuration: %w
Error message
Failed to set state store provider configuration: %w
What it means
Thrown during `terraform state migrate` to a state_store destination when bsf.StateStore.Provider.SetConfig(providerConfigVal, dstB.ProviderSchema()) fails. This captures the destination state-store *provider's* own configuration (distinct from the state store config) into the backend state file. The %w is the ctyjson marshal error against the provider's schema, naming the non-conforming attribute/type.
Source
Thrown at internal/command/state_migrate.go:312
bsf.StateStore = &workdir.StateStoreConfigState{
Type: rootMod.StateStore.Type,
Hash: uint64(cHash),
Provider: &workdir.ProviderConfigState{
Source: &rootMod.StateStore.ProviderAddr,
Version: version,
},
ProviderSupplyMode: rootMod.StateStore.ProviderSupplyMode,
}
err = bsf.StateStore.SetConfig(stateStoreConfigVal, dstB.ConfigSchema())
if err != nil {
diags = diags.Append(fmt.Errorf("Failed to set state store configuration: %w", err))
view.Diagnostics(diags)
return 1
}
err = bsf.StateStore.Provider.SetConfig(providerConfigVal, dstB.ProviderSchema())
if err != nil {
diags = diags.Append(fmt.Errorf("Failed to set state store provider configuration: %w", err))
view.Diagnostics(diags)
return 1
}
} else {
diags = diags.Append(tfdiags.Sourceless(
tfdiags.Error,
"Unknown migration destination",
"No configuration was provided for where to migrate the state to. Please ensure that a file with a .tf extension is present and contains valid state_store or backend configuration inside the terraform block.",
))
}
// present all errors from above together so user can fix them all at once
if diags.HasErrors() {
view.Diagnostics(diags)
return 1
}
View on GitHub (pinned to c9def3e214)
Solutions
- Read the wrapped %w to find the exact provider attribute/type that failed.
- Align the provider configuration block with the state-store provider's documented schema.
- Upgrade or pin the state-store provider consistently in required_providers and re-run migrate.
- Remove stale provider alias blocks no longer matching the provider schema.
Example fix
# before
provider "foo" {
alias = "state"
legacy_field = true # removed in current provider version
}
# after
provider "foo" {
alias = "state"
region = "us-east-1"
} Defensive patterns
Strategy: validation
Validate before calling
// verify the state-store *provider* config conforms to the provider schema
func validateProviderConfig(val cty.Value, schema *configschema.Block) error {
_, err := ctyjson.Marshal(val, schema.ImpliedType())
return err
} Prevention
- Keep provider configuration blocks aligned with the provider version in required_providers.
- Remove stale provider alias blocks after provider upgrades.
- Validate after every provider version change.
- Pin provider versions to avoid silent schema drift.
When it happens
Trigger: Running `terraform state migrate` to a state_store where the provider configuration value produced by stateStoreInitFromConfig does not conform to the provider schema returned by dstB.ProviderSchema().
Common situations: Provider-level configuration attributes changed between provider versions; a provider alias block with invalid attributes; schema drift after upgrading the state-store provider; mixed required_providers entries referencing the same provider with differing versions.
Related errors
- Failed to set state store provider configuration: %w
- Failed to convert provider version to Go version: %s
- Failed to set state store configuration: %w
- missing provider schema
- Failed to negotiate acceptable chunk size. Expected size > 0
AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07).
Data as JSON: /api/errors/59726916ab34620b.
Report an issue: GitHub.