hashicorp/terraform · error

Failed to set state store configuration

Error message

Failed to set state store configuration: %w

What it means

Thrown during state-store migration when bsf.StateStore.SetConfig(stateStoreConfigVal, dstB.ConfigSchema()) fails to serialize the state-store (not provider) configuration. Mirrors [747] but for the `state_store` block rather than `backend` block. Uses %w so the underlying error is preserved.

Solutions

  1. Read the wrapped err for the exact attribute/schema mismatch.
  2. Confirm the state-store provider is in required_providers and was downloaded (`terraform providers` shows it).
  3. Cross-check each attribute against the state-store provider's docs.
  4. Run `terraform init -upgrade` to refresh the schema from a freshly downloaded provider binary.

Example fix

// before
 terraform {
   state_store "xyz" {
     cluster = "prod"
   }
 }

// after
 terraform {
   state_store "xyz" {
     cluster = "prod"
     region  = "us-east-1"
   }
 }
Defensive patterns

Strategy: validation

Validate before calling

// Pre-validate state_store block schema.
if _, diags := dstB.ConfigSchema().Validate(stateStoreConfigVal); diags.HasErrors() {
    return diags
}

Try / catch

if err := bsf.StateStore.SetConfig(stateStoreConfigVal, dstB.ConfigSchema()); err != nil {
    diags = diags.Append(fmt.Errorf("Failed to set state store configuration: %w", err))
    view.Diagnostics(diags)
    hintInvalidStateStoreBlock(view, rootMod.StateStore.Type)
    return 1
}

Prevention

When it happens

Trigger: The state_store block's hcl config value does not match dstB.ConfigSchema(): missing required attributes, type mismatches, unknown values, or schema is empty because the state-store provider wasn't loaded correctly.

Common situations: State-store block missing required fields; `required_providers` does not include the state-store provider at the right source address; typo'd attribute names; variable interpolation left unresolved because state_store blocks are evaluated early.

Related errors


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

Appendix: source

Thrown at internal/command/state_migrate.go:308

		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 d32a084675)