Skip to content

Commit

Permalink
feat: Allow disable scale-in protection for ECS nodes ASG
Browse files Browse the repository at this point in the history
  • Loading branch information
sugdyzhekov committed Aug 18, 2020
1 parent c36c1f1 commit 78eae4a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion asg.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
23 changes: 14 additions & 9 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand All @@ -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,
Expand Down

0 comments on commit 78eae4a

Please # to comment.