Overview
This Infrastructure as Code (IaC) project showcases the implementation of OpenTofu/Terraform to provision and configure an Amazon Web Services (AWS) Elastic Compute Cloud (EC2) instance. The EC2 instance serves as a Docker host, facilitating the deployment of a containerized static website.
This approach demonstrates best practices in cloud infrastructure automation and container-based application deployment.
It utilizes OpenTofu/Terraform and variables to provide reusable,
data driven components for the Infrastructure as Code (IaC)
deployment. The specifics of the deployment are configurable
through an (unpublished) terraforms.tfvars
file
which sets values passed to the OpenTofu/Terraform code.
Static website is sourced from a separate GitHub repository or can be sourced from local storage allowing separate maintenance and versioning from the IaC code.

Tech Stack
- AWS Command Line Interface (AWS CLI)
- Amazon EC2 key pair
- Docker Hub
- Visual Studio Code
- Git/GitHub
- Bash
- Terraform/openToFu
- Docker
- Amazon Elastic Compute Cloud (Amazon EC2)
- SSH
- wget
IaC Steps
- Create EC2 Instance
- Enable HTTP & SSH access
- Configure EC2 with existing Key Pair
- Connect to the EC2 instance using SSH
- Install and enable Docker in EC2
- Build image from `amazonlinux:latest`
- Update image adding `httpd`, `wget`, and `unzip`
- Download and unzip static web site content from GitHub
- Cleanup and start `httpd`
- Tag and push image to pre-existing Docker Hub repository
- Run Docker container using built image
The pattern for this project (Docker Container in EC2) is a bit dated. It is likely more prevalent to use AWS ECR and ECS or EKS.
The last output from the `terraform apply` is a URL for the container:
container_url = "http://<EC2-INSTANCE-PUBLIC-IPV4-DNS>"
Use this to browse to the running website.
OIr connect via `ssh` with:
ssh -i ~/.ssh/my-ec2-key-pair.pem ec2-user@<EC2-INSTANCE-PUBLIC-IPV4-DNS>