-
Notifications
You must be signed in to change notification settings - Fork 0
/
appautoscaling.tf
59 lines (50 loc) · 2.41 KB
/
appautoscaling.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
// CREATE AUTOSCALING TARGET
resource "aws_appautoscaling_target" "appautoscaling_target" {
max_capacity = "${var.appautoscaling_target_max_capacity}"
min_capacity = "${var.appautoscaling_target_min_capacity}"
resource_id = "service/${data.terraform_remote_state.ecs_cluster.ecs_cluster_name}/${aws_ecs_task_definition.ecs_task_definition.family}"
role_arn = "${aws_iam_role.ecs_as_iam_role.arn}"
scalable_dimension = "ecs:service:DesiredCount"
service_namespace = "ecs"
depends_on = [
"aws_ecs_service.ecs_service",
]
}
// CREATE SCALE UP AUTOSCALING POLICY
resource "aws_appautoscaling_policy" "scale_up_appautoscaling_policy" {
name = "${aws_ecs_task_definition.ecs_task_definition.family}-scale-up"
resource_id = "service/${data.terraform_remote_state.ecs_cluster.ecs_cluster_name}/${aws_ecs_task_definition.ecs_task_definition.family}"
scalable_dimension = "ecs:service:DesiredCount"
service_namespace = "ecs"
step_scaling_policy_configuration {
adjustment_type = "ChangeInCapacity"
cooldown = "${var.scale_up_appautoscaling_policy_cooldown}"
metric_aggregation_type = "Maximum"
step_adjustment {
metric_interval_lower_bound = "${var.scale_up_appautoscaling_policy_metric_interval_lower_bound}"
scaling_adjustment = "${var.scale_up_appautoscaling_policy_scaling_adjustment}"
}
}
depends_on = [
"aws_appautoscaling_target.appautoscaling_target",
]
}
// CREATE SCALE DOWN AUTOSCALING POLICY
resource "aws_appautoscaling_policy" "scale_down_appautoscaling_policy" {
name = "${aws_ecs_task_definition.ecs_task_definition.family}-scale-down"
resource_id = "service/${data.terraform_remote_state.ecs_cluster.ecs_cluster_name}/${aws_ecs_task_definition.ecs_task_definition.family}"
scalable_dimension = "ecs:service:DesiredCount"
service_namespace = "ecs"
step_scaling_policy_configuration {
adjustment_type = "ChangeInCapacity"
cooldown = "${var.scale_down_appautoscaling_policy_cooldown}"
metric_aggregation_type = "Maximum"
step_adjustment {
metric_interval_lower_bound = "${var.scale_down_appautoscaling_policy_metric_interval_lower_bound}"
scaling_adjustment = "${var.scale_down_appautoscaling_policy_scaling_adjustment}"
}
}
depends_on = [
"aws_appautoscaling_target.appautoscaling_target",
]
}