Bird
Raised Fist0
Terraformcloud~10 mins

Why the workflow matters in Terraform - Visual Breakdown

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Process Flow - Why the workflow matters
Write Terraform Code
↓
terraform init
↓
terraform plan
↓
terraform apply
↓
Infrastructure Created
↓
terraform destroy (optional)
This flow shows the key steps in Terraform workflow: writing code, initializing, planning, applying, and optionally destroying infrastructure.
Execution Sample
Terraform
terraform init
terraform plan
terraform apply
This sequence initializes Terraform, shows the planned changes, and applies them to create infrastructure.
Process Table
StepCommandActionResultNext Step
1terraform initSetup backend and providersTerraform ready to run plansterraform plan
2terraform planCheck what changes will happenShows planned infrastructure changesterraform apply
3terraform applyCreate or update infrastructureInfrastructure created or updatedEnd or terraform destroy
4terraform destroyRemove infrastructureInfrastructure removedEnd
💡 Workflow ends after infrastructure is created or destroyed.
Status Tracker
VariableStartAfter initAfter planAfter applyAfter destroy
Terraform Stateemptyinitializedplannedapplieddestroyed
Infrastructurenonenonenoneexistsnone
Key Moments - 3 Insights
Why do we run 'terraform plan' before 'terraform apply'?
Running 'terraform plan' shows what changes Terraform will make without applying them. This helps avoid surprises and errors, as seen in step 2 of the execution_table.
What happens if we skip 'terraform init'?
'terraform init' sets up necessary plugins and backend. Skipping it means Terraform cannot run plans or apply changes properly, as shown in step 1.
Why might we use 'terraform destroy'?
'terraform destroy' removes all created infrastructure safely. It is useful for cleaning up resources and avoiding costs, as shown in step 4.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the result after running 'terraform plan'?
AShows planned infrastructure changes
BInfrastructure created or updated
CTerraform ready to run plans
DInfrastructure removed
💡 Hint
Check the 'Result' column for step 2 in the execution_table.
At which step does the infrastructure actually get created?
Aterraform init
Bterraform plan
Cterraform apply
Dterraform destroy
💡 Hint
Look at the 'Action' and 'Result' columns in the execution_table for step 3.
If you skip 'terraform init', what will happen to the Terraform state variable after the first command?
AIt becomes 'initialized'
BIt stays 'empty'
CIt becomes 'planned'
DIt becomes 'applied'
💡 Hint
Refer to the variable_tracker row for 'Terraform State' after 'init'.
Concept Snapshot
Terraform workflow steps:
1. terraform init - prepares Terraform
2. terraform plan - previews changes
3. terraform apply - makes changes
4. terraform destroy - removes resources
Following this order avoids errors and surprises.
Full Transcript
The Terraform workflow is important because it guides you through safe and predictable infrastructure changes. First, you write your Terraform code. Then you run 'terraform init' to set up necessary tools. Next, 'terraform plan' shows what changes will happen without applying them. After reviewing, 'terraform apply' creates or updates your infrastructure. Optionally, 'terraform destroy' removes all created resources. Skipping steps can cause errors or unexpected results. This workflow helps you manage cloud resources confidently and avoid mistakes.

Practice

(1/5)
1. Why is it important to run terraform plan before terraform apply?
easy
A. It shows the changes Terraform will make before applying them
B. It automatically applies changes without confirmation
C. It deletes all existing resources immediately
D. It skips validation of the configuration files

Solution

  1. Step 1: Understand the purpose of terraform plan

    This command previews the changes Terraform will make to your infrastructure without applying them.
  2. Step 2: Compare with terraform apply

    terraform apply actually makes the changes, so planning first helps avoid mistakes.
  3. Final Answer:

    It shows the changes Terraform will make before applying them -> Option A
  4. Quick Check:

    Plan previews changes = D [OK]
Hint: Plan first to preview changes, avoid surprises [OK]
Common Mistakes:
  • Skipping plan and applying directly
  • Thinking plan applies changes
  • Confusing plan with destroy
2. Which command correctly initializes a Terraform working directory before planning or applying?
easy
A. terraform init
B. terraform start
C. terraform deploy
D. terraform configure

Solution

  1. Step 1: Identify the initialization command

    terraform init sets up the working directory by downloading providers and preparing backend.
  2. Step 2: Check other options

    Commands like terraform start, deploy, or configure do not exist in Terraform.
  3. Final Answer:

    terraform init -> Option A
  4. Quick Check:

    Initialize with init = B [OK]
Hint: Init first to prepare your workspace [OK]
Common Mistakes:
  • Using non-existent commands
  • Trying to apply before init
  • Confusing init with plan
3. Given this Terraform workflow:
terraform init
tf plan
tf apply

What will happen if you run terraform apply without running terraform plan first?
medium
A. Terraform will apply changes immediately without preview
B. Terraform will show an error and stop
C. Terraform will automatically run plan before apply
D. Terraform will delete all resources

Solution

  1. Step 1: Understand terraform apply behavior

    Terraform always performs an internal plan, shows the execution plan (preview of changes), and prompts for confirmation before applying.
  2. Step 2: Check if plan is mandatory

    Running terraform plan first is recommended for detailed review and saving plans, but terraform apply automatically runs the plan step.
  3. Final Answer:

    Terraform will automatically run plan before apply -> Option C
  4. Quick Check:

    Apply auto-runs plan [OK]
Hint: Apply always plans first internally [OK]
Common Mistakes:
  • Assuming apply always errors without plan
  • Thinking apply auto-runs plan silently
  • Believing apply deletes resources by default
4. You ran terraform apply but noticed unexpected resource deletions. What is the most likely cause related to workflow?
medium
A. Running terraform init twice
B. Skipping terraform plan and not reviewing changes
C. Using an outdated Terraform version
D. Not setting environment variables

Solution

  1. Step 1: Identify workflow mistake

    Skipping terraform plan means you miss previewing changes, leading to surprises like deletions.
  2. Step 2: Evaluate other options

    Running init twice, outdated version, or missing env vars usually cause errors, not unexpected deletions.
  3. Final Answer:

    Skipping terraform plan and not reviewing changes -> Option B
  4. Quick Check:

    Skip plan = risk of unwanted deletions [OK]
Hint: Always plan and review before applying [OK]
Common Mistakes:
  • Ignoring plan output
  • Blaming init for deletions
  • Assuming version causes deletions
5. You want to safely update your cloud infrastructure with Terraform. Which workflow sequence best prevents downtime and mistakes?
hard
A. terraform plan -> terraform apply -> terraform init
B. terraform apply -> terraform plan -> terraform init
C. terraform apply -> terraform init -> terraform plan
D. terraform init -> terraform plan -> review plan -> terraform apply

Solution

  1. Step 1: Understand the correct workflow order

    First, terraform init prepares the workspace, then terraform plan previews changes, followed by reviewing the plan carefully.
  2. Step 2: Apply changes only after review

    Applying changes after review ensures safety and avoids downtime or mistakes.
  3. Final Answer:

    terraform init -> terraform plan -> review plan -> terraform apply -> Option D
  4. Quick Check:

    Init, plan, review, apply = C [OK]
Hint: Init, plan, review, then apply for safe updates [OK]
Common Mistakes:
  • Applying before planning
  • Skipping plan review
  • Running commands in wrong order