The Terraform mistake that breaks every deploy
This video teaches you how to use Terraform to create repeatable, consistent cloud infrastructure and avoid configuration errors.
What this guide covers
After finishing this guide, you’ll be able to define, manage, and deploy AWS cloud infrastructure reliably using Terraform code instead of manual console changes. This ensures consistent environments and reduces the risk of unexpected outages.
When to use it
- You must deploy the same EC2 instance configuration repeatedly across dev, staging, and prod.
- Troubleshooting inconsistent environment setups caused by manual console changes.
- Automating infrastructure provisioning to speed up deployment cycles.
- Ensuring infrastructure changes are version controlled and auditable.
The move, step by step
-
Install Terraform and configure AWS CLI credentials
Download Terraform from terraform.io and configure your AWS CLI withaws configureso Terraform can authenticate to AWS (source: Terraform AWS provider docs). -
Create a Terraform configuration file
In a new folder, write amain.tffile describing your AWS resources. Use this example block for a reusable EC2 instance:resource "aws_instance" "example" { ami = "ami-0c55b159cbfafe1f0" instance_type = "t2.micro" tags = { Name = "example-instance" } } -
Initialize the working directory
Runterraform initto download required provider plugins and prepare the directory. -
Preview your planned changes
Useterraform planto see what infrastructure Terraform will create or modify without affecting live resources. -
Apply the infrastructure changes
Useterraform applyand confirm to provision resources described in the config files. This creates or updates the AWS EC2 instance as defined. -
Keep your Terraform files in version control
Commit all.tffiles and lock files to git. This keeps a history of infrastructure changes and lets you roll back if needed. -
Avoid manual AWS Console changes
Never modify resources directly in the AWS Console. Always update*.tffiles and reapply Terraform to keep state consistent.
Example
Input: main.tf
resource "aws_instance" "example" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
tags = {
Name = "example-instance"
}
}
Commands:
terraform init
terraform plan
terraform apply
Expected output snippet after apply:
aws_instance.example: Creating...
aws_instance.example: Creation complete after 30s [id=i-0123456789abcdef0]
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
Common mistakes
- Mistake: Changing infrastructure manually in AWS Console → Fix: Always use Terraform code to manage resources.
- Mistake: Not initializing Terraform directory before commands → Fix: Run
terraform initfirst in each new project folder. - Mistake: Committing temporary or local state files to git → Fix: Only commit
.tffiles; add.terraform/andterraform.tfstateto.gitignore. - Mistake: Using hard-coded AMI IDs without considering regions or updates → Fix: Use data sources or variables to manage AMI dynamically (see Terraform AWS docs).
- Mistake: Ignoring
terraform planoutput → Fix: Review the plan to understand exactly what Terraform will change before applying.
Next step
In the next 10 minutes, create a new folder with a simple main.tf declaring one EC2 instance as shown above. Initialize Terraform, run plan to check for errors, then apply to deploy it. Then come back and try the next move from the video.
Pick the smallest version of this guide and try it in your tool of choice in the next 20 minutes.
Get the next AI/career guide in your inbox
One short, practical guide on AI tools, cloud, and the modern career stack. No fluff.