- VPC
- 4 Subnets (two public and two private) which includes creation of NAT and IG gateway.
- Two Security group for Load balancer (public) and application level (private).
- A EC2 launch configuration with autoscaling group and with attached target scaling policy based on CPUUtilisation metric threshold.
- Creates initially a single SPOT ec2 (t2.micro) instance in private subnet.
- Included 8GiB as primary root volume and 5GiB secondary storage (default) mount at "/dev/sdb" from launch config in auto scaling group.
- An internet facing application load balancer which exposes our nginx web-server on port 80 (HTTP) deployed in private subnet.
- S3 bucket to store the ALB access logs and to store encrypted terraform state in s3 bucket
- SNS topic as email notification for cloudwatch alarms to trigger sample "CPUUtilisation" metric threshold alert for autoscaling group.
This creates resources which are chargeable.
Terraform provider version
required_version = "<= 0.12.14"
Configure AWS profile with credentials locally with appropriate access
aws configure
Clone the repo
$ git clone https://github.com/kararag/tf-demo-web-server.git
Update all the mandatory parameters in file "terraform.tfvars". By default it creates with demo values in region "ap-south-1". It's tested with default values provided in the terraform.tfvars using ALB. For email notification, it's sns subscription needs to be confirmed from valid email endpoint to get alarms.
To check mandatory parameters to pass here refer comments
$ vi terraform.tfvars
For S3 backend, update the existing s3 bucket name in file "backend.tf"
$ vi backend.tf
To initialize the terraform plugins and modules
$ terraform init
To check the terraform plan and verify
$ terraform plan
To create resources from the plan; confirm "yes"
$ terraform apply
wait for a few minutes till the resources are finished creating...
To get the ALB DNS endpint, refer to "aws_lb_dns" value in output.
Use the end point value from above output, you should see that redirecting to a demo nginx page
To destroy the resource stack completely
$ terraform plan --destroy
$ terraform destroy --auto-approve