{"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":"console","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/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/meta_backend.go#L2254-L2290","documentation":"In Meta.stateStore_C_s (meta_backend.go:2272), Terraform calls StateStoreConfigState.SetConfig(storeConfigVal, b.ConfigSchema()) to serialize the decoded state_store configuration value into JSON against the backend/state-store schema. Failure means the state-store config value cannot be represented as JSON, almost always a state-store provider schema defect.","triggerScenarios":"A state_store provider whose schema does not match the values it accepts, so the cty.Value fails JSON round-tripping; using an incompatible provider version with this Terraform build.","commonSituations":"State-store provider plugin with a schema regression; exotic/sensitive attribute types the JSON marshaler cannot encode.","solutions":["Read the wrapped `%w` to confirm it is a JSON/cty type failure, indicating a provider schema defect.","Pin the state-store provider to a known-good version in the lock file and re-run `terraform init`.","Reduce the state_store block to the minimum to isolate the failing attribute and report it to the provider maintainer.","If recently upgraded Terraform core, try the previous Terraform version to rule out a core regression."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Validate the state_store config serializes against the backend schema before init writes it.\nfunc stateStoreConfigSerializes(b backend.Backend, storeVal cty.Value) error {\n    st := &workdir.StateStoreConfigState{Type: \"x\"}\n    return st.SetConfig(storeVal, b.ConfigSchema())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pin a state-store provider version with a known-good schema in the lock file.","Keep state_store blocks minimal and avoid attribute types the schema may not serialize.","Test first-time state_store init in a scratch environment.","Report provider schema defects upstream."],"tags":["state-store","schema","json","serialization","init"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}