forked from Hapag-Lloyd/terraform-aws-bastion-host-ssm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautoscaling.tf
132 lines (100 loc) · 3.69 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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
resource "aws_autoscaling_group" "on_demand" {
count = var.instance.enable_spot ? 0 : 1
name_prefix = "${var.resource_names["prefix"]}${var.resource_names["separator"]}"
vpc_zone_identifier = var.subnet_ids
min_size = 1
desired_capacity = var.instance.desired_capacity
max_size = var.instance.desired_capacity
force_delete = false
health_check_type = "EC2"
health_check_grace_period = 120
termination_policies = ["OldestInstance"]
launch_configuration = aws_launch_configuration.this.id
dynamic "tag" {
for_each = local.bastion_runtime_tags
content {
key = tag.key
value = tag.value
propagate_at_launch = true
}
}
lifecycle {
create_before_destroy = true
}
depends_on = [aws_launch_configuration.this]
}
resource "aws_autoscaling_group" "on_spot" {
count = var.instance.enable_spot ? 1 : 0
name = var.resource_names["prefix"]
vpc_zone_identifier = var.subnet_ids
min_size = 1
desired_capacity = var.instance.desired_capacity
max_size = var.instance.desired_capacity
force_delete = false
health_check_type = "EC2"
health_check_grace_period = 120
termination_policies = ["OldestInstance"]
mixed_instances_policy {
instances_distribution {
on_demand_percentage_above_base_capacity = 0
on_demand_base_capacity = 0
}
launch_template {
launch_template_specification {
launch_template_id = aws_launch_template.manual_start.id
version = "$Latest"
}
}
}
dynamic "tag" {
for_each = local.bastion_runtime_tags
content {
key = tag.key
value = tag.value
propagate_at_launch = true
}
}
lifecycle {
create_before_destroy = true
}
}
resource "aws_autoscaling_schedule" "on_demand_up" {
count = var.schedule != null && !var.instance.enable_spot ? 1 : 0
scheduled_action_name = "${local.resource_prefix_with_separator}start"
recurrence = var.schedule["start"]
time_zone = var.schedule["time_zone"]
min_size = 1
max_size = var.instance.desired_capacity
desired_capacity = var.instance.desired_capacity
autoscaling_group_name = aws_autoscaling_group.on_demand[0].name
}
resource "aws_autoscaling_schedule" "on_demand_down" {
count = var.schedule != null && !var.instance.enable_spot ? 1 : 0
scheduled_action_name = "${local.resource_prefix_with_separator}stop"
recurrence = var.schedule["stop"]
time_zone = var.schedule["time_zone"]
min_size = 0
max_size = 0
desired_capacity = 0
autoscaling_group_name = aws_autoscaling_group.on_demand[0].name
}
resource "aws_autoscaling_schedule" "on_spot_up" {
count = var.schedule != null && var.instance.enable_spot ? 1 : 0
scheduled_action_name = "${local.resource_prefix_with_separator}start"
recurrence = var.schedule["start"]
time_zone = var.schedule["time_zone"]
min_size = 1
max_size = var.instance.desired_capacity
desired_capacity = var.instance.desired_capacity
autoscaling_group_name = aws_autoscaling_group.on_spot[0].name
}
resource "aws_autoscaling_schedule" "on_spot_down" {
count = var.schedule != null && var.instance.enable_spot ? 1 : 0
scheduled_action_name = "${local.resource_prefix_with_separator}stop"
recurrence = var.schedule["stop"]
time_zone = var.schedule["time_zone"]
min_size = 0
max_size = 0
desired_capacity = 0
autoscaling_group_name = aws_autoscaling_group.on_spot[0].name
}