{"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":"console","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/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/meta_backend.go#L386-L422","documentation":"Appended as a diagnostic in BackendForLocalPlan() when the provider factory for the state_store configuration returns an error instantiating the provider. This path is taken when the plan's state_store configuration requires a provider to back the state storage, and factory() (provider creation) fails. The %w wraps the provider instantiation error.","triggerScenarios":"BackendForLocalPlan resolves the plan's state_store settings, locates the provider factory from the lock file, calls factory(), and it returns a non-nil error — e.g. the provider binary won't start, crashes on init, fails schema handshake, or its executable is missing from the cache.","commonSituations":"Applying a saved plan after the provider plugin cache was cleared or the provider version downgraded; a corrupted .terraform.lock.hcl pointing to a provider that cannot launch; a provider binary with missing shared-library dependencies on the host; plugin protocol version mismatch after a Terraform upgrade.","solutions":["Run `terraform init` to re-fetch and validate provider plugins before applying the saved plan.","Verify the provider version in .terraform.lock.hcl matches an installed, launchable binary in the plugin cache.","Re-create the plan with the current toolchain if the providers have changed: `terraform plan -out=plan.tfplan` then apply.","Check TF_LOG=DEBUG output for the provider subprocess error (missing .so, crash, handshake failure)."],"exampleFix":"# before: stale plan, provider gone from cache\nterraform apply plan.tfplan\n# after: re-init then re-plan\nterraform init\nterraform plan -out=plan.tfplan\nterraform apply plan.tfplan","handlingStrategy":"validation","validationCode":"// Ensure providers are installed before applying a saved plan\nif _, err := os.Stat(\".terraform/providers\"); err != nil {\n    log.Fatal(\"run terraform init before applying a saved plan\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run `terraform init` to populate the provider cache before applying a plan.","Re-plan with the current toolchain if providers changed since the plan was made.","Keep .terraform.lock.hcl committed and in sync with installed providers."],"tags":["provider","state-store","plan","plugin","init"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}