{"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/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/workdir/statestore_config_state.go#L37-L73","documentation":"ConfigRaw holds the raw JSON of the state_store block's own arguments excluding the provider (statestore_config_state.go:30). Validate() at statestore_config_state.go:54 rejects a nil ConfigRaw because there would be nothing to decode against the schema later in Config()/PlanData().","triggerScenarios":"Validate() called on a StateStoreConfigState whose ConfigRaw is nil — typically because SetConfig was never called.","commonSituations":"State store object built without invoking SetConfig; file written without the config payload; programming error in the init path.","solutions":["If seen at runtime, report a Terraform bug.","Re-run 'terraform init' to regenerate.","In caller code, call SetConfig(val, schema) to populate ConfigRaw before encoding."],"exampleFix":"// before\ns := &StateStoreConfigState{Type:\"remote\", Provider:prov, ProviderSupplyMode:getproviders.ManagedByTerraform}\n// ConfigRaw nil -> error 770\n\n// after\ns.SetConfig(configVal, storeSchema)","handlingStrategy":"validation","validationCode":"if s.ConfigRaw == nil {\n    // populate first:\n    // _ = s.SetConfig(val, storeSchema)\n    return errors.New(\"state store config payload is missing\")\n}","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Always call SetConfig(val, schema) after constructing a StateStoreConfigState.","Verify ConfigRaw is non-nil in a constructor/builder before returning the object.","Re-init to regenerate a complete file."],"tags":["terraform","state-store","config","validation"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}