{"record":{"id":"441bf995c0a5f7cd","repo":"hashicorp/terraform","slug":"encountered-a-malformed-backend-state-file-with-a","errorCode":null,"errorMessage":"encountered a malformed backend state file with a 'state_store' block that is missing the required 'provider_supply_mode' property","messagePattern":"encountered a malformed backend state file with a 'state_store' block that is missing the required 'provider_supply_mode' property","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/workdir/backend_state.go","lineNumber":116,"sourceCode":"\tvar stateFile BackendStateFile\n\terr = json.Unmarshal(src, &stateFile)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid syntax: %w\", err)\n\t}\n\tif stateFile.Backend == nil && stateFile.Remote != nil {\n\t\t// It's very unlikely to get here, but one way it could happen is\n\t\t// if this working directory was most recently used with Terraform v0.8\n\t\t// or earlier, which didn't yet include the concept of backends.\n\t\t// This error message assumes that's the case.\n\t\treturn nil, fmt.Errorf(\"this working directory uses legacy remote state and so must first be upgraded using Terraform v0.9\")\n\t}\n\tif stateFile.Backend != nil && stateFile.StateStore != nil {\n\t\treturn nil, fmt.Errorf(\"encountered a malformed backend state file that contains state for both a 'backend' and a 'state_store' block\")\n\t}\n\tif stateFile.StateStore != nil && stateFile.StateStore.ProviderSupplyMode == \"\" {\n\t\t// Check for this, as lacking this data can cause problems later when an empty provider version\n\t\t// is encountered. This error will make debugging much easier.\n\t\treturn nil, fmt.Errorf(\"encountered a malformed backend state file with a 'state_store' block that is missing the required 'provider_supply_mode' property\")\n\t}\n\n\treturn &stateFile, nil\n}\n\nfunc EncodeBackendStateFile(f *BackendStateFile) ([]byte, error) {\n\tf.Version = 3 // we only support version 3\n\tf.TFVersion = version.SemVer.String()\n\n\tswitch {\n\tcase f.Backend != nil && f.StateStore != nil:\n\t\treturn nil, fmt.Errorf(\"attempted to encode a malformed backend state file; it contains state for both a 'backend' and a 'state_store' block. This is a bug in Terraform and should be reported.\")\n\tcase f.Backend == nil && f.StateStore == nil:\n\t\t// This is valid - if the user has a backend state file and an implied local backend in use\n\t\t// the backend state file exists but has no Backend data.\n\tcase f.Backend != nil:\n\t\t// Not implementing anything here - risk of breaking changes\n\tcase f.StateStore != nil:","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/workdir/backend_state.go#L98-L134","documentation":"ParseBackendStateFile decoded a state_store block but its required `provider_supply_mode` property is empty/missing. ProviderSupplyMode drives how Terraform sources the state-store's nested provider (built-in, managed-by-terraform, reattached, dev-override); without it later code would crash on an empty version, so parsing fails fast with a clear message instead.","triggerScenarios":"A .terraform/terraform.tfstate with a `state_store` object that omits `provider_supply_mode`. Possible causes: hand-editing, a buggy/old fork that didn't write the field, or a file truncated mid-write.","commonSituations":"Pre-release or experimental state_store support that predates the field, third-party tooling that wrote an incomplete state_store block, or filesystem-level tampering.","solutions":["Re-run `terraform init` so the state_store block is rewritten with all required fields.","Verify you are on a Terraform/OpenTofu version that actually supports state_store — older versions never wrote this field.","Delete the corrupt file and re-init from your state_store configuration block."],"exampleFix":"rm .terraform/terraform.tfstate\nterraform init","handlingStrategy":"validation","validationCode":"// pre-flight: require provider_supply_mode on state_store\nvar probe struct {\n    StateStore *struct {\n        Mode string `json:\"provider_supply_mode\"`\n    } `json:\"state_store\"`\n}\n_ = json.Unmarshal(src, &probe)\nif probe.StateStore != nil && probe.StateStore.Mode == \"\" {\n    return nil, errors.New(\"state_store block missing provider_supply_mode; re-run `terraform init`\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Stay on a Terraform/OpenTofu version that supports state_store end-to-end.","Don't hand-edit the state_store section."],"tags":["backend","state-store","missing-field","init"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}