From 78eae4a8acb568ac924faec285220c350e2c95df Mon Sep 17 00:00:00 2001 From: Sergei Ugdyzhekov Date: Tue, 18 Aug 2020 20:39:13 +0200 Subject: [PATCH] feat: Allow disable scale-in protection for ECS nodes ASG --- asg.tf | 2 +- variables.tf | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/asg.tf b/asg.tf index 6e3e8b3..2d28715 100644 --- a/asg.tf +++ b/asg.tf @@ -3,7 +3,7 @@ resource "aws_autoscaling_group" "ecs_nodes" { max_size = 100 min_size = 0 vpc_zone_identifier = local.subnets_ids - protect_from_scale_in = true + protect_from_scale_in = local.protect_from_scale_in mixed_instances_policy { instances_distribution { diff --git a/variables.tf b/variables.tf index 3681d32..555a5bb 100644 --- a/variables.tf +++ b/variables.tf @@ -17,6 +17,10 @@ variable "instance_types" { "t3a.small" = 2 } } +variable "protect_from_scale_in" { + description = "The autoscaling group will not select instances with this setting for termination during scale in events." + default = true +} data "aws_ssm_parameter" "ecs_ami" { name = "/aws/service/ecs/optimized-ami/amazon-linux-2/recommended/image_id" } @@ -41,15 +45,16 @@ data "aws_subnet" "default" { } locals { - vpc_id = data.aws_subnet.default.vpc_id - subnets_ids = var.subnets_ids - name = replace(var.cluster_name, " ", "_") - trusted_cidr_blocks = var.trusted_cidr_blocks - instance_types = var.instance_types - sg_ids = distinct(concat(var.security_group_ids, [aws_security_group.ecs_nodes.id])) - ami_id = data.aws_ssm_parameter.ecs_ami.value - spot = var.spot == true ? 0 : 100 - target_capacity = var.target_capacity + vpc_id = data.aws_subnet.default.vpc_id + subnets_ids = var.subnets_ids + name = replace(var.cluster_name, " ", "_") + trusted_cidr_blocks = var.trusted_cidr_blocks + instance_types = var.instance_types + sg_ids = distinct(concat(var.security_group_ids, [aws_security_group.ecs_nodes.id])) + ami_id = data.aws_ssm_parameter.ecs_ami.value + spot = var.spot == true ? 0 : 100 + target_capacity = var.target_capacity + protect_from_scale_in = var.protect_from_scale_in tags = merge({ Name = var.cluster_name,