Skip to content

Commit 8f596f4

Browse files
committed
Moving autoscaling resources to anther module
1 parent 81ed1d6 commit 8f596f4

File tree

3 files changed

+28
-92
lines changed

3 files changed

+28
-92
lines changed

autoscaling.tf

Lines changed: 0 additions & 88 deletions
This file was deleted.

main.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,22 @@ resource "aws_security_group_rule" "ingress_through_https" {
150150
protocol = "tcp"
151151
source_security_group_id = module.ecs-alb.aws_security_group_lb_access_sg_id
152152
}
153+
154+
module "ecs-autoscaling" {
155+
count = var.enable_autoscaling ? 1 : 0
156+
157+
source = "cn-terraform/ecs-service-autoscaling/aws"
158+
version = "1.0.0"
159+
160+
name_prefix = var.name_prefix
161+
ecs_cluster_name = var.ecs_cluster_name
162+
ecs_service_name = aws_ecs_service.service.name
163+
max_cpu_threshold = var.max_cpu_threshold
164+
min_cpu_threshold = var.min_cpu_threshold
165+
max_cpu_evaluation_period = var.max_cpu_evaluation_period
166+
min_cpu_evaluation_period = var.min_cpu_evaluation_period
167+
max_cpu_period = var.max_cpu_period
168+
min_cpu_period = var.min_cpu_period
169+
scale_target_max_capacity = var.scale_target_max_capacity
170+
scale_target_min_capacity = var.scale_target_min_capacity
171+
}

variables.tf

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,16 @@ variable "container_name" {
122122
#------------------------------------------------------------------------------
123123
# AWS ECS SERVICE AUTOSCALING
124124
#------------------------------------------------------------------------------
125+
variable "enable_autoscaling" {
126+
description = "(Optional) If true, autoscaling alarms will be created."
127+
type = bool
128+
default = true
129+
}
130+
125131
variable "ecs_cluster_name" {
126-
description = "Name of the ECS cluster"
132+
description = "(Optional) Name of the ECS cluster. Required only if autoscaling is enabled"
133+
type = string
134+
default = null
127135
}
128136

129137
variable "max_cpu_threshold" {
@@ -174,9 +182,6 @@ variable "scale_target_min_capacity" {
174182
#------------------------------------------------------------------------------
175183
# AWS LOAD BALANCER
176184
#------------------------------------------------------------------------------
177-
#------------------------------------------------------------------------------
178-
# APPLICATION LOAD BALANCER
179-
#------------------------------------------------------------------------------
180185
variable "lb_internal" {
181186
description = "(Optional) If true, the LB will be internal."
182187
type = bool

0 commit comments

Comments
 (0)