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

  1. Read the wrapped %w to find the exact provider attribute/type that failed.
  2. Align the provider configuration block with the state-store provider's documented schema.
  3. Upgrade or pin the state-store provider consistently in required_providers and re-run migrate.
  4. 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

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


AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07). Data as JSON: /api/errors/59726916ab34620b. Report an issue: GitHub.