hashicorp/terraform · error

error when obtaining provider instance during state store in

Error message

error when obtaining provider instance during state store initialization: %w

What it means

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.

Source

Thrown at internal/command/meta_backend.go:404

			})
		}

		factory, exists := factories[*settings.Provider.Source]
		if !exists {
			return nil, diags.Append(&hcl.Diagnostic{
				Severity: hcl.DiagError,
				Summary:  "Provider unavailable",
				Detail: 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.",
					settings.Provider.Source.Type,
					settings.Provider.Source,
					settings.Type,
				),
			})
		}

		provider, err := factory()
		if err != nil {
			diags = diags.Append(fmt.Errorf("error when obtaining provider instance during state store initialization: %w", err))
			return nil, diags
		}
		log.Printf("[TRACE] Meta.BackendForLocalPlan: launched instance of provider %s (%q)",
			settings.Provider.Source.Type,
			settings.Provider.Source,
		)

		// We purposefully don't have a deferred call to the provider's Close method here because the calling code needs a
		// running provider instance inside the returned backend.Backend instance.
		// Stopping the provider process is the responsibility of the calling code.

		resp := provider.GetProviderSchema()

		if len(resp.StateStores) == 0 {
			diags = diags.Append(&hcl.Diagnostic{
				Severity: hcl.DiagError,
				Summary:  "Provider does not support pluggable state storage",
				Detail: fmt.Sprintf("There are no state stores implemented by provider %s (%q)",

View on GitHub (pinned to c9def3e214)

Solutions

  1. Run `terraform init` to re-fetch and validate provider plugins before applying the saved plan.
  2. Verify the provider version in .terraform.lock.hcl matches an installed, launchable binary in the plugin cache.
  3. Re-create the plan with the current toolchain if the providers have changed: `terraform plan -out=plan.tfplan` then apply.
  4. Check TF_LOG=DEBUG output for the provider subprocess error (missing .so, crash, handshake failure).

Example fix

# before: stale plan, provider gone from cache
terraform apply plan.tfplan
# after: re-init then re-plan
terraform init
terraform plan -out=plan.tfplan
terraform apply plan.tfplan
Defensive patterns

Strategy: validation

Validate before calling

// Ensure providers are installed before applying a saved plan
if _, err := os.Stat(".terraform/providers"); err != nil {
    log.Fatal("run terraform init before applying a saved plan")
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07). Data as JSON: /api/errors/499af90afb78ab46. Report an issue: GitHub.