A simple PoC using Terraform to create two instances of Amazon AWS EC2 servers running Docker with containerized Nginx daemon. It uses default Amazon AMI PV image for us-east-1.
To check what recurses will be created:
$ terraform plan
To create EC2 instances and their dependencies:
$ terraform apply
To destroy all:
$ terraform destroy
Dockerfile which uses the official ruby image (https://hub.docker.com/_/ruby/) which contains a ruby program running in an infinite loop and doing the following: Program
- Do a 5sec pause.
- Downloads the JSON file exercise1.yaml
- Generates terraform resources “aws_instance” (https://www.terraform.io/docs/providers/ aws/r/instance.html) and “aws_key_pair” (https://www.terraform.io/docs/providers/aws/r/ key_pair.html) out of it. The key needs to be used by the instance.
- Prints out the terraform resources.
In order to use it create Docker image from Dockerfile and start a container:
- cd lab
- docker build -t test .
- docker run -dt test
A terraform configuration which contains the following: AWS Setup
• An EC2 instance of type t2.micro based on a Ubuntu image.
• A Loadbalancer forwarding incoming requests to the EC2 instance.
• The EC2 instance needs to run an Nginx webserver serving one HTML file (just make one up and make the file part of your Github repo).
• The Nginx server is a Docker container started on the EC2 instance.
The state can be deployed by:
- terraform init and
- terraform apply.
These projects require AWS permissions to create ressources.