Module 12 - Terraform

Lab 1: Create an EC2 Instance with Terraform

  • How do you write a main.tf file that creates 1 EC2 instance?

  • How do you use the latest Amazon Linux 2 AMI in Terraform?

  • How do you specify the t2.micro instance type?

  • How do you output the instance’s public IP using Terraform outputs?


Lab 2: Create a VPC from Scratch

  • How do you create a VPC with Terraform?

  • How do you add one public subnet and one private subnet?

  • How do you attach an Internet Gateway to the VPC?

  • How do you create route tables for both subnets?

  • How do you deploy an EC2 instance in the public subnet?

  • How do you verify public access using ping or SSH?


Lab 3: Use Terraform Variables & tfvars

  • How do you convert hardcoded values into Terraform variables (region, instance type, bucket name)?

  • How do you create variables.tf and terraform.tfvars?

  • How do you re-run Terraform while ensuring idempotency (no unnecessary recreations)?


Lab 4: Create IAM User, Group & Policy

  • How do you create an IAM user named devops-user in Terraform?

  • How do you create an IAM group named devops-group?

  • How do you create a policy with S3 read-only access?

  • How do you attach the IAM user to the group?

  • How do you output the IAM user’s ARN?


Lab 5: Remote State with S3 + DynamoDB

  • How do you create an S3 bucket to store Terraform state?

  • How do you create a DynamoDB table for state locking?

  • How do you update the Terraform backend block to use S3 + DynamoDB?

  • How do you migrate the existing state using terraform init?


Lab 6: Create a Reusable Terraform Module

  • How do you build a Terraform module that launches an EC2 instance?

  • How do you parameterize the module with:

    • Name tag

    • Instance type

    • AMI

  • How do you use this module to create three EC2 instances?

  • How do you output the private IPs of all instances?


Lab 7: Deploy a Load Balancer + Auto Scaling Group

  • How do you create a launch template in Terraform?

  • How do you create an Auto Scaling Group with desired capacity 2?

  • How do you create an Application Load Balancer?

  • How do you create a target group for the ALB?

  • How do you verify ALB health checks?

  • How do you confirm that EC2 instances auto-register to the target group?

  • How do you scale the ASG to 3 using Terraform?


Lab 8: Auto-Deploy Docker Container via User Data

  • How do you update EC2 user data to install Docker?

  • How do you pull the Nginx Docker image in user data?

  • How do you run the Nginx container on port 80 at launch?


Lab 9: Multi-Region EC2 Deployment

  • How do you configure multiple AWS providers using alias?

  • How do you deploy EC2 resources to two different regions (e.g., us-east-1 and us-west-2)?

  • How do you output the public IP addresses of both instances?

  • How do you validate the deployment by SSH’ing into instances in both regions?


Lab 10: Terraform Workspaces (Dev / Stage / Prod)

  • How do you create Terraform workspaces: dev, stage, and prod?

  • How do you deploy EC2 instances with different tags based on workspace?

  • How do you verify that each workspace deploys separate infrastructure?

Last updated