← Debugging Guides

阅读中文版本

Terraform — provider version conflict or failed to query provider

Fix provider version conflicts by constraining versions and refreshing the dependency lock file.

intermediatedebuggingterraformproviders

Symptoms

  • Failed to query available provider packages
  • Version constraints do not allow a single provider version
  • terraform init fails after adding a module
  • A provider version is no longer available in the registry

Possible causes

  • Two modules require incompatible provider versions
  • A pinned provider version was removed or renamed
  • The lock file is stale relative to the configuration
  • The registry or network is unreachable

Diagnosis steps

Read the conflicting constraints

terraform init 2>&1 | head -30

Interpretation

Terraform lists the constraints from each source, showing which ranges do not overlap.

Update the lock file

terraform init -upgrade

Interpretation

Upgrading resolves newer compatible versions and refreshes the lock when constraints allow.

Pin and align versions

required_providers { aws = { source = "hashicorp/aws"; version = "~> 5.0" } }

Interpretation

Aligning version ranges across modules lets Terraform select one provider version.

Root cause

No single provider version satisfied the combined version constraints or the lock file, so Terraform could not select and install a provider.

Fix

Relax or align version constraints so a common version exists, upgrade the lock file to a compatible release, and ensure the registry or mirror hosts the required versions.

Verify the fix

Run init again and confirm it succeeds and installs the provider, then run validate to confirm the configuration is consistent.

Symptom walkthrough

terraform init fails with a provider version conflict or a message that it could not query provider packages. Two modules may require incompatible ranges, a pinned version may have been removed, or the lock file may be stale relative to the configuration. Because Terraform must pick one version per provider, any contradictory constraint stops initialization.

Fix in practice

Read the constraints Terraform prints, align them so a common version exists, and run init -upgrade to resolve and refresh the lock file. If the registry or a mirror is unreachable, fix connectivity or point at a reachable source.

Verification

Run init again and confirm it succeeds and installs providers, then run terraform validate to confirm the configuration is internally consistent. Successful init with valid configuration confirms the versions now agree. Committing the lock file keeps every environment on that same set of provider versions.

Diagnostic commands

Check the behavior with commands like these:

terraform init 2>&1 | head -30
terraform init -upgrade
required_providers { aws = { source = "hashicorp/aws"; version = "~> 5.0" } }