hashicorp/terraform · error

Failed obtain the in-use version of provider %s (%q) used wi

Error message

Failed obtain the in-use version of provider %s (%q) used with state store %q. This is a bug in Terraform and should be reported: %w

What it means

In getStateStorageProviderVersion (meta_backend.go:2478), Terraform reads the locked provider version from the dependency lock file via pLock.Version() and converts it with providerreqs.GoVersionFromVersion. If that conversion fails, the version recorded in .terraform.lock.hcl is unparseable. The message explicitly says this is a Terraform bug and should be reported.

Source

Thrown at internal/command/meta_backend.go:2478

	pLock := locks.Provider(c.ProviderAddr)
	if pLock == nil {
		diags = diags.Append(tfdiags.Sourceless(
			tfdiags.Error,
			"Inconsistent dependency lock file",
			fmt.Sprintf(`The provider dependency used for state storage is missing from the lock file despite being present in the current configuration:
  - provider %s: required by this configuration but no version is selected

To make the initial dependency selections that will initialize the dependency lock file, run:
  terraform init`,
				c.ProviderAddr,
			),
		))
		return nil, diags
	}
	pVersion, err := providerreqs.GoVersionFromVersion(pLock.Version())
	if err != nil {
		diags = diags.Append(fmt.Errorf("Failed obtain the in-use version of provider %s (%q) used with state store %q. This is a bug in Terraform and should be reported: %w",
			c.Provider.Name,
			c.ProviderAddr,
			c.Type,
			err))
		return nil, diags
	}

	return pVersion, diags
}

// Initializing a saved state store from the backend state file (aka 'cache file', aka 'legacy state file')
func (m *Meta) savedStateStore(sMgr *clistate.LocalState) (backend.Backend, tfdiags.Diagnostics) {
	// We're preparing a state_store version of backend.Backend.
	//
	// The provider and state store will be configured using the backend state file.

	var diags tfdiags.Diagnostics

View on GitHub (pinned to c9def3e214)

Solutions

  1. Regenerate the lock file: back up .terraform.lock.hcl, delete it, and run `terraform init` to rewrite valid entries.
  2. If reproducible with a clean lock file, report it as a Terraform bug with the provider address and state-store type from the message.
  3. Verify the provider's version in the lock file is a concrete semver (e.g. 1.2.3), not a constraint (e.g. ~>1.2).
  4. Ensure you are on a current Terraform release to avoid a known version-writing regression.

Example fix

// before: terraform init   (fails: Failed obtain the in-use version of provider ... This is a bug)
// after: cp .terraform.lock.hcl .terraform.lock.hcl.bak && rm .terraform.lock.hcl && terraform init
Defensive patterns

Strategy: validation

Validate before calling

// Validate every provider entry in the lock file is a concrete, parseable version.
func lockFileVersionsParseable(path string) error {
    locks, diags := depsfile.LoadLocksFromFile(path)
    if diags.HasErrors() { return diags.Err() }
    for _, p := range locks.AllProviders() {
        if _, err := providerreqs.GoVersionFromVersion(locks.Provider(p).Version()); err != nil {
            return fmt.Errorf("provider %s has unparseable version: %w", p, err)
        }
    }
    return nil
}

Prevention

When it happens

Trigger: The lock file contains a provider version constraint that does not parse as a concrete version (e.g. malformed, empty, or a constraint where a version is expected); a lock file produced by a buggy/older Terraform that wrote an incompatible version field; manual edits to .terraform.lock.hcl.

Common situations: Hand-editing .terraform.lock.hcl, a lock file shared/rewritten across incompatible Terraform versions, or a core bug writing a bad version field.

Related errors


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