{"record":{"id":"fe16500d0409fd09","repo":"hashicorp/terraform","slug":"error-when-obtaining-provider-instance-during-stat","errorCode":null,"errorMessage":"error when obtaining provider instance during state store initialization: %w","messagePattern":"error when obtaining provider instance during state store initialization: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/init.go","lineNumber":207,"sourceCode":"\n\tvar opts *BackendOpts\n\tswitch {\n\tcase root.StateStore != nil:\n\t\t// state_store config present\n\t\tfactory, fDiags := c.Meta.StateStoreProviderFactoryFromConfig(root.StateStore, configLocks)\n\t\tdiags = diags.Append(fDiags)\n\t\tif fDiags.HasErrors() {\n\t\t\treturn nil, true, diags\n\t\t}\n\n\t\t// If overrides supplied by -backend-config CLI flag, process them\n\t\tvar configOverride hcl.Body\n\t\tif !initArgs.BackendConfig.Empty() {\n\t\t\t// We need to launch an instance of the provider to get the config of the state store for processing any overrides.\n\t\t\tprovider, err := factory()\n\t\t\tdefer provider.Close() // Stop the child process once we're done with it here.\n\t\t\tif err != nil {\n\t\t\t\tdiags = diags.Append(fmt.Errorf(\"error when obtaining provider instance during state store initialization: %w\", err))\n\t\t\t\treturn nil, true, diags\n\t\t\t}\n\n\t\t\tresp := provider.GetProviderSchema()\n\n\t\t\tif len(resp.StateStores) == 0 {\n\t\t\t\tdiags = diags.Append(&hcl.Diagnostic{\n\t\t\t\t\tSeverity: hcl.DiagError,\n\t\t\t\t\tSummary:  \"Provider does not support pluggable state storage\",\n\t\t\t\t\tDetail: fmt.Sprintf(\"There are no state stores implemented by provider %s (%q)\",\n\t\t\t\t\t\troot.StateStore.Provider.Name,\n\t\t\t\t\t\troot.StateStore.ProviderAddr),\n\t\t\t\t\tSubject: &root.StateStore.DeclRange,\n\t\t\t\t})\n\t\t\t\treturn nil, true, diags\n\t\t\t}\n\n\t\t\tstateStoreSchema, exists := resp.StateStores[root.StateStore.Type]","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/init.go#L189-L225","documentation":"Emitted by InitCommand.initBackend when a state_store configuration block is present AND -backend-config overrides are supplied, requiring Terraform to launch the state-store provider (factory()) to read its schema — and factory() returns an error. The %w wraps the underlying provider-launch failure so it propagates with full context. This path only exists under the experimental pluggable-state-storage feature.","triggerScenarios":"Using `-enable-pluggable-state-storage-experiment` together with `-backend-config=...` overrides and a state_store block, where the required state-store provider binary cannot be started: missing/incorrect provider version, provider plugin not installed, provider crashes on startup, or the provider factory is misconfigured.","commonSituations":"State-store provider not yet downloaded (forgot `terraform init` for the provider before adding -backend-config overrides); provider version incompatible with the terraform build; provider binary missing execute permissions; dev-override pointing at a stale/broken provider build; provider fails schema RPC due to bad credentials.","solutions":["Run `terraform init` first to install the state-store provider before adding -backend-config overrides.","Inspect the wrapped error (%w) for the provider's startup failure reason and address it (e.g. fix credentials, reinstall provider).","Verify the provider version satisfies required_providers constraints and is compatible with this Terraform version.","If using dev_overrides, confirm the local provider binary builds and runs; remove the override to use the registry version as a test.","Drop the -backend-config override temporarily to isolate whether the failure is the provider itself or the override processing."],"exampleFix":"# before\n$ terraform init -backend-config='token=xxx'   # provider not installed yet\n# after\n$ terraform init                                # install providers first\n$ terraform init -backend-config='token=xxx'    # then apply overrides","handlingStrategy":"try-catch","validationCode":"// Ensure the state-store provider is installed BEFORE adding -backend-config overrides.\nif _, err := os.Stat(filepath.Join(pluginsDir, stateStoreProviderName)); err != nil {\n    log.Fatal(\"install the state-store provider first: terraform init\")\n}","typeGuard":null,"tryCatchPattern":"// Wrap init in a retry that first installs providers without overrides.\nfor attempt := 0; attempt < 2; attempt++ {\n    if attempt == 0 {\n        run(\"terraform\", \"init\") // no -backend-config\n    }\n    if err := run(\"terraform\", \"init\", \"-backend-config=overrides.tfvars\"); err == nil { break }\n}","preventionTips":["Always run a plain `terraform init` to install providers before adding -backend-config overrides for a state store.","Keep required_providers version constraints in sync with the installed provider.","When using dev_overrides, validate the local provider binary starts before relying on it."],"tags":["terraform-init","state-store","provider","experimental"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}