{"record":{"id":"499af90afb78ab46","repo":"hashicorp/terraform","slug":"error-when-obtaining-provider-instance-during-stat-499af9","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":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/meta_backend.go","lineNumber":404,"sourceCode":"\t\t\t})\n\t\t}\n\n\t\tfactory, exists := factories[*settings.Provider.Source]\n\t\tif !exists {\n\t\t\treturn nil, diags.Append(&hcl.Diagnostic{\n\t\t\t\tSeverity: hcl.DiagError,\n\t\t\t\tSummary:  \"Provider unavailable\",\n\t\t\t\tDetail: fmt.Sprintf(\"The provider %s (%q) is required to initialize the %q state store, but the matching provider factory is missing. This is a bug in Terraform and should be reported.\",\n\t\t\t\t\tsettings.Provider.Source.Type,\n\t\t\t\t\tsettings.Provider.Source,\n\t\t\t\t\tsettings.Type,\n\t\t\t\t),\n\t\t\t})\n\t\t}\n\n\t\tprovider, err := factory()\n\t\tif err != nil {\n\t\t\tdiags = diags.Append(fmt.Errorf(\"error when obtaining provider instance during state store initialization: %w\", err))\n\t\t\treturn nil, diags\n\t\t}\n\t\tlog.Printf(\"[TRACE] Meta.BackendForLocalPlan: launched instance of provider %s (%q)\",\n\t\t\tsettings.Provider.Source.Type,\n\t\t\tsettings.Provider.Source,\n\t\t)\n\n\t\t// We purposefully don't have a deferred call to the provider's Close method here because the calling code needs a\n\t\t// running provider instance inside the returned backend.Backend instance.\n\t\t// Stopping the provider process is the responsibility of the calling code.\n\n\t\tresp := provider.GetProviderSchema()\n\n\t\tif len(resp.StateStores) == 0 {\n\t\t\tdiags = diags.Append(&hcl.Diagnostic{\n\t\t\t\tSeverity: hcl.DiagError,\n\t\t\t\tSummary:  \"Provider does not support pluggable state storage\",\n\t\t\t\tDetail: fmt.Sprintf(\"There are no state stores implemented by provider %s (%q)\",","sourceCodeStart":386,"sourceCodeEnd":422,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/meta_backend.go#L386-L422","documentation":"Appended as a diagnostic from `Meta.BackendForLocalPlan` when a state store's configured provider factory returns an error from `factory()` — i.e. instantiating the gRPC provider plugin process fails. This occurs during application of a saved plan whose `state_store` block references a provider (e.g. a custom state backend). The factory was found and the schema check passed, but launching the provider binary failed.","triggerScenarios":"`factory()` (a `providers.Factory` func) returns an error because the provider plugin binary cannot start — missing executable, wrong version, gRPC handshake failure, plugin process crashed on startup, or a lock-file/timeout issue. This is in the `state_store` initialization path of `BackendForLocalPlan`.","commonSituations":"Provider plugin not installed (`terraform init` not run or `-lockfile=readonly` skipped a needed provider); provider binary corrupted or incompatible with the Terraform CLI version; provider requires a newer gRPC protocol version; OS/architecture mismatch of the downloaded provider; plugin cache or filesystem permission issue.","solutions":["Run `terraform init` to (re)install the required provider plugin named in the wrapped error.","Run `terraform providers` / inspect the plan to see which provider the state store requires.","Delete `.terraform/providers/` and re-init if the binary may be corrupt.","Confirm Terraform CLI and provider versions are compatible (check the provider's releases/CHANGELOG).","Read the wrapped `%w` for the exact launch failure (path not found, handshake error, etc.)."],"exampleFix":"# before: provider not installed\nterraform apply tfplan\n# after\nterraform init\nterraform apply tfplan\n# if corrupt:\nrm -rf .terraform/providers && terraform init","handlingStrategy":"validation","validationCode":"// Ensure required providers are installed before applying a plan.\n// `terraform providers` shows what the state store needs.\n// Then `terraform init` installs them.","typeGuard":"// Confirm the factory exists before calling it (the schema check above already guards this).\nif factory == nil {\n    return errors.New(\"provider factory missing for state store provider\")\n}","tryCatchPattern":"// Provider launch failures are often resolved by re-init; not safe to retry blindly.\nprovider, err := factory()\nif err != nil {\n    // run `terraform init`, then re-attempt BackendForLocalPlan\n}","preventionTips":["Run `terraform init` in the same environment before applying a saved plan.","Keep provider versions consistent between plan and apply (use version constraints).","Clear `.terraform/providers/` if a binary is suspected corrupt."],"tags":["terraform","provider","state-store","plugin","plan","grpc"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}