A terraform module that creates:
- A load balancer
- An auto scalling group
- 5 ububtu VM with Apache that serve "hello world"
-
Run those commands:
# Tools brew install terraform brew install packer # Build Ububtu with Apache packer build apache-packer.json
-
Create a KeyPair and save it on disk.
-
Change
image_id
andkey_name
inmain.tf
module "ninfra" { source = "./infra" # Use the image_id created with: # packer build apache-packer.json # https://us-west-2.console.aws.amazon.com/ec2/v2/home?region=us-west-2#Images:visibility=owned-by-me;sort=name image_id = "ami-081c4a2dcf94faaa0" # Use the key-pair created in: # https://us-west-2.console.aws.amazon.com/ec2/v2/home?region=us-west-2#KeyPairs:sort=keyName key_name = "ssh-key" }
-
Build the infra
terraform init terraform apply
- Go to EC2 instance dashboard
- Terminate a
ninfra instance
the
-
Find an instance ip on the EC2 instance dashboard
-
Go to a terminal and ssh to that instance
# Change acl of the key downloaded when keyPair was created. chmod 0600 ssh-key.pem.txt # Ssh to the instance. ssh -i ssh-key.pem.txt ubuntu@INSTANCE_IP # Kill apache. sudo killall -9 apache2
- EC2 instance dashboard
- Target group dashboard on the Targets tab.
- Auto Scalling dashboard
- Activity History tab
- Instances Tab
- Load Balancers dashboard - Enter the DNS Name in a browser to see Hello World
-
Deregister
ami-ninfra
-
Destroy the infra
terraform destroy