How mvasilenko/terraform-aws-infrastructure works
Main Components Identification
• Infrastructure Management: Represented by Terraform. You have multiple Terraform directories which are organized by region (e.g., eu-west-1) and further by service (e.g., network, ECS, LB, DNS, IAM).
• State & Lock Management: Include S3 (for Terraform state storage) and DynamoDB (for locking).
• Networking: VPC, public subnets, and security groups that are configured in the “network” directory.
• IAM Roles: Global IAM provisioning (in terraform/global/iam) and Terraform modules for IAM roles.
• Container Orchestration: ECS Cluster and Service (in terraform/eu-west-1/ecs/app), along with a task definition that runs the Flask application.
• Application: A simple Flask app located in the “app” directory, with related Dockerfile, build, and deployment scripts.
• Container Registry: ECR repository (configured in terraform/eu-west-1/ecr) where Docker images are built and pushed.
• Load Balancing: Application load balancer and listener configurations, including target group setup in the LB directory.
• DNS: Though not configured in code, the README mentions manual DNS configuration (e.g., mapping a hostname to the load balancer).
Relationships and Interactions
• Terraform orchestrates the entire AWS infrastructure, connecting components such as network, IAM, ECS, ECR, and LB.
• The Flask app is containerized using Docker, then built and pushed to the ECR repository.
• The ECS cluster pulls the container image from ECR and runs the Docker container as a service.
• The load balancer (ALB) routes external HTTP/HTTPS traffic to the running ECS tasks via defined listener rules and target groups.
• S3 and DynamoDB are used by Terraform to store the state and manage locking, ensuring consistent deployments.
• IAM roles granted to the container allow secure access to necessary AWS services (e.g., pulling images from ECR).
Architectural Patterns and Design Principles
• Separation of Concerns: Infrastructure code is clearly separated by AWS service and region. The application code is isolated in its own directory.
• Modular Design: Use of Terraform modules (for example, the iam-role module) promotes reuse and consistency.
• Declarative Infrastructure: The approach leverages Terraform’s declarative model to define dependencies and interactions.
• Continuous Deployment Pipeline: The process includes automated Docker image builds (via build.sh), pushing to ECR, and updating ECS with a new image tag via Terraform.