hashicorp/terraform · error

Failed to set state store configuration

Error message

Failed to set state store configuration: %w

What it means

When persisting the freshly initialized state_store config into the cache file, s.StateStore.SetConfig(storeConfigVal, b.ConfigSchema()) failed. The wrapped %w is the encode error: the state-store config value could not be serialized against the state store's declared schema.

Solutions

  1. Read inner %w to find the offending attribute/type.
  2. Update (or pin) the state-store provider so its schema matches the config and the Terraform build.
  3. Remove undocumented/extra keys from the state_store block; keep only schema-declared attributes.
  4. Run `tofu init -upgrade` to align the cached provider with the lock file, then re-init.

Example fix

// before
state_store "acme" {
  provider = "example.com/acme/storage"
  region  = "eu-west-1"
  unknown = true  # not in state-store schema
}

// after
state_store "acme" {
  provider = "example.com/acme/storage"
  region  = "eu-west-1"
}
Defensive patterns

Strategy: validation

Validate before calling

// Validate the state-store config block against the provider's state-store
// schema before persisting.
func validateStateStoreConfig(storeCfg cty.Value, schema *configschema.Block) error {
    if schema == nil { return fmt.Errorf("state-store schema is nil") }
    if err := schema.ImpliedType().Value(storeCfg); err != nil {
        return fmt.Errorf("state-store config does not match schema: %w", err)
    }
    return nil
}

Try / catch

if err := s.StateStore.SetConfig(storeConfigVal, b.ConfigSchema()); err != nil {
    if isJSONEncodingErr(err) {
        diags = diags.Append(fmt.Errorf("state-store config does not match schema (remove undocumented keys / align provider version): %w", err))
    } else {
        diags = diags.Append(fmt.Errorf("Failed to set state store configuration: %w", err))
    }
    return nil, diags
}

Prevention

When it happens

Trigger: SetConfig fails on the state_store schema with storeConfigVal. Triggers: state store schema nil/malformed, configVal has attributes or types not declared in the schema, or version skew between the provider's state-store schema and this Terraform build.

Common situations: State-store provider plugin version mismatch; extra/unknown keys in the state_store block; a provider that changed its state-store schema between versions while the cache/lock pinned the old one.

Related errors


AI-assisted analysis of hashicorp/terraform@d32a084675 (2026-08-11). Data as JSON: /api/errors/87e33a4ab755b503. Report an issue: GitHub.

Appendix: source

Thrown at internal/command/meta_backend.go:2272

	pVersion, vDiags := getStateStorageProviderVersion(c, opts.Locks) // pVersion will remain nil for builtin, dev override, and unmanaged providers.
	diags = diags.Append(vDiags)
	if vDiags.HasErrors() {
		return nil, diags
	}

	s.Backend = nil // unset this; user may be running `terraform init -reconfigure` and there's a preexisting backend state file.
	s.StateStore = &workdir.StateStoreConfigState{
		Type: c.Type,
		Hash: uint64(stateStoreHash),
		Provider: &workdir.ProviderConfigState{
			Source:  &c.ProviderAddr,
			Version: pVersion,
		},
		ProviderSupplyMode: c.ProviderSupplyMode,
	}
	err := s.StateStore.SetConfig(storeConfigVal, b.ConfigSchema())
	if err != nil {
		diags = diags.Append(fmt.Errorf("Failed to set state store configuration: %w", err))
		return nil, diags
	}

	err = s.StateStore.Provider.SetConfig(providerConfigVal, b.ProviderSchema())
	if err != nil {
		diags = diags.Append(fmt.Errorf("Failed to set state store provider configuration: %w", err))
		return nil, diags
	}

	// Verify that selected workspace exists in the state store.
	if opts.Init && b != nil {
		if err := m.selectWorkspace(b); err != nil {
			if errors.Is(err, &errBackendNoExistingWorkspaces{}) {
				ws, err := m.Workspace()
				if err != nil {
					diags = diags.Append(fmt.Errorf("Failed to check current workspace: %w", err))
					return nil, diags
				}

View on GitHub (pinned to d32a084675)