How to fix Error: The given plan file was created with a different set of external dependency selections in Terraform

TerraformINTERMEDIATEHIGHUpdated Dec 30, 2025· 145 views

This error occurs when applying a saved Terraform plan file that was created with different provider versions or configurations than your current setup. A plan file is environment-specific and cannot be reused after dependency changes. Resolve it by regenerating the plan and lock file in your current environment.

Quick fix

Fixes Error: The given plan file was created with a different set of external dependency selections

ls -la .terraform.lock.hcl
cat .terraform.lock.hcl | head -20
  1. Verify you have the correct lock file in your working directory
  2. Run terraform init to synchronize dependencies
  3. Regenerate the plan in the same environment
  4. Lock provider versions for all platforms (if needed)
terraform — error
ls -la .terraform.lock.hcl
cat .terraform.lock.hcl | head -20
Error: The given plan file was created with a different set of external dependency selections

What this error means

The "plan file was created with a different set of external dependency selections" error means Terraform detected a mismatch between the provider versions/dependencies recorded in your saved plan file and those currently configured in your Terraform working directory. In Terraform, when you run "terraform plan", it captures not just the resource changes but also the exact provider versions and dependency lock file state at that moment. A saved plan file is tightly coupled to the Terraform configuration and lock file (.terraform.lock.hcl) that created it. If either your configuration or lock file changes after the plan was created, Terraform will refuse to apply that plan because the dependencies no longer match. This is a safety mechanism to prevent applying infrastructure changes with mismatched provider versions, which could lead to unexpected behavior or compatibility issues.

Typical symptoms

  • terraform apply fails with "plan file was created with a different set of external dependency selections"
  • Plan file works locally but fails in CI/CD pipeline
  • Error occurs when applying a saved plan in a different environment
  • Cross-platform deployments fail (e.g., plan on macOS, apply on Linux)
  • Lock file was regenerated since the plan was created

Common causes

  1. The .terraform.lock.hcl file was updated or regenerated after the plan was created
  2. Running plan and apply in different environments with different architectures (e.g., macOS vs Linux)
  3. Provider version constraints changed in your Terraform configuration
  4. Running terraform init between plan and apply, which regenerates the lock file
  5. CI/CD pipeline cached the wrong lock file or .terraform directory
  6. Using different Terraform versions between plan and apply steps

How to fix "Error: The given plan file was created with a different set of external dependency selections"

1Verify you have the correct lock file in your working directory

Ensure the .terraform.lock.hcl file matches what was used when the plan was created. If you're in a CI/CD environment, check that your artifact or cache includes the correct lock file:

bash
ls -la .terraform.lock.hcl
cat .terraform.lock.hcl | head -20

If the lock file is missing or outdated, this is likely the cause.

2Run terraform init to synchronize dependencies

Initialize your Terraform working directory with the current configuration and lock file:

bash
terraform init

This command downloads and installs the provider versions specified in your lock file and ensures all dependencies are synchronized. If the lock file has changed, it will update it to match your configuration.

3Regenerate the plan in the same environment

After running terraform init, create a new plan file in the current environment:

bash
terraform plan -out=plan.tfplan

This new plan will be created with the current dependency selections and can be safely applied in this environment. Discard the old plan file that had mismatched dependencies.

4Lock provider versions for all platforms (if needed)

If you're working in a multi-platform environment (local development on macOS but CI/CD on Linux), explicitly lock providers for all target platforms:

bash
terraform providers lock -platform=linux_amd64 -platform=darwin_amd64 -platform=darwin_arm64

This generates checksums for each platform and adds them to the lock file, ensuring consistency across environments.

5Apply the newly generated plan

Once you've regenerated the plan in the same environment, apply it:

bash
terraform apply plan.tfplan

This applies the infrastructure changes with dependencies that match your current configuration.

Advanced notes

CI/CD Best Practices: When using plan in CI and apply in CD, save the entire terraform context into your build artifact:
- The plan file (plan.tfplan)
- The lock file (.terraform.lock.hcl)
- The .terraform directory (or let CD re-initialize)

Then retrieve all of these in the CD stage before running terraform apply. This ensures dependency selections remain consistent.

Cross-Architecture Deployments: Terraform generates platform-specific checksums in the lock file. If you plan on macOS but apply on Linux, lock files won't match unless you explicitly generate checksums for both platforms using "terraform providers lock".

Architecture-Specific Checksums: The lock file includes checksums like "h1:..." which are specific to each platform (linux_amd64, darwin_amd64, etc.). Different platforms require different checksums, which is why cross-architecture deployments fail without explicit platform locking.

Workaround for CI/CD Caching Issues: If your CI/CD system caches .terraform directories, ensure the cache is invalidated when the lock file changes, or skip caching the .terraform directory and always run "terraform init" fresh.

Frequently asked questions

What does "Error: The given plan file was created with a different set of externa" mean?
The "plan file was created with a different set of external dependency selections" error means Terraform detected a mismatch between the provider versions/dependencies recorded in your saved plan file and those currently configured in your Terraform working directory. In Terraform, when you run "terraform plan", it captures not just the resource changes but also the exact provider versions and dependency lock file state at that moment. hcl) that created it.
How do I fix "Error: The given plan file was created with a different set of externa"?
This error occurs when applying a saved Terraform plan file that was created with different provider versions or configurations than your current setup. A plan file is environment-specific and cannot be reused after dependency changes. Resolve it by regenerating the plan and lock file in your current environment.
What causes "Error: The given plan file was created with a different set of externa"?
The .terraform.lock.hcl file was updated or regenerated after the plan was created Running plan and apply in different environments with different architectures (e.g., macOS vs Linux) Provider version constraints changed in your Terraform configuration
Is the "Error: The given plan file was created with a different set of externa" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading