{"record":{"id":"5ffde5fe357203a2","repo":"hashicorp/terraform","slug":"failed-to-set-state-store-provider-configuration","errorCode":null,"errorMessage":"Failed to set state store provider configuration: %w","messagePattern":"Failed to set state store provider configuration: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/meta_backend.go","lineNumber":2278,"sourceCode":"\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}\n\n\t\t\t\tif ws == backend.DefaultStateName {\n\t\t\t\t\t// If the default workspace is selected, no workspaces existing _may_ be expected.\n\t\t\t\t\t// It's valid for the default workspace's state to not be created until the first apply takes place.\n\t\t\t\t\t// However, it could be that the user is configuring their working directory for the first time but\n\t\t\t\t\t// they expect pre-existing state to be in the store from previous actions. In that case, the user","sourceCodeStart":2260,"sourceCodeEnd":2296,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/meta_backend.go#L2260-L2296","documentation":"Immediately after the state_store config is persisted, the provider portion of the config is set via s.StateStore.Provider.SetConfig(providerConfigVal, b.ProviderSchema()). If that encode fails, this error wraps the cause. It reflects a provider-schema vs provider-config mismatch, distinct from the state-store schema error at 671.","triggerScenarios":"Provider.SetConfig fails encoding providerConfigVal against b.ProviderSchema(). Triggers: provider schema nil/malformed, provider config block has unknown attributes/types, or provider plugin version whose provider schema differs from what Terraform built the config value against.","commonSituations":"Provider pinned to a version with a different provider-schema than expected; extra keys in the state_store provider {} sub-block; provider plugin built against a different Terraform plugin SDK.","solutions":["Inspect inner %w for the failing provider attribute/type.","Align the provider version (lock file vs cache vs config) with `tofu init -upgrade` or by correcting the version constraint.","Strip undocumented keys from the provider {} sub-block of the state_store.","Recompile/replace a dev provider so its schema matches the declared config."],"exampleFix":"// before\nstate_store \"acme\" {\n  provider = \"example.com/acme/storage\"\n  provider_config {\n    token = \"...\"   # not in provider schema\n  }\n}\n\n// after\nstate_store \"acme\" {\n  provider = \"example.com/acme/storage\"\n  provider_config {\n    # schema-declared provider attributes only\n  }\n}","handlingStrategy":"validation","validationCode":"// Validate the provider_config sub-block against the provider schema.\nfunc validateProviderConfig(providerCfg cty.Value, schema *configschema.Block) error {\n    if schema == nil { return fmt.Errorf(\"provider schema is nil\") }\n    if err := schema.ImpliedType().Value(providerCfg); err != nil {\n        return fmt.Errorf(\"provider config does not match schema: %w\", err)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := s.StateStore.Provider.SetConfig(providerConfigVal, b.ProviderSchema()); err != nil {\n    if isJSONEncodingErr(err) {\n        diags = diags.Append(fmt.Errorf(\"state-store provider 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 provider configuration: %w\", err))\n    }\n    return nil, diags\n}","preventionTips":["Keep provider_config keys to those declared by the provider schema.","Align provider version in lock file with the installed plugin.","For dev providers, rebuild against the current plugin SDK version."],"tags":["state-store","provider","schema","json","serialization"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}