This Terraform project sets up an AWS infrastructure with the following components:
- A Virtual Private Cloud (VPC)
- Two subnets
- An Internet Gateway
- A route table
- A security group
- An S3 bucket
- Two EC2 instances
- An Application Load Balancer (ALB) with a target group and listener
- Terraform installed on your local machine
- AWS CLI configured with the necessary permissions
AWS VPC with ALB and EC2 Setup
├── main.tf # Main Terraform configuration
├── variables.tf # Variable definitions
├── outputs.tf # Output values
├── userdata.sh # User data script for webserver1
├── userdata1.sh # User data script for webserver2
└── README.md # Project documentation
- The userdata.sh and userdata1.sh files should contain the initialization scripts for the EC2 instances.
terraform init
terraform validate
terraform plan -var="cidr=<your-cidr-block>"
terraform apply -var="cidr=<your-cidr-block>"
- After the deployment, the DNS name of the load balancer will be outputted. You can find it in the outputs.tf file.
- To delete the created resources, apply the below command:
terraform destroy -var="cidr=<your-cidr-block>"
- Ensure that the AMI IDs used in aws_instance resources are valid for your region.
- Adjust the cidr_block values for the subnets as necessary.