- Create a VPC which should have a public and private subnet
- Create a role with s3 access.
- Launch an ec2 instance with the role created in step 1, inside the private subnet of VPC, and install apache through bootstrapping. (You need to have your NAT gateway attached to your private subnet)
- Create a load balancer in public subnet.
- Add the ec2 instance, under the load balancer
- Create an auto scaling group with minimum size of 1 and maximum size of 3 with load balancer created in step 3.
- Add the created instances under the auto scaling group.
- Write a life cycle policy with the following parameters: a. scale in : CPU utilization > 80% b. scale out : CPU Utilization < 60%
- Create a persistence layer of your choice and ensure that the ec2 instance can access it
- Basic knowledge of aws is required
- Basic knowledge of terraform is required
- AWS CLI (Install AWS CLI)
- Terraform (Install Terraform)
- aws configure
We have to create a new profile using aws configure command. This require access key and secret key to make profile and this profile will be used in terraform provider for authentication.
$ aws configure --profile yourProfilename
- Providers (terraform and aws) and profile
main.tf
- VPC (creating a VPC)
main.tf
- Subnets (Private & Public)
main.tf
- Internal Gateway for VPC (Create a internal gateway for VPC)
main.tf
- Elastic IP (Create a Elastic IP)
main.tf
- Route Table and Association for Public and Private Subnets
main.tf
- Create an S3 bucket and make it Private
main.tf
- Create a policy that will give access to the S3 bucket
allowaccess.json
main.tf
- Create an IAM role
ec2-assume-policy.json
main.tf
- Policy Attachment (Attach the policy to the role)
main.tf
- Create Security Group
main.tf
- Create apache launch configuration
ec2.tf
- Create Apache web instance EC2
ec2.tf
- Create IAM instance profile
main.tf
- Create an application load balancer security group
main.tf
- Create a new application load balancer in public subnet
main.tf
- Create a new target group for the application load balancer
main.tf
- Create a listener
main.tf
- Creating a target group attachment for the target group
main.tf
- Create a new ALB Target Group Attachment
main.tf
- Create an auto scaling group
main.tf
- Write a life cycle policy to scale up and down
main.tf
- Write a trigger using a CloudWatch alarm
main.tf
- Create Elastic Block Storage for our second EC2 instance
main.tf
- Create a volume attachment for our second EC2 instance
main.tf
Please run the following Terraform Code:
- terraform init
- terraform plan
- terraform apply
- Login into your AWS Console and click on the autoscaling EC2. Then copy the Public IPv4 address to your web browser: