{"record":{"id":"d069d94d92d5c6fc","repo":"hashicorp/terraform","slug":"failed-to-decode-state-store-config-w","errorCode":null,"errorMessage":"failed to decode state_store config: %w","messagePattern":"failed to decode state_store config: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/workdir/statestore_config_state.go","lineNumber":127,"sourceCode":"\n// PlanData produces an alternative representation of the receiver that is\n// suitable for storing in a plan. The current workspace must additionally\n// be provided, to be stored alongside the state store configuration.\n//\n// The state_store configuration schema is required in order to properly\n// encode the state store-specific configuration settings.\nfunc (s *StateStoreConfigState) PlanData(storeSchema *configschema.Block, providerSchema *configschema.Block, workspaceName string) (*plans.StateStore, error) {\n\tif s == nil {\n\t\tpanic(\"PlanData called on a nil *StateStoreConfigState receiver. This is a bug in Terraform and should be reported.\")\n\t}\n\n\tif err := s.Validate(); err != nil {\n\t\treturn nil, fmt.Errorf(\"error when preparing state store config for planfile: %s\", err)\n\t}\n\n\tstoreConfigVal, err := s.Config(storeSchema)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to decode state_store config: %w\", err)\n\t}\n\tproviderConfigVal, err := s.Provider.Config(providerSchema)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to decode state_store's nested provider config: %w\", err)\n\t}\n\n\tvar providerVersion *version.Version\n\tswitch s.ProviderSupplyMode {\n\tcase getproviders.BuiltIn, getproviders.Reattached, getproviders.DevOverride:\n\t\t// For built-in providers, reattached providers, and developer overrides, we don't require version information to be present in the state file, so we should be tolerant of it being missing.\n\t\t// In this case we can just use a placeholder version that will never actually be used for anything, but allows us to avoid returning an error when trying to save state store data to a plan file.\n\t\tproviderVersion = version.Must(version.NewVersion(\"0.0.0\"))\n\tcase getproviders.ManagedByTerraform:\n\t\tproviderVersion = s.Provider.Version\n\tdefault:\n\t\tpanic(fmt.Sprintf(\"State store provider %q (%s) has unknown supply mode %q. This is a bug in Terraform and should be reported.\", s.Provider.Source.Type, s.Provider.Source.ForDisplay(), s.ProviderSupplyMode))\n\t}\n","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/workdir/statestore_config_state.go#L109-L145","documentation":"In PlanData at statestore_config_state.go:125, the stored ConfigRaw JSON is decoded against the state_store schema's implied cty type via ctyjson.Unmarshal. A failure means the stored raw config does not conform to the current schema (an attribute type changed, an unknown/missing block, or corrupt bytes).","triggerScenarios":"s.Config(storeSchema) returns an error from ctyjson.Unmarshal because ConfigRaw doesn't fit storeSchema.ImpliedType().","commonSituations":"State-store provider schema changed between when the state was written and now; a provider upgrade altered attribute types; corrupt ConfigRaw bytes from a partial write.","solutions":["Re-run 'terraform init' against the current provider release so ConfigRaw is re-encoded for the current schema.","If mid-upgrade, follow the provider's upgrade guide and re-init.","Inspect the wrapped cty error for the offending attribute name and type mismatch."],"exampleFix":"// before\n$ terraform plan -out=tfplan\nError: failed to decode state_store config: ...attribute \"endpoint\": string required\n\n// after\n$ rm -rf .terraform && terraform init   # re-encodes ConfigRaw for current schema\n$ terraform plan -out=tfplan","handlingStrategy":"try-catch","validationCode":"// Probe-decode ConfigRaw against the schema before PlanData to fail with context.\nif _, err := s.Config(storeSchema); err != nil {\n    return fmt.Errorf(\"state_store config will not decode: %w\", err)\n}","typeGuard":"null","tryCatchPattern":"if _, err := s.PlanData(storeSchema, provSchema, ws); err != nil {\n    if strings.Contains(err.Error(), \"failed to decode state_store config\") {\n        // schema drift; re-init against current provider\n    }\n}","preventionTips":["Re-init whenever the state-store provider version changes.","Pin provider versions to avoid surprise schema drift.","Decode with the same schema version used to encode."],"tags":["terraform","plan","state-store","schema","decode"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}