hashicorp/terraform · error

Failed to set state store configuration: %w

Error message

Failed to set state store configuration: %w

What it means

Thrown during `terraform state migrate` to a state_store destination when bsf.StateStore.SetConfig(stateStoreConfigVal, dstB.ConfigSchema()) fails. SetConfig marshals the state-store config cty value to JSON against the state-store backend's ImpliedType; failure means the value does not conform to that schema. The %w carries the ctyjson marshal error naming the offending attribute/type.

Source

Thrown at internal/command/state_migrate.go:305

		version, err := providerreqs.GoVersionFromVersion(v)
		if err != nil {
			diags = diags.Append(fmt.Errorf("Failed to convert provider version to Go version: %s", err))
			view.Diagnostics(diags)
			return 1
		}

		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.",
		))
	}

View on GitHub (pinned to c9def3e214)

Solutions

  1. Read the wrapped %w: it identifies the exact attribute/type mismatch versus the state-store schema.
  2. Correct the state_store block to use only attributes documented by the state-store provider.
  3. Re-run `terraform init -upgrade` to pull a state-store provider whose schema matches the config.
  4. Pin the state-store provider to the version declared in required_providers to avoid silent schema changes.

Example fix

# before
terraform {
  state_store "foo" {
    unkown_attr = "x"  # typo, not in schema
  }
}

# after
terraform {
  state_store "foo" {
    region = "us-east-1"
  }
}
Defensive patterns

Strategy: validation

Validate before calling

// verify a state_store config value conforms to the state-store schema
func validateStateStoreConfig(val cty.Value, schema *configschema.Block) error {
    _, err := ctyjson.Marshal(val, schema.ImpliedType())
    return err
}

Prevention

When it happens

Trigger: Running `terraform state migrate` where the state_store block's configuration value does not match the schema advertised by the destination state-store provider/backend (stateStoreInitFromConfig produced a value incompatible with dstB.ConfigSchema()).

Common situations: State-store block with attributes the provider does not recognise; mismatched state-store provider version; typo'd or deprecated attribute in the state_store block; schema drift between provider versions.

Related errors


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