{"record":{"id":"43b74c85795f641b","repo":"hashicorp/terraform","slug":"attempted-to-encode-a-malformed-backend-state-file-43b74c","errorCode":null,"errorMessage":"attempted to encode a malformed backend state file; provider data is missing","messagePattern":"attempted to encode a malformed backend state file; provider data is missing","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/workdir/statestore_config_state.go","lineNumber":52,"sourceCode":"\n// Empty returns true if there is no active state store.\nfunc (s *StateStoreConfigState) Empty() bool {\n\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())","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/workdir/statestore_config_state.go#L34-L70","documentation":"A state_store requires a nested provider description (the Provider *ProviderConfigState field, statestore_config_state.go:29). Validate() at statestore_config_state.go:51 fails when s.Provider == nil because without provider identity the state cannot be decoded or locked later.","triggerScenarios":"Validate() is called on a StateStoreConfigState whose Provider field was never assigned.","commonSituations":"Bug in code that builds state_store config without setting the provider; a malformed file loaded and then re-validated; partial migration of state_store data.","solutions":["If seen at runtime as a user, report a Terraform bug.","Re-run 'terraform init' to regenerate a complete state_store record.","In caller code, always populate Provider (Source, and Version for managed providers) before encoding."],"exampleFix":"// before\ns := &StateStoreConfigState{Type:\"remote\", ConfigRaw:raw, ProviderSupplyMode:getproviders.ManagedByTerraform}\n// s.Provider is nil -> error 769\n\n// after\ns.Provider = &ProviderConfigState{Source: addr, Version: ver, ConfigRaw: provRaw}","handlingStrategy":"validation","validationCode":"if s.Provider == nil {\n    return errors.New(\"state store requires a nested provider config\")\n}","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Populate Provider whenever you set StateStore on a BackendStateFile.","Unit-test that every code path writing state_store config sets Provider.","Re-init to recover if a malformed file is already on disk."],"tags":["terraform","state-store","provider","validation"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}