Skip to content
Latchkey

Terraform Cloud "Cannot apply ... plan ... discarded" in CI

The apply step tried to confirm a run whose plan is no longer applicable. HCP Terraform discards a plan when a newer run supersedes it, when it is discarded manually, or when it ages out, so the stale run cannot be applied.

What this error means

A pipeline that plans, then confirms in a later step, fails with "Error: Cannot apply a run that has been discarded" or that the run was superseded.

terraform
Error: Cannot apply run run-ABC123

The run was discarded because a newer run for the workspace superseded it.

Common causes

A newer run superseded the plan

A second push or a concurrent pipeline queued a new run, and HCP Terraform discarded the older pending plan.

The plan aged out or was discarded

A plan left pending too long, or discarded in the UI, cannot then be applied.

How to fix it

Re-plan and apply in one flow

  1. Avoid a long gap between plan and apply so the plan cannot be superseded.
  2. Serialize pipeline runs per workspace to prevent overlap.
  3. Re-run the plan, then apply the fresh run.
Terminal
terraform plan -out=tfplan
terraform apply tfplan

Prevent concurrent runs

Use concurrency controls so only one run per workspace is in flight, so a later run cannot discard the one you are applying.

.github/workflows/ci.yml
concurrency:
  group: tf-${{ github.workflow }}-prod
  cancel-in-progress: false

How to prevent it

  • Keep plan and apply close together in the pipeline.
  • Serialize runs per workspace with a concurrency group.
  • Do not manually discard runs a pipeline is about to apply.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →