0
0
Terraformcloud~10 mins

Plan and apply separation in pipelines in Terraform - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Plan and apply separation in pipelines
Start Pipeline
Terraform Plan Stage
Review Plan Output
Approve
Terraform Apply
Deploy Infrastructure
End Pipeline
The pipeline first runs a plan to show changes, waits for approval, then applies changes to deploy infrastructure.
Execution Sample
Terraform
terraform plan -out=tfplan
# Review plan output
terraform apply tfplan
This code runs a plan to preview changes and then applies them if approved.
Process Table
StepActionInput/ConditionResultNext Step
1Run terraform planNo prior planPlan file 'tfplan' created showing changesReview plan output
2Review plan outputPlan file existsChanges understood, decision neededApprove or Reject
3Decision: Approve?User inputIf yes, proceed; if no, stopApply or Stop
4Run terraform applyApproved plan fileInfrastructure updated as plannedDeploy infrastructure
5Deploy infrastructureApply successfulInfrastructure live and configuredEnd pipeline
6Stop pipelineRejected planNo changes appliedEnd pipeline
💡 Pipeline ends after apply or stop based on approval decision
Status Tracker
VariableStartAfter PlanAfter ApprovalAfter ApplyFinal
plan_filenonetfplan createdtfplan approved or rejectedtfplan applied or discardednone or applied state
pipeline_statusstartedplanningwaiting approvalapplying or stoppedcompleted or stopped
Key Moments - 3 Insights
Why do we separate 'plan' and 'apply' stages in the pipeline?
Separating plan and apply lets us review changes before making them live, as shown in execution_table rows 2 and 3.
What happens if the plan is rejected during approval?
The pipeline stops without applying changes, as shown in execution_table row 6.
Why do we save the plan output to a file before applying?
Saving the plan ensures the exact reviewed changes are applied later, preventing unexpected updates (execution_table row 1 and 4).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the result of step 1?
AInfrastructure updated as planned
BPlan file 'tfplan' created showing changes
CNo changes applied
DUser input required
💡 Hint
Check the 'Result' column for step 1 in the execution_table
At which step does the pipeline wait for user approval?
AStep 3
BStep 2
CStep 4
DStep 6
💡 Hint
Look at the 'Action' and 'Next Step' columns around step 3 in the execution_table
If the plan is rejected, what is the pipeline status after step 6?
Aapplying
Bcompleted
Cstopped
Dplanning
💡 Hint
Refer to 'pipeline_status' in variable_tracker after step 6
Concept Snapshot
Terraform pipelines separate 'plan' and 'apply' stages.
Plan stage previews changes and saves to a file.
Approval is required before applying.
Apply stage uses the saved plan to update infrastructure.
This prevents unexpected changes and improves safety.
Full Transcript
In Terraform pipelines, we first run 'terraform plan' to see what changes will happen. This plan is saved to a file. Then, the pipeline waits for approval to make sure the changes are correct. If approved, 'terraform apply' uses the saved plan to update the infrastructure exactly as planned. If rejected, the pipeline stops and no changes are made. This separation helps avoid mistakes and keeps infrastructure safe.