{"record":{"id":"9b876e00767fc537","repo":"hashicorp/terraform","slug":"error-when-preparing-state-store-config-for-planfi","errorCode":null,"errorMessage":"error when preparing state store config for planfile: %s","messagePattern":"error when preparing state store config for planfile: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/workdir/statestore_config_state.go","lineNumber":122,"sourceCode":"\t\treturn err\n\t}\n\ts.ConfigRaw = buf\n\treturn nil\n}\n\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:","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/workdir/statestore_config_state.go#L104-L140","documentation":"StateStoreConfigState.PlanData called Validate() and it returned an error; PlanData wraps it with this message. The wrapped error is one of [772]-[777] describing the specific validation failure. PlanData runs while writing a plan file, so the user sees this when a `terraform plan` cannot serialise the state_store configuration.","triggerScenarios":"Running `terraform plan` (or any command that creates a plan) when the loaded StateStoreConfigState is invalid — empty, missing fields, bad provider source, or missing version under ManagedByTerraform mode.","commonSituations":"State file corrupted or partially written, mismatched Terraform version reading a newer state_store format, manual tampering.","solutions":["Read the wrapped error — it identifies which [772]-[777] check failed; follow that error's fix.","Re-run `terraform init` to rewrite a clean state_store record before planning.","Delete .terraform/terraform.tfstate and re-init if the record is unrecoverable."],"exampleFix":"rm .terraform/terraform.tfstate\nterraform init\nterraform plan","handlingStrategy":"try-catch","validationCode":"// pre-flight: validate before plan to surface a friendlier error\nif err := s.Validate(); err != nil {\n    return nil, fmt.Errorf(\"cannot write plan: state_store config invalid — re-run `terraform init`: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"store, err := s.PlanData(storeSchema, providerSchema, workspace)\nif err != nil {\n    if vErr := newValidateError(err); vErr != nil {\n        return nil, fmt.Errorf(\"plan blocked by invalid state_store (%v); run `terraform init` and retry\", vErr)\n    }\n    return nil, err\n}","preventionTips":["Always `terraform init` before `terraform plan`.","Treat plan-time state_store decode errors as init hygiene problems first."],"tags":["backend","state-store","plan","validate","wrapper"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}