GitXplorerGitXplorer
m

terraform-ecs-container-instance-draining

public
6 stars
14 forks
10 issues

Commits

List of commits on branch master.
Unverified
e6e821661a740d8b0967e7808e6749f151ae3b05

ci(release): update changelog

iinvalid-email-address committed 4 years ago
Unverified
44ab76438ab9f5e773d13a46d3a7ef937b09a342

ci: update changelog

iinvalid-email-address committed 4 years ago
Verified
3072178016d5d523c0b39034de0a3f894ce165f0

feat: upgrade terraform aws provider (#27)

committed 4 years ago
Unverified
67528214c72557615d5dd798c66536a63fb2a4b4

ci: update changelog

iinvalid-email-address committed 4 years ago
Verified
f0db98796d557ce759cb98b082f8522b609130ab

chore(deps): bump github.com/aws/aws-sdk-go from 1.34.22 to 1.34.28 (#3)

ddependabot[bot] committed 4 years ago
Unverified
e169f9f0d3b5b29e058b079ced0303f20d91c41b

ci: update changelog

iinvalid-email-address committed 4 years ago

README

The README file for this repository.

ECS container instance draining on lifecycle events

Conventional Commits CI

Overview

Automates Container Instance Draining in Amazon ECS by removing tasks from an instance before scaling down a cluster with Auto Scaling Groups. Heavily inspired by this blog post from AWS. Lambda source code taken from and terraform inspired by the CloudFormation stack from Amazon available here.

It works by consuming lifecyle events from an autoscaling group. When an autoscaling:EC2_INSTANCE_TERMINATING event happens for the specified ASG it is placed on an SNS topic which in turn triggers lambda that will drain the tasks first from the ECS instance and then terminate the instance once the number of tasks on the instance become zero.

Architecture

Usage

data "aws_region" "current" {}

module "example_module_test" {
  source = "git::https://github.com/edispark/terraform-ecs-container-instance-draining"

  autoscaling_group_name = "arn:partition:service:region:account-id:autoScalingGroupName/XXX"
  autoscaling_group_arn = "my-asg-name"
  ecs_cluster_arn = "arn:partition:service:region:account-id:cluster/XXX"
  ecs_cluster_name = "my-ecs-cluster-name"

  region                 = data.aws_region.current.name
}

Requirements

Name Version
terraform >= 0.12.26
aws >= 3.0
local 1.4.0

Providers

Name Version
aws >= 3.0
local 1.4.0

Inputs

Name Description Type Default Required
autoscaling_group_arn The name of the Auto Scaling group to which you want to assign the lifecycle hook to string n/a yes
autoscaling_group_name The name of the Auto Scaling group to which you want to assign the lifecycle hook to string n/a yes
ecs_cluster_arn Specifies the ECS Cluster ARN with which the resources would be associated string n/a yes
ecs_cluster_name Specifies the ECS Cluster Name with which the resources would be associated string n/a yes
region AWS Region for ECS cluster string n/a yes
tags Additional tags (_e.g._ { BusinessUnit : ABC }) map(string) {} no

Outputs

Name Description
sns_topic_arn Topic used by ASG to send notifications when instance state is changing

Development

Prerequisites

Configurations

  • Configure pre-commit hooks
pre-commit install
  • Configure golang deps for tests
> go get github.com/gruntwork-io/terratest/modules/terraform
> go get github.com/stretchr/testify/assert

Tests

  • Tests are available in test directory
  • In the test directory, run the below command
go test