Skip to content

Latest commit

 

History

History
158 lines (115 loc) · 4.64 KB

README.rst

File metadata and controls

158 lines (115 loc) · 4.64 KB

aws ecs/cluster terraform module

A terraform module to provides ecs cluster

  • ECS Cluster
    • with AutoScaling Group
    • with Launch Configuration
    • with IAM Role & attached IAM Policy
    • with CloudWatch Log Group
  • [Optional] Autoscaling

See more details about Amazon ECS Clusters in the official AWS docs.


provider "aws" {
  # https://github.com/terraform-providers/terraform-provider-aws/releases
  version = "~> 1.0"
  region  = "${var.region}"
}

# Pre-require your resources declaration (as may be necessary)
# The following related sources is out of scope on this module
#resource "aws_key_pair"       "xxx" {}
#resource "aws_subnet"         "xxx" {}
#resource "aws_security_group" "xxx" {}
#data     "aws_ami"            "xxx" {}

module "ecs_cluster" {
  source                       = "git@github.com:voyagegroup/tf_aws_ecs//cluster"
  name                         = "ex-app-cluster"

  key_name                     = "${aws_key_pair.ex_app.key_name}"
  ami_id                       = "ami-04351e12"
  vpc_zone_identifier          = [
    "${aws_subnet.az_left.id}",
    "${aws_subnet.az_right.id}",
  ]
  security_groups              = ["${aws_security_group.ex_app.id}"]
  instance_type                = "c4.large"
  #ebs_optimized               = true
  user_data                    = "${ file('user_data.sh') }"

  asg_min_size                 = 0
  asg_max_size                 = 2
  #asg_default_cooldown        = 150
  #asg_enabled_metrics         = ["GroupDesiredCapacity"]
  #asg_termination_policies    = ["OldestInstance"]
  asg_extra_tags               = [
    {
      key                 = "Name"
      value               = "example-application"
      propagate_at_launch = true
    }
  ]

  log_group                    = "ex-app-cluster/ecs-agent"
  log_groups_expiration_days   = 14
  log_groups_tags              = {
    Application = "example"
  }
}

As below U can create enhanced ecs-service using optional input-variables or others

module "ecs_cluster" {
  source = "git@github.com:voyagegroup/tf_aws_ecs//cluster"

  # ...

  #scale_out_ok_actions        = []
  scale_out_more_alarm_actions = ["${aws_sns_topic.ex_alert.arn}"]
  scale_out_thresholds         = {
    memory_reservation = 75
    // cpu_util        =
    // cpu_reservation =
    // memory_util     =
  }

  #scale_in_ok_actions         = []
  #scale_in_more_alarm_actions = []
  scale_in_thresholds          = {
    memory_reservation = 40
    // cpu_util        =
    // cpu_reservation =
    // memory_util     =
  }
}

See more details about Scaling a Cluster What Is Auto Scaling? in the official AWS docs.

module "ecs_cluster" {
   # ...

   autoscale_notification_ok_topic_arn = "${aws_sns_topic.ex.arn}"
   autoscale_notification_ng_topic_arn = "${aws_sns_topic.ex_alert.arn}"
}

See more details about Getting SNS Notifications When Your Auto Scaling Group Scales in the official AWS docs.

Specify volume_size of root_block_device if U want perform to size, and iops

module "ecs_cluster" {
   # ...

   root_volume_size = 100
}

See more details about Storage Configuration General Purpose SSD (gp2) Volumes in the official AWS docs.