Skip to content

Terraform Tutorials

This page collects workflow notes and practical examples for Terraform.

Typical Project Layout

terraform/
  main.tf
  variables.tf
  outputs.tf
  versions.tf
  terraform.tfvars

Basic Workflow

terraform init
terraform fmt
terraform validate
terraform plan
terraform apply

Simple Example

resource "aws_security_group" "web" {
  name        = "web"
  description = "Web access"

  ingress {
    from_port   = 80
    to_port     = 80
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }
}

Useful Patterns

  • Use terraform fmt before review.
  • Keep environment-specific values in *.tfvars.
  • Split shared logic into modules when repetition appears.
  • Use terraform destroy only when you intentionally want to remove the managed resources.

Practical Notes

  • Prefer predictable resource names.
  • Keep your backend configuration and state access documented.
  • Review plans before applying in shared environments.