Skip to content

CICD-237 · Apply an approved Terraform plan ​

Encyclopedia · Terraform and infrastructure as code · All snippets

Previous · CICD-236 · Next · CICD-238

1. Where it fits ​

  • Placement In an approved apply job after retrieving the saved plan and checksum.
  • Prerequisites trusted Linux runner, Terraform CLI, reviewed IaC and a disposable state for writes.
  • Platforms local-linux, github-actions, gitea-actions.

2. Copy the snippet ​

bash
sha256sum --check tfplan.sha256
terraform init -input=false -lockfile=readonly
terraform apply -input=false -lock-timeout=2m tfplan

3. How it works ​

The checksum verifies the reviewed plan bytes before apply. Terraform then uses its saved actions against the selected backend and can reject a stale plan.

Apply consumes the exact reviewed plan and independently verifies its bytes.

flowchart TD
  N1["Reviewed plan"]
  N2{"Checksum matches"}
  N1 --> N2
  N3["Trusted checksum"]
  N3 --> N2
  N4["Apply saved plan"]
  N2 -->|Yes| N4
  N5["Fail before state mutation"]
  N2 -->|No| N5

4. Verify the result ​

Use the reviewed plan and the same configuration, state and provider versions. A stale state should cause apply to fail.

Validation syntax-validated (Bash parse). Status definitions.