{"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":"validation","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/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/workdir/backend_state.go#L98-L134","documentation":"A state_store block must record how its provider was supplied via provider_supply_mode (one of: builtin, managed-by-terraform, reattached, dev-override — see getproviders.ProviderSupplyMode). The check at backend_state.go:113 rejects an empty value early because later code (statestore_config_state.go:65) branches on it and would otherwise produce confusing downstream errors about missing version data.","triggerScenarios":"ParseBackendStateFile finds StateStore != nil but StateStore.ProviderSupplyMode == '' (backend_state.go:113).","commonSituations":"A state_store file written by an early/buggy Terraform build that did not populate provider_supply_mode; manual editing that dropped the field; a half-completed migration.","solutions":["Re-run 'terraform init' with a current Terraform release so the file is rewritten with provider_supply_mode populated.","If editing by hand, set provider_supply_mode to the correct value for how the provider is installed (typically 'managed-by-terraform').","If this recurs on a released Terraform, report it — the write path should always set the field."],"exampleFix":"// before — .terraform/terraform.tfstate:\n{ \"version\":3, \"state_store\":{ \"type\":\"...\", \"provider\":{...}, \"config\":{...}, \"hash\":0, \"provider_supply_mode\":\"\" } }\nError: ... missing the required 'provider_supply_mode' property\n\n// after\n{ \"version\":3, \"state_store\":{ ..., \"provider_supply_mode\":\"managed-by-terraform\" } }\n// or: rm -rf .terraform && terraform init","handlingStrategy":"validation","validationCode":"// Ensure provider_supply_mode is set before encoding.\nfunc stateStoreHasSupplyMode(s *StateStoreConfigState) bool {\n    return s != nil && s.ProviderSupplyMode != \"\"\n}","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Always populate ProviderSupplyMode when constructing a StateStoreConfigState programmatically.","Use a released Terraform to write state_store files so the field is always set.","Add a unit test that asserts every encoded state_store record has a non-empty supply mode."],"tags":["terraform","state-store","provider","workdir"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}