-
Notifications
You must be signed in to change notification settings - Fork 1
/
ec2_instances.tf
115 lines (101 loc) · 3.25 KB
/
ec2_instances.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
resource "aws_security_group" "ec2_host_sg" {
name = "EC2_SG"
description = "Security Group for EC2 hosts on Private Network"
vpc_id = aws_vpc.main.id
# Allow all from Bastion, LoadBalancer and Self
ingress {
from_port = 0
to_port = 0
protocol = "-1"
security_groups = [aws_security_group.bastion_sg.id, aws_security_group.lb_sg.id]
self = true
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_launch_template" "swarm_managers" {
name = "swarm_managers"
image_id = var.rancher_amis[var.aws_region]
instance_type = "t2.micro"
key_name = var.aws_key_name
vpc_security_group_ids = [aws_security_group.ec2_host_sg.id]
# Ensure the managers are not terminated by accident
disable_api_termination = true
# Tags added to the created Instances
tag_specifications {
resource_type = "instance"
tags = {
Name = "Swarm Manager"
}
}
iam_instance_profile {
name = aws_iam_instance_profile.ec2_profile.name
}
block_device_mappings {
device_name = "/dev/sda1"
ebs {
volume_size = 10 # In GB
}
}
# This is used to run on instance initialization
user_data = base64encode(local.swarm_managers_init_user_data)
}
resource "aws_autoscaling_group" "swarm_managers_asg" {
name = "swarm-managers-asg"
max_size = 3
min_size = 1
desired_capacity = 1
health_check_grace_period = 300
force_delete = false
vpc_zone_identifier = [aws_subnet.private_subnet_1.id, aws_subnet.private_subnet_2.id]
target_group_arns = [aws_lb_target_group.ec2_tg.arn]
launch_template {
id = aws_launch_template.swarm_managers.id
version = "$Latest"
}
}
# resource "aws_launch_template" "swarm_workers" {
# name = "swarm_workers"
# image_id = var.rancher_amis[var.aws_region]
# instance_type = "t2.micro"
# key_name = var.aws_key_name
# vpc_security_group_ids = [aws_security_group.ec2_host_sg.id]
# # Ensure the workers are not terminated by accident
# disable_api_termination = true
# # Tags added to the created Instances
# tag_specifications {
# resource_type = "instance"
# tags = {
# Name = "Swarm Worker"
# }
# }
# iam_instance_profile {
# name = aws_iam_instance_profile.ec2_profile.name
# }
# block_device_mappings {
# device_name = "/dev/sda1"
# ebs {
# volume_size = 10 # In GB
# }
# }
# # This is used to run on instance initialization
# user_data = base64encode(local.swarm_workers_user_data)
# }
# resource "aws_autoscaling_group" "swarm_workers_asg" {
# name = "swarm-workers-asg"
# max_size = 3
# min_size = 1
# desired_capacity = 1
# health_check_grace_period = 300
# force_delete = false
# vpc_zone_identifier = [aws_subnet.private_subnet_1.id, aws_subnet.private_subnet_2.id]
# target_group_arns = [aws_lb_target_group.ec2_tg.arn]
# launch_template {
# id = aws_launch_template.swarm_workers.id
# version = "$Latest"
# }
# }