AWS Scenarios
This guide provides practical deployment scenarios for AWS using Terraform, incorporating modern best practices and patterns for 2025.
ECS Fargate with Application Load Balancer
A production-ready ECS Fargate deployment with ALB:
module "ecs_cluster" {
source = "./modules/ecs-cluster"
name = "production"
capacity_providers = ["FARGATE", "FARGATE_SPOT"]
default_capacity_provider_strategy = [
{
capacity_provider = "FARGATE"
weight = 60
base = 1
},
{
capacity_provider = "FARGATE_SPOT"
weight = 40
}
]
container_insights = true
}
module "ecs_service" {
source = "./modules/ecs-service"
name = "api-service"
cluster_id = module.ecs_cluster.id
task_definition = {
cpu = 1024
memory = 2048
container_definitions = [
{
name = "api"
image = "${var.ecr_repository_url}:latest"
cpu = 512
memory = 1024
essential = true
portMappings = [
{
containerPort = 8080
protocol = "tcp"
}
]
environment = [
{
name = "ENV"
value = "production"
}
]
logConfiguration = {
logDriver = "awslogs"
options = {
awslogs-group = "/ecs/api-service"
awslogs-region = var.aws_region
awslogs-stream-prefix = "api"
}
}
}
]
}
networking = {
subnets = var.private_subnet_ids
security_groups = [aws_security_group.ecs_tasks.id]
assign_public_ip = false
}
load_balancer = {
target_group_arn = module.alb.target_group_arns[0]
container_name = "api"
container_port = 8080
}
auto_scaling = {
min_capacity = 2
max_capacity = 10
cpu_threshold = 75
memory_threshold = 75
}
enable_execute_command = true
}Multi-Account AWS Organization
Setting up a secure multi-account AWS organization:
Secure VPC with Transit Gateway
Deploy a secure VPC architecture with Transit Gateway:
EKS Cluster with Node Groups
Deploy a production-ready EKS cluster:
Aurora Serverless v2 Database
Deploy a highly available Aurora Serverless v2 cluster:
CloudFront with S3 Origin
Deploy a secure CloudFront distribution with S3:
Best Practices
1. Resource Tagging Strategy
2. IAM Role Strategy
3. Security Groups
Testing
Integration Tests with Terratest
Last updated