TERRAFORM_STALE_PLAN cicd config_error ai_generated true

Error: Saved plan is stale. The configuration has changed since the plan was saved.

ID: cicd/terraform-plan-stale

Also available as: JSON · Markdown · 中文
92%Fix Rate
85%Confidence
1Evidence
2023-08-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Terraform 1.5.0 active
OpenTofu 1.6.0 active

Root Cause

Terraform plan was generated from an older version of the configuration files, but the configuration was modified before the plan could be applied, causing a checksum mismatch.

generic

中文

Terraform计划是从旧版本的配置文件生成的,但在应用计划之前配置已被修改,导致校验和不匹配。

Official Documentation

https://developer.hashicorp.com/terraform/cli/commands/plan#planning-and-applying-in-automation

Workarounds

  1. 95% success Re-run `terraform plan -out=tfplan` to generate a fresh plan, then apply with `terraform apply tfplan`
    Re-run `terraform plan -out=tfplan` to generate a fresh plan, then apply with `terraform apply tfplan`
  2. 90% success In CI/CD pipelines, run plan and apply in the same job without intermediate steps that modify config files (e.g., use a single workflow step: `terraform plan -out=tfplan && terraform apply tfplan`)
    In CI/CD pipelines, run plan and apply in the same job without intermediate steps that modify config files (e.g., use a single workflow step: `terraform plan -out=tfplan && terraform apply tfplan`)

中文步骤

  1. Re-run `terraform plan -out=tfplan` to generate a fresh plan, then apply with `terraform apply tfplan`
  2. In CI/CD pipelines, run plan and apply in the same job without intermediate steps that modify config files (e.g., use a single workflow step: `terraform plan -out=tfplan && terraform apply tfplan`)

Dead Ends

Common approaches that don't work:

  1. 100% fail

    Terraform will reject the apply because the plan file's checksum doesn't match the current config; it will fail with the same error

  2. 95% fail

    Plan files are binary and checksummed; manual editing corrupts the file and terraform will refuse to apply it