Skip to content

uday770202/ECS-Terraform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧭 Terraform + AWS ECS Deployment (Step-by-Step)

This guide walks you through deploying a containerized app to AWS ECS using Terraform. It includes:

  • VPC with 2 public and 2 private subnets
  • Application Load Balancer (ALB)
  • ECS Fargate to host a Docker container (running in private subnets)
  • Terraform remote state setup

🧱 Directory Structure

.
β”œβ”€β”€ app/                            # Flask app + Dockerfile
└── terraform/                      # Terraform files                 
    β”œβ”€β”€ main.tf                     # Entry point - root module
    β”œβ”€β”€ variables.tf                # Input variables
    β”œβ”€β”€ providers.tf                # Provider declaration
    β”œβ”€β”€ outputs.tf                  # Outputs from root
    └── modules/                    # Module-based infrastructure
        β”œβ”€β”€ vpc/                    # VPC module
        β”œβ”€β”€ alb/                    # Load Balancer module
        └── ecs/                    # ECS + Task + Service

πŸš€ Deployment Instructions (ECR + Terraform)

Step 1: Create ECR Repository

aws ecr create-repository --repository-name simple-time-service --region ap-south-1

Step 2: Authenticate Docker to ECR

Replace <your_aws_account_id> with your actual AWS account number:

aws ecr get-login-password --region ap-south-1 | docker login --username AWS --password-stdin <your_aws_account_id>.dkr.ecr.ap-south-1.amazonaws.com

Step 3: Build and Push Docker Image

docker build -t simple-time-service ./app

docker tag simple-time-service:latest <your_aws_account_id>.dkr.ecr.ap-south-1.amazonaws.com/simple-time-service:latest

docker push <your_aws_account_id>.dkr.ecr.ap-south-1.amazonaws.com/simple-time-service:latest

Step 4: Deploy Terraform Infrastructure

cd terraform
terraform init

# Replace with the correct image URI from Step 3
terraform plan -var="app_image=<your_aws_account_id>.dkr.ecr.ap-south-1.amazonaws.com/simple-time-service:latest"
terraform apply -var="app_image=<your_aws_account_id>.dkr.ecr.ap-south-1.amazonaws.com/simple-time-service:latest"

Step 5: Access the App

Once deployed, find the Load Balancer DNS name output from Terraform and visit:

http://<alb_dns>

You should see JSON output with timestamp and IP.


βœ… You're done!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published