Problem
When you run a terraform plan, Terraform returns the following error, indicating a provider version mismatch:
The current state of <resource address> was created by a newer provider version than is currently selected. Upgrade the <provider name> provider to work with this state.
Cause
This error occurs when the Terraform state file was last written by a newer version of a provider that has upgraded a resource's internal schema. The resource schema version is recorded in the state file. Once this migration occurs, older versions of the provider can no longer read the resource's schema, and the migration cannot be reverted without restoring a previous version of the state file.
Solutions
Solution 1: Ensure Provider Version Consistency
To resolve this issue, you must ensure that the provider versions used to execute the plan match the versions that wrote the latest state file.
- Check Provider Version Constraints: Review your configuration to see if the providers have version constraints specified. These constraints define which provider versions are compatible with your configuration.
-
Verify Installed Providers: Check which providers are currently installed for your configuration by running the
terraform versioncommand.$ terraform version
-
Use the Dependency Lock File: If you are using Terraform v0.14 or newer, ensure the dependency lock file (
.terraform.lock.hcl) is committed to your version control system. This file guarantees thatterraform initwill install the same provider versions in any environment, preventing inconsistencies.
Outcome
After aligning the provider versions, the terraform plan command should execute successfully without the provider version error.