{"record":{"id":"87e33a4ab755b503","repo":"hashicorp/terraform","slug":"failed-to-set-state-store-configuration-w","errorCode":null,"errorMessage":"Failed to set state store configuration: %w","messagePattern":"Failed to set state store configuration: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/meta_backend.go","lineNumber":2272,"sourceCode":"\tpVersion, vDiags := getStateStorageProviderVersion(c, opts.Locks) // pVersion will remain nil for builtin, dev override, and unmanaged providers.\n\tdiags = diags.Append(vDiags)\n\tif vDiags.HasErrors() {\n\t\treturn nil, diags\n\t}\n\n\ts.Backend = nil // unset this; user may be running `terraform init -reconfigure` and there's a preexisting backend state file.\n\ts.StateStore = &workdir.StateStoreConfigState{\n\t\tType: c.Type,\n\t\tHash: uint64(stateStoreHash),\n\t\tProvider: &workdir.ProviderConfigState{\n\t\t\tSource:  &c.ProviderAddr,\n\t\t\tVersion: pVersion,\n\t\t},\n\t\tProviderSupplyMode: c.ProviderSupplyMode,\n\t}\n\terr := s.StateStore.SetConfig(storeConfigVal, b.ConfigSchema())\n\tif err != nil {\n\t\tdiags = diags.Append(fmt.Errorf(\"Failed to set state store configuration: %w\", err))\n\t\treturn nil, diags\n\t}\n\n\terr = s.StateStore.Provider.SetConfig(providerConfigVal, b.ProviderSchema())\n\tif err != nil {\n\t\tdiags = diags.Append(fmt.Errorf(\"Failed to set state store provider configuration: %w\", err))\n\t\treturn nil, diags\n\t}\n\n\t// Verify that selected workspace exists in the state store.\n\tif opts.Init && b != nil {\n\t\tif err := m.selectWorkspace(b); err != nil {\n\t\t\tif errors.Is(err, &errBackendNoExistingWorkspaces{}) {\n\t\t\t\tws, err := m.Workspace()\n\t\t\t\tif err != nil {\n\t\t\t\t\tdiags = diags.Append(fmt.Errorf(\"Failed to check current workspace: %w\", err))\n\t\t\t\t\treturn nil, diags\n\t\t\t\t}","sourceCodeStart":2254,"sourceCodeEnd":2290,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/meta_backend.go#L2254-L2290","documentation":"When persisting the freshly initialized state_store config into the cache file, s.StateStore.SetConfig(storeConfigVal, b.ConfigSchema()) failed. The wrapped %w is the encode error: the state-store config value could not be serialized against the state store's declared schema.","triggerScenarios":"SetConfig fails on the state_store schema with storeConfigVal. Triggers: state store schema nil/malformed, configVal has attributes or types not declared in the schema, or version skew between the provider's state-store schema and this Terraform build.","commonSituations":"State-store provider plugin version mismatch; extra/unknown keys in the state_store block; a provider that changed its state-store schema between versions while the cache/lock pinned the old one.","solutions":["Read inner %w to find the offending attribute/type.","Update (or pin) the state-store provider so its schema matches the config and the Terraform build.","Remove undocumented/extra keys from the state_store block; keep only schema-declared attributes.","Run `tofu init -upgrade` to align the cached provider with the lock file, then re-init."],"exampleFix":"// before\nstate_store \"acme\" {\n  provider = \"example.com/acme/storage\"\n  region  = \"eu-west-1\"\n  unknown = true  # not in state-store schema\n}\n\n// after\nstate_store \"acme\" {\n  provider = \"example.com/acme/storage\"\n  region  = \"eu-west-1\"\n}","handlingStrategy":"validation","validationCode":"// Validate the state-store config block against the provider's state-store\n// schema before persisting.\nfunc validateStateStoreConfig(storeCfg cty.Value, schema *configschema.Block) error {\n    if schema == nil { return fmt.Errorf(\"state-store schema is nil\") }\n    if err := schema.ImpliedType().Value(storeCfg); err != nil {\n        return fmt.Errorf(\"state-store config does not match schema: %w\", err)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := s.StateStore.SetConfig(storeConfigVal, b.ConfigSchema()); err != nil {\n    if isJSONEncodingErr(err) {\n        diags = diags.Append(fmt.Errorf(\"state-store config does not match schema (remove undocumented keys / align provider version): %w\", err))\n    } else {\n        diags = diags.Append(fmt.Errorf(\"Failed to set state store configuration: %w\", err))\n    }\n    return nil, diags\n}","preventionTips":["Pin the state-store provider version and commit the lock file.","Keep the state_store block to documented, schema-declared keys.","Re-init after provider upgrades that change the state-store schema."],"tags":["state-store","schema","json","serialization","config"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}