0
0
Terraformcloud~10 mins

Terraform CLI overview - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Terraform CLI overview
Start: User writes Terraform config
Run 'terraform init'
Terraform downloads providers
Run 'terraform plan'
Terraform shows planned changes
Run 'terraform apply'
Terraform creates/updates infrastructure
Run 'terraform destroy'
Terraform deletes infrastructure
End
This flow shows how a user writes config, initializes Terraform, plans changes, applies them, and optionally destroys infrastructure.
Execution Sample
Terraform
terraform init
terraform plan
terraform apply
terraform destroy
These commands initialize Terraform, show planned changes, apply them, and destroy resources.
Process Table
StepCommandActionResult
1terraform initInitialize working directory and download providersProviders downloaded, backend configured
2terraform planCreate execution planShows what will be created/changed/destroyed
3terraform applyApply changes to infrastructureResources created/updated as planned
4terraform destroyDestroy all managed infrastructureResources deleted
5-End of workflowNo further actions
💡 Workflow ends after destroy or when no further changes are needed
Status Tracker
VariableStartAfter initAfter planAfter applyAfter destroy
Working DirectoryEmptyInitialized with .terraform folderPlan generatedInfrastructure state updatedInfrastructure state cleared
ProvidersNot downloadedDownloadedUsed for planUsed for applyUsed for destroy
State FileNoneNoneNoneCreated/UpdatedCleared
Key Moments - 3 Insights
Why do we run 'terraform init' before other commands?
'terraform init' sets up the working directory and downloads necessary providers. Without it, 'plan' or 'apply' will fail. See execution_table step 1.
What does 'terraform plan' do if no changes are detected?
'terraform plan' will show that no changes are needed and no resources will be created or modified. This is shown in execution_table step 2.
Does 'terraform apply' always create new resources?
'terraform apply' only creates or updates resources if the plan shows changes. Otherwise, it does nothing. See execution_table step 3.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the result of running 'terraform init'?
AResources created
BExecution plan created
CProviders downloaded, backend configured
DResources destroyed
💡 Hint
Check execution_table row 1 under Result column
At which step does Terraform show what changes it will make?
Aterraform plan
Bterraform init
Cterraform apply
Dterraform destroy
💡 Hint
See execution_table step 2 Action and Result
If you want to remove all infrastructure, which command do you run?
Aterraform plan
Bterraform destroy
Cterraform init
Dterraform apply
💡 Hint
Look at execution_table step 4 Command and Result
Concept Snapshot
Terraform CLI commands:
- terraform init: sets up directory and downloads providers
- terraform plan: shows what changes will happen
- terraform apply: makes changes to infrastructure
- terraform destroy: deletes all managed resources
Always run init first before plan or apply.
Full Transcript
Terraform CLI is a set of commands to manage infrastructure. First, you write your configuration files. Then you run 'terraform init' to prepare your working directory and download necessary providers. Next, 'terraform plan' shows you what changes Terraform will make. If you agree, 'terraform apply' makes those changes to your cloud resources. When you want to remove everything, 'terraform destroy' deletes all managed infrastructure. This workflow helps you safely create, update, and delete cloud resources using simple commands.