The core workflow
Write Terraform code
↓
terraform init
↓
terraform plan
↓
terraform apply
↓
Infrastructure created
Example project:
provider "aws" {
region = "ap-south-1"
}
resource "aws_instance" "web" {
ami = "ami-0db56f446d44f2f09"
instance_type = "t3.micro"
}terraform init
terraform initInternally Terraform:
- Reads configuration files
- Downloads required providers (for example AWS)
- Creates
.terraform/ - Writes
.terraform.lock.hclto pin provider versions
terraform init
↓
Read .tf files
↓
Download providers
↓
Create .terraform/ + lock file
↓
Ready
terraform plan
terraform planCompares desired configuration to current state and prints what would be added, changed, or destroyed — without making changes.
terraform apply
terraform applyShows the plan, asks for confirmation (yes), then creates or updates resources and refreshes state.
Next apply
If nothing changed in code or cloud drift, plan shows no changes. If you change instance_type, plan shows an update (or replacement, depending on the attribute).
Destroy
terraform destroyRemoves all resources tracked in state for this configuration.
Lifecycle summary
init → prepare working directory
plan → preview changes
apply → create / modify
destroy → tear down
What is -auto-approve?
Normally apply asks:
Do you want to perform these actions?
Only 'yes' will be accepted to approve.
Skip the prompt:
terraform apply -auto-approve
terraform destroy -auto-approveWhy CI uses it
In GitHub Actions, Jenkins, or GitLab CI nobody is present to type yes.
terraform init
terraform plan
terraform apply -auto-approveIs it safe?
| Context | Guidance |
|---|---|
| Local learning labs | Usually fine |
| Production | Risky without a reviewed plan |
Wrong code + -auto-approve = immediate create/change/destroy with no human gate.
In production pipelines, run terraform plan (or plan artifacts) for review, then apply with auto-approve only after approval — never apply blindly to prod.
Interview answer
-auto-approve runs Terraform without the interactive yes confirmation. It is common in CI/CD and dangerous without a prior reviewed plan.