This repository contains a Terraform configuration that launches several public EC2 instances with one Classic Elastic Load Balancer.
project
│ *README.md
└───files
│ *docker_nginx.sh --> Script to install Docker and Nginx Image
│ *main_aws.tf --> AWS Provider and Key Pair
│ *main_ec2.tf --> EC2 instances and ec2 security group
│ *main_lb.tf --> Classic Elastic Load Balancer and elb security group
│ *main_vpc.tf --> VPC, Subnets, Route Tables, Route Table Association and VPC security group
│ *output.tf --> Outputs VPC id, public subnet ids, security group id, and DNS name for elb
│ *terraform.tfstate --> State of configuration
│ *terraform.tfvars --> Input variables (To change depending on AWS account)
│ *variables.tf --> Defines variables
When terraform configuration is applied, a VPC is created along with public subnets and each subnet will have an EC2 instance that will provision a Nginx Docker container with an availability zone based on the region. A public facing Classic Load Balancer is created to balance the instances.
To use terraform configuration, make sure you have the following:
- An AWS account
- AWS CLI installed
- terraform installed
- keypair created (to ssh into instances)
us-east-1
= ami-759bc50aus-east-2
= ami-5e8bb23bus-west-1
= ami-4aa04129us-west-2
= ami-ba602bc2
To start, replace all necessary variables in terraform.tfvars
and if necessary, variables.tf
.
Access key and secret key are provided from your AWS account
access_key = "ACCESS_KEY"
Run these terraform commands to launch the insfrastructure based on the configuration provided
$ terraform init
$ terraform plan
$ terraform apply
Run this terraform command to destroy the insfrastructure
$ terraform destroy
- Configuration has been tested across all US regions