/terraform-aws-ecs-cluster

Creates an ECS cluster backed by an Auto Scaling Group

Primary LanguageHCLBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

DEPRECATION NOTICE

This module has been deprecated and is no longer maintained. Should you need to continue to use it, please fork the repository. Thank you.

Creates an ECS cluster backed by an AutoScaling Group.

The cluster is minimally configured and expects any ECS service added will use awsvpc networking and Task IAM Roles for access control.

Creates the following resources:

  • IAM role for the container instance.
  • Launch Configuration and AutoScaling group.
  • ECS cluster.

Usage

data "aws_ami" "ecs_ami" {
  most_recent = true
  owners      = ["amazon"]

  filter {
    name   = "name"
    values = ["amzn-ami-*-amazon-ecs-optimized"]
  }
}

module "app_ecs_cluster" {
  source = "trussworks/ecs-cluster/aws"

  name        = "app"
  environment = "prod"

  image_id      = "${data.aws_ami.ecs_ami.image_id}"
  instance_type = "t2.micro"

  vpc_id           = "${module.vpc.id}"
  subnet_ids       = "${module.vpc.private_subnets}"
  desired_capacity = 3
  max_size         = 3
  min_size         = 3
}

Terraform Versions

Terraform 0.13. Pin module version to ~> 3.0. Submit pull-requests to master branch.

Terraform 0.12. Pin module version to ~> 2.0. Submit pull-requests to terraform012 branch.

Terraform 0.11. Pin module version to ~> 1.0. Submit pull-requests to terraform011 branch.

Requirements

Name Version
terraform >= 0.13.0
aws ~> 4.0

Providers

Name Version
aws ~> 4.0

Modules

No modules.

Resources

Name Type
aws_autoscaling_group.main resource
aws_ecs_cluster.main resource
aws_iam_instance_profile.ecs_instance_profile resource
aws_iam_role.ecs_instance_role resource
aws_iam_role_policy_attachment.ecs_instance_role_policy resource
aws_launch_configuration.main resource
aws_security_group.main resource
aws_security_group_rule.main resource
aws_iam_policy_document.ecs_instance_assume_role_policy data source

Inputs

Name Description Type Default Required
desired_capacity Desired instance count. string 2 no
environment Environment tag. string n/a yes
image_id Amazon ECS-Optimized AMI. string n/a yes
instance_type The instance type to use. string "t2.micro" no
max_size Maxmimum instance count. string 2 no
min_size Minimum instance count. string 2 no
name The ECS cluster name this will launching instances for. string n/a yes
security_group_ids A list of security group ids to attach to the autoscaling group list(string) [] no
subnet_ids A list of subnet IDs to launch resources in. list(string) n/a yes
use_AmazonEC2ContainerServiceforEC2Role_policy Attaches the AWS managed AmazonEC2ContainerServiceforEC2Role policy to the ECS instance role. string true no
vpc_id The id of the VPC to launch resources in. any n/a yes

Outputs

Name Description
ecs_cluster_arn The ARN of the ECS cluster.
ecs_cluster_name The name of the ECS cluster.
ecs_instance_role The name of the ECS instance role.

Developer Setup

Install dependencies (macOS)

brew install pre-commit go terraform terraform-docs
pre-commit install --install-hooks