GitXplorerGitXplorer
m

terraform-ecs-container-instance-draining

public
6 stars
14 forks
10 issues

Commits

List of commits on branch master.
Verified
791c9d30ff55e24a2b2f28c4d480afa68aec0c5c

chore(deps): bump github.com/gruntwork-io/terratest from 0.29.0 to 0.30.0 (#1)

ddependabot[bot] committed 4 years ago
Unverified
7cda9a66d2f9b10beb9a18fc53072665eae697ea

ci: update changelog

iinvalid-email-address committed 4 years ago
Verified
6c1eacd9481314bb1189feb73382e2f0adf5bf15

chore: update readme

mmridehalgh committed 4 years ago
Unverified
ec214df48bb8a66d07f450270cb0f62c898d3451

ci(release): update changelog

iinvalid-email-address committed 4 years ago
Unverified
86bee88084c93b917a249083258631e3eba2e43c

feat: initial implementation of 'terraform-ecs-container-instance-draining'

mmridehalgh 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