-
Notifications
You must be signed in to change notification settings - Fork 1
/
rabbitmq.cluster-main.tf
211 lines (180 loc) · 7.65 KB
/
rabbitmq.cluster-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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
### ---> #################### <--- ### || < ####### > || ###
### ---> -------------------- <--- ### || < ------- > || ###
### ---> Service Layer Module <--- ### || < Layer S > || ###
### ---> -------------------- <--- ### || < ------- > || ###
### ---> #################### <--- ### || < ####### > || ###
module rabbitmq-cloud-config
{
source = "github.com/devops4me/rabbitmq-fluentd-es-cloud-config"
########### source = "github.com/devops4me/rabbitmq-systemd-cloud-config"
in_node_count = "${ var.in_initial_node_count }"
in_elasticsearch_url = "elasticsearch-901302010-557078750.eu-west-2.elb.amazonaws.com"
in_s3_logs_bucket_name = "ecosystem.up.bucket"
in_s3_bucket_region = "eu-central-1"
}
### ---> ##################### <--- ### || < ####### > || ###
### ---> --------------------- <--- ### || < ------- > || ###
### ---> Instance Layer Module <--- ### || < Layer I > || ###
### ---> --------------------- <--- ### || < ------- > || ###
### ---> ##################### <--- ### || < ####### > || ###
module ec2-instance-cluster
{
source = "github.com/devops4me/terraform-aws-ec2-instance-cluster"
in_node_count = "${ var.in_initial_node_count }"
in_subnet_ids = "${ module.vpc-network.out_private_subnet_ids }"
in_security_group_ids = [ "${ module.security-group.out_security_group_id }" ]
in_ami_id = "${ module.coreos-ami-id.out_ami_id }"
in_user_data = "${ module.rabbitmq-cloud-config.out_ignition_config }"
in_ssh_public_key = "${ tls_private_key.generated.public_key_openssh }"
in_route_dependency = "${ module.vpc-network.out_outgoing_routes }"
in_ecosystem_name = "${ var.in_ecosystem_name }"
in_tag_timestamp = "${ module.resource-tags.out_tag_timestamp }"
in_tag_description = "${ module.resource-tags.out_tag_description }"
}
/*
| -- This generated private key will be ejected into the state file.
| -- For long lived scenarios a better strategy is to pass in public
| -- keys that have their private counterpart secured.
| --
*/
resource tls_private_key generated
{
algorithm = "RSA"
rsa_bits = 4096
}
### ---> ##################### <--- ### || < ####### > || ###
### ---> --------------------- <--- ### || < ------- > || ###
### ---> Network Layer Modules <--- ### || < Layer N > || ###
### ---> --------------------- <--- ### || < ------- > || ###
### ---> ##################### <--- ### || < ####### > || ###
/*
| --
| -- This module creates a VPC and then allocates subnets in a round robin manner
| -- to each availability zone. For example if 8 subnets are required in a region
| -- that has 3 availability zones - 2 zones will hold 3 subnets and the 3rd two.
| --
| -- Whenever and wherever public subnets are specified, this module knows to create
| -- an internet gateway and a route out to the net.
| --
*/
module vpc-network
{
source = "github.com/devops4me/terraform-aws-vpc-network"
in_vpc_cidr = "10.66.0.0/16"
in_num_public_subnets = 6
in_num_private_subnets = 6
in_ecosystem_name = "${ var.in_ecosystem_name }"
in_tag_timestamp = "${ module.resource-tags.out_tag_timestamp }"
in_tag_description = "${ module.resource-tags.out_tag_description }"
}
/*
| --
| -- For human beings this application load balancer maps http
| -- requests to RabbitMQ's management interface on port 15672.
| --
| -- http://<http-load-balancer-dns-name>/#/
| --
| -- The url brings up the RabbitMQ login page which responds
| -- to the username "devops4me" and the passowrd that terraform
| -- provides via the "out_rmq_password" output variable.
| --
| -- This load balancer terminates SSL (in the production branch)
| -- with a provided SSL certificate ID from the AWS Cert Manager.
| --
| -- This layer 7 load balancer is slower than its layer 4 cousin
| -- which is fine as it only services human sys admins.
| --
module http-load-balancer
{
source = "github.com/devops4me/terraform-aws-load-balancer"
in_vpc_id = "${ module.vpc-network.out_vpc_id }"
in_subnet_ids = "${ module.vpc-network.out_private_subnet_ids }"
in_security_group_ids = [ "${ module.security-group.out_security_group_id }" ]
in_ip_addresses = "${ module.ec2-instance-cluster.out_private_ip_addresses }"
in_ip_address_count = "${ var.in_initial_node_count }"
in_lb_class = "application"
in_is_internal = false
in_front_end = [ "http" ]
in_back_end = [ "rabbitmq" ]
in_ecosystem_name = "${ var.in_ecosystem_name }"
in_tag_timestamp = "${ module.resource-tags.out_tag_timestamp }"
in_tag_description = "${ module.resource-tags.out_tag_description }"
}
*/
/*
| --
| -- For machines this (layer 4) network load balancer farms
| -- out TCP traffic using the AMQP protocol on port 5672.
| --
| -- amqp://<username>:<password>@<lb-dns-name>:5672/%2F
| --
| -- The default username is "devops4me" and the password via
| -- "out_rmq_password" is auto provisioned by terraform.
| --
| -- This high performance load balancer does not open packets
| -- so refuses to accept security groups in its configuration.
| --
module amqp-load-balancer
{
source = "github.com/devops4me/terraform-aws-load-balancer"
in_vpc_id = "${ module.vpc-network.out_vpc_id }"
in_subnet_ids = "${ module.vpc-network.out_private_subnet_ids }"
in_security_group_ids = []
in_ip_addresses = "${ module.ec2-instance-cluster.out_private_ip_addresses }"
in_ip_address_count = "${ var.in_initial_node_count }"
in_lb_class = "network"
in_is_internal = false
in_front_end = [ "amqp" ]
in_back_end = [ "amqp" ]
in_ecosystem_name = "${ var.in_ecosystem_name }"
in_tag_timestamp = "${ module.resource-tags.out_tag_timestamp }"
in_tag_description = "${ module.resource-tags.out_tag_description }"
}
*/
/*
| --
| -- I have used network flow logs in conjunction with the RabbitMQ
| -- bench test tool (perf-test) to pinpoint the exact set of security
| -- group rules that are neither overly permissive nor restrictive.
| --
| -- https://www.rabbitmq.com/clustering.html
| --
| -- The above URL makes the case for the ports required for RabbitMQ
| -- to cluster correctly.
| --
*/
module security-group
{
source = "github.com/devops4me/terraform-aws-security-group"
in_ingress = [ "ssh", "https", "rmq-admin", "rmq-tls", "amqp", "amqp-tls", "http", "etcd-client", "etcd-server", "epmd", "rmq-comms" ]
in_vpc_id = "${ module.vpc-network.out_vpc_id }"
in_ecosystem_name = "${ var.in_ecosystem_name }"
in_tag_timestamp = "${ module.resource-tags.out_tag_timestamp }"
in_tag_description = "${ module.resource-tags.out_tag_description }"
}
/*
| --
| -- Remember the AWS resource tags! Using this module, every
| -- infrastructure component is tagged to tell you 5 things.
| --
| -- a) who (which IAM user) created the component
| -- b) which eco-system instance is this component a part of
| -- c) when (timestamp) was this component created
| -- d) where (in which AWS region) was this component created
| -- e) which eco-system class is this component a part of
| --
*/
module resource-tags
{
source = "github.com/devops4me/terraform-aws-resource-tags"
}
/*
| --
| -- This module dynamically acquires the HVM CoreOS AMI ID for the region that
| -- this infrastructure is built in (specified by the AWS credentials in play).
| --
*/
module coreos-ami-id
{
source = "github.com/devops4me/terraform-aws-coreos-ami-id"
}