This project is a skill assessment that I did for a job interview. The required steps were to create a server within AWS, run a mysql container which is accessed by the hostname 'mysql' and a container that would run a small django app.
Everything is configured and deployed using terraform with 0.12
syntax. A single terraform apply
will bring up all resources.
The django app can be acessed from port 8000 on the public IP of
the EC2 instance that is created.
I made two adjustments to the django app.
- Updated django from 3.0.2 to 3.0.3 to resolve a CVE
- Added '*' to ALLOWED_HOSTS so that the app could be accessed remotely.
Running terraform apply will do the following:
- Create an ssh key for accessing the EC2 instance for debugging purposes
- Write out both the private and public keys to disk.
- Create a VPC to use
- Create both an Internet gateway and a NAT gateway
- Assign an elastic IP to the nat gateway
- Create 2 subnets within the VPC
- Subnet for the EC2 instance that routes via the IGW
- Subnet for the mysql container that routes via the NAT gateway. (No public IPs)
- Create security groups for the EC2 instance and the mysql container.
- Assign rules to the previously created security groups
- Create an ECR repository for the django container
- Build the django container
- Tags the django container
- Pushes the built container to the ECR repository
- Creates a service discovery for the mysql instance.
- Create various IAM roles for the ECS instance
- Create an ASG launch configuration
- Use a script run via user_data to configure which ECS cluster to serve
- Create the auto scaling group (min/max/desired = 1)
- Creates an ECS cluster that the ASG EC2 instance will serve
- Create a task and service for the mysql container
- Create a task and service for the django app container