Question on "Error: Saved plan is stale"

Hi @kansberry,

When Terraform creates state snapshots, it includes in them two tracking fields called “lineage” and “serial”. “lineage” is chosen once for the first state snapshot in a series and then preserved for all subsequent snapshots in that series. “serial” is an integer value that increases each time a new state snapshot is created, so any new snapshot should always have a greater serial than its predecessor.

When Terraform saves a plan to disk for applying later, it includes in that plan file the lineage and serial that were associated with the state snapshot that the plan was based on. When you tell Terraform to apply a saved plan, it will retrieve the latest state snapshot and compare its serial and lineage with those recorded in the plan. Both of these tracking fields must be exactly equal between the saved plan and the latest state snapshot at the time you run apply.

“Saved plan is stale” is the error message for when the serial in the plan does not match the serial in the latest state snapshot.

There is another similar error messa ge"Saved plan does not match the given state" which Terraform will return if the lineage does not match between the plan and the latest state snapshot.