This repository contains a solution for automating the deployment of ECS clusters and containers on AWS using Terraform and Shell scripts. It simplifies the process of provisioning the necessary infrastructure and managing containerized applications on the Amazon Elastic Container Service (ECS). The solution leverages Terraform to create AWS resources, such as VPC, IAM, ECR, ECS, and uses Shell scripts to streamline the build and deployment workflows.
Before getting started, ensure that you have the following prerequisites installed on your local machine:
- Terraform: Install Terraform
- AWS CLI: Install AWS CLI
The repository is organized as follows:
├───python-api
└───terraform
├───ecr
│ └───.terraform
│ ├───modules
│ └───providers
│
├───modules
│ ├───ecr
│ ├───ecs
│ ├───iam
│ └───vpc
└───stack
├───modules
└───providers
python-api
: Directory contains build_and_push.sh filetrerraform/
: This directory contains All Terraform files and modules for creating AWS resources.ecr
: separate entity to create ECR repo to avoid blockers.stack
: This is the heart of this project and contains all ECS and its dependencies modules.outputs.tf
: The file where output values from the Terraform modules are defined.
To utilize this solution, follow these steps:
- Clone the repository to your local machine.
- Navigate to the repository directory.
- Execute the
terraform/ecr
terraform script located in theterraform/
directory by using the commandterraform init; terraform apply --auto-approve
in directoryterraform/ecr
. This script creates an ECR repository to store your container images.
- Execute the
build_and_push.sh
script located in thepython-api/
directory. This script builds the container images, performs health checks to ensure container readiness, and pushes the images to the ECR repository.
./python-api/build_and_push.sh
- Execute the
terraform/stack
bundle of scripts located in theterraform/stack
directory using the commandterraform init; terraform apply --auto-approve
. This script runs the Terraform stack to deploy the required infrastructure.
Note: Before running the Terraform commands, make sure you have valid AWS credentials configured using the AWS CLI and user should have access to provisiong and configure ECR, ECS, CloudWatch, ALB, VPC, Endpoints and IAM roles provisioning acecss.