-
Notifications
You must be signed in to change notification settings - Fork 12
/
autoscaling_groups.tf
79 lines (73 loc) · 2.4 KB
/
autoscaling_groups.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Create two autoscaling groups one for spot and the other for spot.
resource "aws_autoscaling_group" "ecs_cluster_ondemand" {
name_prefix = "${var.cluster_name}_asg_ondemand_"
termination_policies = [
"OldestInstance"]
default_cooldown = 30
health_check_grace_period = 30
max_size = var.max_ondmand_instances
min_size = var.min_ondemand_instances
desired_capacity = var.min_ondemand_instances
launch_configuration = aws_launch_configuration.ecs_config_launch_config_ondemand.name
lifecycle {
create_before_destroy = true
}
vpc_zone_identifier = local.public_subnet_ids
tags = [
{
key = "Name"
value = var.cluster_name,
propagate_at_launch = true
}
]
}
resource "aws_autoscaling_group" "ecs_cluster_spot" {
name_prefix = "${var.cluster_name}_asg_spot_"
termination_policies = [
"OldestInstance"]
default_cooldown = 30
health_check_grace_period = 30
max_size = var.max_spot_instances
min_size = var.min_spot_instances
desired_capacity = var.min_spot_instances
launch_configuration = aws_launch_configuration.ecs_config_launch_config_spot.name
# Allow the ASG to be created through Terraform,
# even if the price is too low or there are other
# issues with placing the spot request
wait_for_capacity_timeout = "0"
lifecycle {
create_before_destroy = true
}
vpc_zone_identifier = local.public_subnet_ids
tags = [
{
key = "Name"
value = var.cluster_name,
propagate_at_launch = true
}
]
}
# Attach an autoscaling policy to the spot cluster to target 70% MemoryReservation on the ECS cluster.
resource "aws_autoscaling_policy" "ecs_cluster_scale_policy" {
name = "${var.cluster_name}_ecs_cluster_spot_scale_policy"
policy_type = "TargetTrackingScaling"
adjustment_type = "ChangeInCapacity"
lifecycle {
ignore_changes = [
adjustment_type
]
}
autoscaling_group_name = aws_autoscaling_group.ecs_cluster_spot.name
target_tracking_configuration {
customized_metric_specification {
metric_dimension {
name = "ClusterName"
value = var.cluster_name
}
metric_name = "MemoryReservation"
namespace = "AWS/ECS"
statistic = "Average"
}
target_value = 70.0
}
}