Title: Lab 13 — Provision Free-Tier AWS Infrastructure with Terraform (Local and Real)
Course: AIINFRA 101: Applied Infrastructure & Containerization > Section: Week 13 — Infrastructure as Code with Terraform

🛠️ Lab 13 — Provision Free-Tier AWS Infrastructure with Terraform (50 pts)

Goal: Write a real Terraform configuration, run it entirely locally with zero cloud spend using LocalStack, then run the identical configuration against real AWS free-tier resources — so you experience firsthand what "diffing config against state" actually means.

No AWS account, or want to stay fully local? You may substitute the alternative local-cluster variant: use the community tehcyx/kind provider to declare a 3-node local Kubernetes cluster as code (terraform init / plan / apply, verify with kubectl get nodes, then terraform destroy). See Resources for the provider docs and a walkthrough. Talk to your instructor before switching variants.

Steps:

1. Install the tools (all free). Terraform CLI, Docker, LocalStack (free Community Edition), and the tflocal wrapper (pip install terraform-local). Confirm all four are on your PATH.
2. Start LocalStack. Run localstack start -d to bring up a local container that emulates AWS APIs on your machine — no AWS account charges, no free-tier risk.
3. Write your first main.tf: an AWS provider block and a single t2.micro EC2 instance resource using an official free-tier AMI, following HashiCorp's official "Create infrastructure" tutorial (linked in Resources).
4. Run the workflow locally first. From your project directory, use tflocal init, tflocal plan, and tflocal apply (the wrapper transparently redirects AWS API calls to your LocalStack container). Confirm in the plan output that Terraform intends to create exactly one EC2 instance, then apply it and confirm it exists with awslocal ec2 describe-instances.
5. Save the local plan/apply output to text files (local-plan.txt, local-apply.txt).
6. Run the same, unmodified configuration against real AWS. Using your own free-tier AWS account, run standard terraform init, terraform plan, and terraform apply (no tflocal wrapper) on the exact same .tf files. Save this output too (aws-plan.txt, aws-apply.txt).
7. Diff the two runs. Write a short comparison: what was identical between the LocalStack run and the real-AWS run? What (if anything) differed in the plan output, timing, or resulting resource attributes?
8. Destroy your real AWS resources immediately with terraform destroy to stay safely inside the free tier, and confirm in the AWS console that nothing is left running.
9. Extend with a second free-tier resource. Clone the open-source pvarentsov/terraform-aws-free-tier repo (linked in Resources), review how it organizes free-tier AWS resources, and add one new resource of your own — for example, an S3 bucket with a lifecycle rule that expires objects after 30 days. Run tflocal plan/tflocal apply against LocalStack to prove it works before ever pointing it at real AWS.
10. Write a short reflection (150–250 words) on: (a) one thing that surprised you about the plan/apply output, and (b) one concrete way terraform.tfstate protected you from re-creating resources unnecessarily during this lab.

Deliverables: Your main.tf (and any extended .tf files from Step 9), the four saved output files from Steps 5–6, your Step 7 diff write-up, and your Step 10 reflection, submitted as an upload (zipped folder or repo link) or pasted into the text entry box.