{"record":{"id":"98fa0e449e6b628c","repo":"hashicorp/terraform","slug":"attempted-to-encode-a-malformed-backend-state-file-98fa0e","errorCode":null,"errorMessage":"attempted to encode a malformed backend state file; state_store configuration data is missing","messagePattern":"attempted to encode a malformed backend state file; state_store configuration data is missing","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/workdir/statestore_config_state.go","lineNumber":55,"sourceCode":"\treturn s == nil || s.Type == \"\"\n}\n\n// Validate returns true if there are no missing expected values, and\n// important values have been validated, e.g. FQNs. When the config is\n// invalid an error will be returned.\nfunc (s *StateStoreConfigState) Validate() error {\n\t// Are any bits of data totally missing?\n\tif s.Empty() {\n\t\treturn fmt.Errorf(\"attempted to encode a malformed backend state file; data is empty\")\n\t}\n\tif s.Type == \"\" {\n\t\treturn fmt.Errorf(\"attempted to encode a malformed backend state file; state store type is missing\")\n\t}\n\tif s.Provider == nil {\n\t\treturn fmt.Errorf(\"attempted to encode a malformed backend state file; provider data is missing\")\n\t}\n\tif s.ConfigRaw == nil {\n\t\treturn fmt.Errorf(\"attempted to encode a malformed backend state file; state_store configuration data is missing\")\n\t}\n\n\t// Validity of data that is there\n\terr := s.Provider.Source.Validate()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"state store is not valid: %w\", err)\n\t}\n\n\t// Version information is required if the provider isn't builtin or unmanaged by Terraform\n\tswitch s.ProviderSupplyMode {\n\tcase getproviders.BuiltIn, getproviders.Reattached, getproviders.DevOverride:\n\t\t// These modes do not require version information\n\tcase getproviders.ManagedByTerraform:\n\t\tif s.Provider.Version == nil {\n\t\t\treturn fmt.Errorf(\"state store is not valid: provider version data is missing despite provider %s being managed by Terraform.\", s.Provider.Source.ForDisplay())\n\t\t}\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))","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/workdir/statestore_config_state.go#L37-L73","documentation":"StateStoreConfigState.Validate() found ConfigRaw == nil. ConfigRaw is the msgpack/json-encoded state_store configuration body; without it Terraform cannot reconstruct the state_store's arguments at plan/apply time, so encoding is refused.","triggerScenarios":"A state_store record missing its `config` field — partial file write, hand-editing, or programmatic construction that omitted ConfigRaw.","commonSituations":"Interrupted `terraform init`, third-party tool that builds StateStoreConfigState without encoding the config body, file corruption.","solutions":["Re-run `terraform init` to regenerate the file with ConfigRaw populated.","Delete the corrupt file and re-init from the state_store configuration block.","Restore from backup."],"exampleFix":"rm .terraform/terraform.tfstate\nterraform init","handlingStrategy":"validation","validationCode":"// pre-flight: require ConfigRaw for state_store\nif s.ConfigRaw == nil {\n    return errors.New(\"state_store requires configuration data; populate ConfigRaw before encoding\")\n}","typeGuard":"func (s *StateStoreConfigState) hasConfigRaw() bool { return s != nil && s.ConfigRaw != nil }","tryCatchPattern":null,"preventionTips":["Encode the config body when constructing StateStoreConfigState in code.","Let `terraform init` own the file."],"tags":["backend","state-store","validate","missing-field","config"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}