generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathautoscaling.tf
44 lines (36 loc) · 1.66 KB
/
autoscaling.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
resource "aws_appautoscaling_target" "this" {
for_each = var.enable_autoscaling ? aws_ecs_service.this : {}
max_capacity = local.service_data[each.key].max_capacity
min_capacity = local.service_data[each.key].min_capacity
resource_id = "service/${aws_ecs_cluster.dibbs_app_cluster.name}/${each.key}"
scalable_dimension = "ecs:service:DesiredCount"
service_namespace = "ecs"
}
resource "aws_appautoscaling_policy" "memory" {
for_each = var.enable_autoscaling ? aws_ecs_service.this : {}
name = "${each.key}_memory"
policy_type = "TargetTrackingScaling"
resource_id = aws_appautoscaling_target.this[each.key].resource_id
scalable_dimension = aws_appautoscaling_target.this[each.key].scalable_dimension
service_namespace = aws_appautoscaling_target.this[each.key].service_namespace
target_tracking_scaling_policy_configuration {
predefined_metric_specification {
predefined_metric_type = "ECSServiceAverageMemoryUtilization"
}
target_value = 80
}
}
resource "aws_appautoscaling_policy" "cpu" {
for_each = var.enable_autoscaling ? aws_ecs_service.this : {}
name = "${each.key}_cpu"
policy_type = "TargetTrackingScaling"
resource_id = aws_appautoscaling_target.this[each.key].resource_id
scalable_dimension = aws_appautoscaling_target.this[each.key].scalable_dimension
service_namespace = aws_appautoscaling_target.this[each.key].service_namespace
target_tracking_scaling_policy_configuration {
predefined_metric_specification {
predefined_metric_type = "ECSServiceAverageCPUUtilization"
}
target_value = 50
}
}