/terraform-aws-ecs-cluster

AWS ECS cluster terraform module

Primary LanguageHCLApache License 2.0Apache-2.0

About

Terraform module to run ECS cluster, with ASG + Launch Template + Scaling policies via capacity provider. See details in the corresponding AWS blog post Amazon ECS Cluster Auto Scaling is Now Generally Available.

Features:

  • ECS cluster manages ASG capacity automatically.
  • ASG with optional spot instances support.
  • It's possible to specify various instance types for your cluster.
  • EC2 instance profile with SSM policy - you can connect to the instances using the Session Manager.
  • Default ECS task role allows creating a log group.
  • Default security group for ECS nodes allow inbound connections from configurable list of network CIDRs.
  • It's possible to specify additional security groups for ECS nodes.
  • Latest ECS Optimized AMI.

Usage

module "example_ecs_cluster" {
  source              = "github.com/jetbrains-infra/terraform-aws-ecs-cluster?ref=vX.X.X" // see https://github.com/jetbrains-infra/terraform-aws-ecs-cluster/releases
  cluster_name        = "FooBar"
  spot                = true
  instance_types = {
    "t3a.large"  = 1
    "t3a.xlarge" = 2
  }
  target_capacity = 100

  // subnets with ALB and bastion host e.g..
  trusted_cidr_blocks = [
    aws_subnet.public_subnet_1.cidr_block,
    aws_subnet.public_subnet_2.cidr_block
  ]
  
  subnets_ids         = [
    aws_subnet.private_subnet_1.id,
    aws_subnet.private_subnet_2.id
  ]

  tags = {
    Stack = "Dev"
  }
}

Default values:

module "example_ecs_cluster" {
  source              = "github.com/jetbrains-infra/terraform-aws-ecs-cluster?ref=vX.X.X" // see https://github.com/jetbrains-infra/terraform-aws-ecs-cluster/releases
  cluster_name        = "FooBar"
  spot                = false
  instance_types = {
    "t3a.small"  = 2
  }
  target_capacity    = 100
  security_group_ids = []
  // subnets with ALB and bastion host e.g..
  trusted_cidr_blocks = []
  subnets_ids         = [
    aws_subnet.private_subnet_1.id,
    aws_subnet.private_subnet_2.id
  ]

  tags = {
    Name   = "FooBar",
    Module = "ECS Cluster"
  }
}

Outputs

  • name - cluster name
  • id - cluster id
  • arn - cluster ARN
  • ecs_service_role_name - ECS service role name
  • ecs_default_task_role_name - ECS default task role name
  • iam_instance_profile_arn - IAM instance profile ARN
  • iam_instance_profile_name - IAM instance profile name
  • iam_instance_role_name - IAM instance role name
  • security_group_id - security group id
  • security_group_name - security group name