Skip to content

Commit ed39447

Browse files
authored
Merge pull request #16 from AntonAleksandrov13/master
More configurations for Autoscalling
2 parents 438cee9 + 1536bfc commit ed39447

File tree

2 files changed

+53
-8
lines changed

2 files changed

+53
-8
lines changed

autoscaling.tf

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ resource "aws_iam_role_policy" "ecs_autoscale_role_policy" {
2020
resource "aws_cloudwatch_metric_alarm" "cpu_high" {
2121
alarm_name = "${var.name_preffix}-cpu-high"
2222
comparison_operator = "GreaterThanOrEqualToThreshold"
23-
evaluation_periods = "3"
23+
evaluation_periods = var.max_cpu_evaluation_period
2424
metric_name = "CPUUtilization"
2525
namespace = "AWS/ECS"
26-
period = "60"
26+
period = var.max_cpu_period
2727
statistic = "Maximum"
28-
threshold = "85"
28+
threshold = var.max_cpu_threshold
2929
dimensions = {
3030
ClusterName = var.ecs_cluster_name
3131
ServiceName = aws_ecs_service.service.name
@@ -39,12 +39,12 @@ resource "aws_cloudwatch_metric_alarm" "cpu_high" {
3939
resource "aws_cloudwatch_metric_alarm" "cpu_low" {
4040
alarm_name = "${var.name_preffix}-cpu-low"
4141
comparison_operator = "LessThanOrEqualToThreshold"
42-
evaluation_periods = "3"
42+
evaluation_periods = var.min_cpu_evaluation_period
4343
metric_name = "CPUUtilization"
4444
namespace = "AWS/ECS"
45-
period = "60"
45+
period = var.min_cpu_period
4646
statistic = "Average"
47-
threshold = "10"
47+
threshold = var.min_cpu_threshold
4848
dimensions = {
4949
ClusterName = var.ecs_cluster_name
5050
ServiceName = aws_ecs_service.service.name
@@ -100,6 +100,6 @@ resource "aws_appautoscaling_target" "scale_target" {
100100
resource_id = "service/${var.ecs_cluster_name}/${aws_ecs_service.service.name}"
101101
scalable_dimension = "ecs:service:DesiredCount"
102102
role_arn = aws_iam_role.ecs_autoscale_role.arn
103-
min_capacity = 1
104-
max_capacity = 5
103+
min_capacity = var.scale_target_min_capacity
104+
max_capacity = var.scale_target_max_capacity
105105
}

variables.tf

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,51 @@ variable "ecs_cluster_name" {
126126
description = "Name of the ECS cluster"
127127
}
128128

129+
variable "max_cpu_threshold" {
130+
description = "Threshold for max CPU usage"
131+
default = "85"
132+
type = string
133+
}
134+
variable "min_cpu_threshold" {
135+
description = "Threshold for min CPU usage"
136+
default = "10"
137+
type = string
138+
}
139+
140+
variable "max_cpu_evaluation_period"{
141+
description = "The number of periods over which data is compared to the specified threshold for max cpu metric alarm"
142+
default = "3"
143+
type = string
144+
}
145+
variable "min_cpu_evaluation_period"{
146+
description = "The number of periods over which data is compared to the specified threshold for min cpu metric alarm"
147+
default = "3"
148+
type = string
149+
}
150+
151+
variable "max_cpu_period"{
152+
description = "The period in seconds over which the specified statistic is applied for max cpu metric alarm"
153+
default = "60"
154+
type = string
155+
}
156+
variable "min_cpu_period"{
157+
description = "The period in seconds over which the specified statistic is applied for min cpu metric alarm"
158+
default = "60"
159+
type = string
160+
}
161+
162+
variable "scale_target_max_capacity" {
163+
description = "The max capacity of the scalable target"
164+
default = 5
165+
type = number
166+
}
167+
168+
variable "scale_target_min_capacity" {
169+
description = "The min capacity of the scalable target"
170+
default = 1
171+
type = number
172+
}
173+
129174
#------------------------------------------------------------------------------
130175
# AWS LOAD BALANCER
131176
#------------------------------------------------------------------------------

0 commit comments

Comments
 (0)