-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.tf
189 lines (153 loc) · 3.5 KB
/
main.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
########## Terraform RabbitMQ Autocluster ##########
resource "aws_autoscaling_group" "rabbitmq-asg" {
vpc_zone_identifier = [
"${split(",", var.subnets["demo"])}",
]
name = "rabbitmq-asg"
max_size = "${var.asg_max}"
min_size = "${var.asg_min}"
desired_capacity = "${var.asg_desired}"
force_delete = true
launch_configuration = "${aws_launch_configuration.rabbitmq-lc.name}"
load_balancers = [
"${aws_elb.rabbitmq-elb.name}",
]
termination_policies = [
"OldestLaunchConfiguration",
]
min_elb_capacity = 3
lifecycle {
create_before_destroy = true
}
tag {
key = "Name"
value = "rabbitmq-asg"
propagate_at_launch = "true"
}
tag {
key = "environment"
value = "demo"
propagate_at_launch = "true"
}
}
# Launch Configuration for the cluster instances
resource "aws_launch_configuration" "rabbitmq-lc" {
name_prefix = "rabbitmq-lc-"
image_id = "${lookup(var.aws_amis, var.aws_region)}"
instance_type = "${var.instance_type}"
iam_instance_profile = "${var.iam_role}"
lifecycle {
create_before_destroy = true
}
root_block_device {
volume_type = "gp2"
volume_size = 30
delete_on_termination = true
}
# Security group
security_groups = [
"${aws_security_group.rabbitmq-sg.id}",
]
user_data = "${file("userdata.sh")}"
key_name = "${var.key_name}"
}
# ELB in front of the cluster
resource "aws_elb" "rabbitmq-elb" {
name = "demo-rabbitmq-elb"
subnets = [
"${split(",", var.subnets["demo"])}",
]
security_groups = [
"${aws_security_group.rabbitmq-elb-sg.id}",
]
idle_timeout = 3600
listener {
instance_port = 1883
instance_protocol = "tcp"
lb_port = 8883
lb_protocol = "ssl"
ssl_certificate_id = "${var.ssl_cert["demo"]}"
}
health_check {
healthy_threshold = 2
unhealthy_threshold = 2
timeout = 3
target = "TCP:1883"
interval = 30
}
}
# Security Group for the cluster instances
resource "aws_security_group" "rabbitmq-sg" {
description = "used for rabbitmq cluster instances"
vpc_id = "${var.vpc_id["demo"]}"
tags {
Name = "rabbitmq-sg"
}
# SSH access to instances
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = [
"10.0.0.0/24",
]
}
# Management Port
ingress {
from_port = 15672
to_port = 15672
protocol = "tcp"
cidr_blocks = [
"10.0.0.0/24",
]
}
ingress {
from_port = 0
to_port = 0
protocol = "-1"
security_groups = [
"${aws_security_group.rabbitmq-elb-sg.id}",
]
}
ingress {
from_port = 0
to_port = 0
protocol = "-1"
self = true
}
# outbound internet access
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = [
"0.0.0.0/0",
]
}
}
# Security Group for the ELB
resource "aws_security_group" "rabbitmq-elb-sg" {
description = "used for rabbitmq-elb"
vpc_id = "${var.vpc_id["demo"]}"
tags {
Name = "rabbitmq-elb-sg"
}
# MQTT SSL access
ingress {
from_port = 8883
to_port = 8883
protocol = "tcp"
cidr_blocks = [
"0.0.0.0/0",
]
}
# outbound internet access
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = [
"0.0.0.0/0",
]
}
}