Example from my udemy enroll course: Udemy: Terraform on AWS with SRE & IaC DevOps | Real-World 20 Demos
- You need a Registered Domain in AWS Route53 to implement this usecase
- Create
private-key
folder - Copy your AWS EC2 Key pair
terraform-key.pem
inprivate-key
folder
The values for these variables should be placed into terraform.tfvars. Simply copy terraform.tfvars.example to terraform.tfvars and edit it with the proper values.
terraform init
terraform validate
terraform plan
terraform apply
Observation:
- Verify EC2 Instances created
- Verify VPC
- Verify Subnets
- Verify IGW
- Verify Public Route for Public Subnets
- Verify no public route for private subnets
- Verify NAT Gateway and Elastic IP for NAT Gateway
- Verify NAT Gateway route for Private Subnets
- Verify no public route or no NAT Gateway route to Database Subnets
- Verify Subnets Security Group
- Verify SSL Certificate (Certificate Manager)
- Verify Route53 DNS Record
- Verify Load Balancer
- Verify Load Balancer Target Group - Health Checks
- Verify Launch Configuration (High Level)
- Verify Autoscaling Group (High Level)
- Verify Autoscaling Group Features In detail
- Details Tab
- ASG Group Details
- Launch Configuration
- Activity Tab
- Automatic Scaling
- Target Tracking Scaling Policies (TTSP)
- Scheduled Actions
- Instance Management
- Instances
- Lifecycle Hooks
- Monitoring
- Autoscaling
- EC2
- Instance Refresh Tab
- Verify Tags
# Connect to Bastion EC2 Instance from local desktop
ssh -i private-key/terraform-key.pem ec2-user@<PUBLIC_IP_FOR_BASTION_HOST>
# Curl Test for Bastion EC2 Instance to Private EC2 Instances
curl http://<Private-Instance-App1-Private-IP>
# Connect to Private EC2 Instances App 1 from Bastion EC2 Instance
ssh -i /tmp/terraform-key.pem ec2-user@<Private-Instance-App1-Private-IP>
cd /var/www/html
ls -lrta
Observation:
1) Should find index.html
2) Should find app1 folder
3) Should find app1/index.html file
4) Should find app1/metadata.html file
# App1
https://asg-lc.domain.com
https://asg-lc.domain.com/app1/index.html
https://asg-lc.domain.com/app1/metadata.html
- Download Postman client and Install
- Create New Collection: terraform-on-aws
- Create new Request: asg
- URL: https://asg-lc.domain.com/app1/metadata.html
- Click on RUN, with 5000 requests
- Monitor ASG -> Activity Tab
- Monitor EC2 -> Instances - To see if new EC2 Instances getting created (Autoscaling working as expected)
- It might take 5 to 10 minutes to autoscale with new EC2 Instances
terraform destroy
rm -rf .terraform*
rm -rf terraform.tfstate*