-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
main.tf
64 lines (54 loc) · 1.92 KB
/
main.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
module "scale_up_label" {
source = "cloudposse/label/null"
version = "0.25.0"
attributes = ["up"]
context = module.this.context
}
module "scale_down_label" {
source = "cloudposse/label/null"
version = "0.25.0"
attributes = ["down"]
context = module.this.context
}
resource "aws_appautoscaling_target" "default" {
count = module.this.enabled ? 1 : 0
service_namespace = "ecs"
resource_id = "service/${var.cluster_name}/${var.service_name}"
scalable_dimension = "ecs:service:DesiredCount"
min_capacity = var.min_capacity
max_capacity = var.max_capacity
}
resource "aws_appautoscaling_policy" "up" {
count = module.this.enabled ? 1 : 0
name = module.scale_up_label.id
service_namespace = "ecs"
resource_id = "service/${var.cluster_name}/${var.service_name}"
scalable_dimension = "ecs:service:DesiredCount"
step_scaling_policy_configuration {
adjustment_type = "ChangeInCapacity"
cooldown = var.scale_up_cooldown
metric_aggregation_type = "Average"
step_adjustment {
metric_interval_lower_bound = 0
scaling_adjustment = var.scale_up_adjustment
}
}
depends_on = [aws_appautoscaling_target.default]
}
resource "aws_appautoscaling_policy" "down" {
count = module.this.enabled ? 1 : 0
name = module.scale_down_label.id
service_namespace = "ecs"
resource_id = "service/${var.cluster_name}/${var.service_name}"
scalable_dimension = "ecs:service:DesiredCount"
step_scaling_policy_configuration {
adjustment_type = "ChangeInCapacity"
cooldown = var.scale_down_cooldown
metric_aggregation_type = "Average"
step_adjustment {
metric_interval_upper_bound = 0
scaling_adjustment = var.scale_down_adjustment
}
}
depends_on = [aws_appautoscaling_target.default]
}