Skip to content

This project defines and deploys a containerized application infrastructure on AWS using Terraform modules.

Notifications You must be signed in to change notification settings

mrshadow98/terraform-aws-ecs-stack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Infrastructure as Code - Project

This project defines and deploys a containerized application infrastructure on AWS using Terraform modules.

The main AWS services covered:

  • Amazon ECS (Elastic Container Service) - Cluster and Service for app deployment.
  • Amazon ECR (Elastic Container Registry) - Container image storage.
  • AWS CodeBuild and CodePipeline - CI/CD Pipeline for automatic build and deployment.
  • Amazon API Gateway (HTTP API) - API endpoint integration with services using VPC Link and Service Discovery.
  • AWS Cloud Map - Internal service discovery.

📁 Project Structure

terraform/
├── environments/
│   ├── dev/
│   │   ├── main.tf
│   │   ├── variables.tf
│   │   ├── outputs.tf
│   ├── qa/
│   │   ├── main.tf
│   │   ├── variables.tf
│   │   ├── outputs.tf
│   └── prod/
│       ├── main.tf
│       ├── variables.tf
│       ├── outputs.tf
│
├── modules/
│   ├── ecs/
│   │   ├── main.tf
│   │   ├── variables.tf
│   │   ├── outputs.tf
│   ├── ecr/
│   │   ├── main.tf
│   │   ├── variables.tf
│   │   ├── outputs.tf
│   ├── codebuild/
│   │   ├── main.tf
│   │   ├── variables.tf
│   │   ├── outputs.tf
│   ├── codepipeline/
│   │   ├── main.tf
│   │   ├── variables.tf
│   │   ├── outputs.tf
│   ├── apigateway/
│   │   ├── main.tf
│   │   ├── variables.tf
│   │   ├── outputs.tf
│   └── vpc/ (Optional)
│       ├── main.tf
│       ├── variables.tf
│       ├── outputs.tf
├── provider.tf
├── backend.tf
└── versions.tf

🚀 Main Components

ECS Module (modules/ecs/)

  • Creates an ECS Cluster.
  • Creates ECS Services using AWS Fargate or EC2 launch type.
  • Supports Service Discovery with Cloud Map.
  • Integrates with API Gateway via VPC Link.

ECR Module (modules/ecr/)

  • Creates an ECR repository.
  • Supports tagging strategies like :latest for image deployments.

CodeBuild Module (modules/codebuild/)

  • Creates a CodeBuild project to build Docker images.
  • Pushes images automatically to ECR.

CodePipeline Module (modules/codepipeline/)

  • Creates a full CI/CD pipeline:
    • Source from GitHub/GitLab via CodeStar Connections.
    • Build using CodeBuild.
    • Deploy image to ECS Service.

API Gateway Module (modules/apigateway/)

  • Creates a VPC-integrated API Gateway (HTTP API).
  • Connects to ECS Services via Service Discovery (Cloud Map).
  • Handles default route $default with ANY method forwarding.

🔐 Secrets and Encryption

  • KMS Keys are used for encryption:
    • For SSM SecureString parameters.
    • For S3 bucket encryption if needed.

📜 Usage

  1. Set AWS credentials (through CLI config, environment variables, or IAM roles).
  2. Initialize Terraform:
    terraform init
  3. Select workspace (example: prod, qa, dev):
    terraform workspace select prod
  4. Apply changes:
    terraform apply

✨ Notes

  • Highly modular: Components can be deployed independently if needed.
  • Environment-specific configurations handled through workspaces and parameter store.
  • Secure defaults: Encryption, minimal IAM permissions.
  • Production-ready structure.

About

This project defines and deploys a containerized application infrastructure on AWS using Terraform modules.

Topics

Resources

Stars

Watchers

Forks

Languages