-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathec2_as_group.tf
116 lines (95 loc) · 2.97 KB
/
ec2_as_group.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
data "aws_ami" "amazon_linux_ami" {
owners = ["amazon"]
most_recent = true
filter {
name = "name"
values = ["amzn2-ami-ecs-*-x86_64*"]
}
}
# Private
resource "aws_launch_template" "ecs_launch_config-priv" {
image_id = data.aws_ami.amazon_linux_ami.id
vpc_security_group_ids = [aws_security_group.ecs_sg.id]
instance_type = "t2.medium"
key_name = "andrey_mulin_monitoring_account"
user_data = filebase64("templates/user_data.sh")
update_default_version = true
iam_instance_profile {
name = aws_iam_instance_profile.ecs_agent.name
}
}
resource "aws_autoscaling_group" "prometheus_ecs_asg-priv" {
name = "asg-priv"
vpc_zone_identifier = [aws_subnet.priv-subnet-1.id, aws_subnet.priv-subnet-2.id]
desired_capacity = 2
min_size = 1
max_size = 3
health_check_grace_period = 300
health_check_type = "EC2"
mixed_instances_policy {
instances_distribution {
on_demand_base_capacity = 0
on_demand_percentage_above_base_capacity = 0
spot_allocation_strategy = "capacity-optimized"
}
launch_template {
launch_template_specification {
launch_template_id = aws_launch_template.ecs_launch_config-priv.id
}
override {
instance_type = "t2.medium"
weighted_capacity = "1"
}
override {
instance_type = "t2.small"
weighted_capacity = "2"
}
}
}
lifecycle {
ignore_changes = [desired_capacity]
}
}
# Public aws_launch_configuration
resource "aws_launch_template" "ecs_launch_config-pub" {
image_id = data.aws_ami.amazon_linux_ami.id
network_interfaces {
associate_public_ip_address = true
security_groups = [aws_security_group.ecs_sg.id]
}
instance_type = "t2.medium"
key_name = "andrey_mulin_monitoring_account"
update_default_version = true
}
resource "aws_autoscaling_group" "prometheus_ecs_asg-pub" {
name = "asg-pub"
vpc_zone_identifier = [aws_subnet.pub_subnet-1.id, aws_subnet.pub_subnet-2.id]
desired_capacity = 2
min_size = 1
max_size = 3
health_check_grace_period = 300
health_check_type = "EC2"
mixed_instances_policy {
instances_distribution {
on_demand_base_capacity = 0
on_demand_percentage_above_base_capacity = 0
spot_allocation_strategy = "capacity-optimized"
}
launch_template {
launch_template_specification {
launch_template_id = aws_launch_template.ecs_launch_config-pub.id
}
override {
instance_type = "t2.medium"
weighted_capacity = "1"
}
override {
instance_type = "t2.large"
weighted_capacity = "2"
}
}
}
lifecycle {
ignore_changes = [desired_capacity]
}
}