Terraform Init and Plan
The first two commands you'll use in any Terraform project are
terraform init and terraform plan. They set up your working directory and let you preview changes.terraform init
Initializes a Terraform working directory. It:
- Downloads provider plugins specified in the configuration.
- Sets up the backend (local or remote).
- Installs modules (covered later).
.tf files:terraform initYou must run this before any other command. Re‑run it if you change provider versions or backends.terraform plan
Creates an execution plan, showing what Terraform will do without actually making changes. It compares the current state (from
terraform.tfstate) with your configuration.terraform planOutput shows:+create new resource-destroy existing resource~update in‑place-/+replace (destroy then create)
Example Workflow
Create a file
main.tf with content:terraform {
required_providers {
random = {
source = "hashicorp/random"
}
}
}
resource "random_string" "pet" {
length = 6
special = false
}Now run:terraform init
terraform planYou'll see a plan showing one resource to add.Saving Plans
You can save the plan to a file:
terraform plan -out=myplan.tfplanThen apply exactly that plan: terraform apply myplan.tfplan.Destroy Plan
To see a plan that destroys all resources:
terraform plan -destroyTwo Minute Drill
terraform initdownloads providers and sets up backend.terraform planpreviews changes without applying.- Plan symbols:
+create,-destroy,~update,-/+replace. - Save plan to file for later apply.
- Always run
initbeforeplan.
Need more clarification?
Drop us an email at career@quipoinfotech.com
