11data "aws_vpc" "vpc" {
2- id = " ${ var . vpc_id } "
2+ id = var. vpc_id
33}
44
5- data "aws_region" "current" {}
5+ data "aws_region" "current" {
6+ }
67
78data "aws_ami_ids" "ami" {
89 owners = [" amazon" ]
@@ -44,27 +45,27 @@ data "aws_iam_policy_document" "policy_doc" {
4445}
4546
4647data "template_file" "cloud-init" {
47- template = " ${ file (" ${ path . module } /cloud-init.yaml" )} "
48+ template = file (" ${ path . module } /cloud-init.yaml" )
4849
49- vars {
50+ vars = {
5051 sync_node_count = 3
51- asg_name = " ${ local . cluster_name } "
52- region = " ${ data . aws_region . current . name } "
53- admin_password = " ${ random_string . admin_password . result } "
54- rabbit_password = " ${ random_string . rabbit_password . result } "
55- secret_cookie = " ${ random_string . secret_cookie . result } "
56- message_timeout = " ${ 3 * 24 * 60 * 60 * 1000 } " # 3 days
52+ asg_name = local.cluster_name
53+ region = data.aws_region.current.name
54+ admin_password = random_string.admin_password.result
55+ rabbit_password = random_string.rabbit_password.result
56+ secret_cookie = random_string.secret_cookie.result
57+ message_timeout = 3 * 24 * 60 * 60 * 1000 # 3 days
5758 }
5859}
5960
6061resource "aws_iam_role" "role" {
61- name = " ${ local . cluster_name } "
62- assume_role_policy = " ${ data . aws_iam_policy_document . policy_doc . json } "
62+ name = local. cluster_name
63+ assume_role_policy = data. aws_iam_policy_document . policy_doc . json
6364}
6465
6566resource "aws_iam_role_policy" "policy" {
66- name = " ${ local . cluster_name } "
67- role = " ${ aws_iam_role . role . id } "
67+ name = local. cluster_name
68+ role = aws_iam_role. role . id
6869
6970 policy = << EOF
7071{
@@ -83,16 +84,17 @@ resource "aws_iam_role_policy" "policy" {
8384 ]
8485}
8586EOF
87+
8688}
8789
8890resource "aws_iam_instance_profile" "profile" {
89- name_prefix = " ${ local . cluster_name } "
90- role = " ${ aws_iam_role . role . name } "
91+ name_prefix = local. cluster_name
92+ role = aws_iam_role. role . name
9193}
9294
9395resource "aws_security_group" "rabbitmq_elb" {
9496 name = " rabbitmq_elb-${ var . name } "
95- vpc_id = " ${ var . vpc_id } "
97+ vpc_id = var. vpc_id
9698 description = " Security Group for the rabbitmq elb"
9799
98100 egress {
@@ -102,14 +104,14 @@ resource "aws_security_group" "rabbitmq_elb" {
102104 cidr_blocks = [" 0.0.0.0/0" ]
103105 }
104106
105- tags {
107+ tags = {
106108 Name = " rabbitmq ${ var . name } ELB"
107109 }
108110}
109111
110112resource "aws_security_group" "rabbitmq_nodes" {
111113 name = " ${ local . cluster_name } -nodes"
112- vpc_id = " ${ var . vpc_id } "
114+ vpc_id = var. vpc_id
113115 description = " Security Group for the rabbitmq nodes"
114116
115117 ingress {
@@ -123,14 +125,14 @@ resource "aws_security_group" "rabbitmq_nodes" {
123125 protocol = " tcp"
124126 from_port = 5672
125127 to_port = 5672
126- security_groups = [" ${ aws_security_group . rabbitmq_elb . id } " ]
128+ security_groups = [aws_security_group . rabbitmq_elb . id ]
127129 }
128130
129131 ingress {
130132 protocol = " tcp"
131133 from_port = 15672
132134 to_port = 15672
133- security_groups = [" ${ aws_security_group . rabbitmq_elb . id } " ]
135+ security_groups = [aws_security_group . rabbitmq_elb . id ]
134136 }
135137
136138 egress {
@@ -143,24 +145,24 @@ resource "aws_security_group" "rabbitmq_nodes" {
143145 ]
144146 }
145147
146- tags {
148+ tags = {
147149 Name = " rabbitmq ${ var . name } nodes"
148150 }
149151}
150152
151153resource "aws_launch_configuration" "rabbitmq" {
152- name = " ${ local . cluster_name } "
153- image_id = " ${ data . aws_ami_ids . ami . ids [0 ]} "
154- instance_type = " ${ var . instance_type } "
155- key_name = " ${ var . ssh_key_name } "
156- security_groups = [ " ${ aws_security_group . rabbitmq_nodes . id } " , " ${ var . nodes_additional_security_group_ids } " ]
157- iam_instance_profile = " ${ aws_iam_instance_profile . profile . id } "
158- user_data = " ${ data . template_file . cloud-init . rendered } "
154+ name = local. cluster_name
155+ image_id = data. aws_ami_ids . ami . ids [0 ]
156+ instance_type = var. instance_type
157+ key_name = var. ssh_key_name
158+ security_groups = concat ([ aws_security_group . rabbitmq_nodes . id ], var. nodes_additional_security_group_ids )
159+ iam_instance_profile = aws_iam_instance_profile. profile . id
160+ user_data = data. template_file . cloud-init . rendered
159161
160162 root_block_device {
161- volume_type = " ${ var . instance_volume_type } "
162- volume_size = " ${ var . instance_volume_size } "
163- iops = " ${ var . instance_volume_iops } "
163+ volume_type = var. instance_volume_type
164+ volume_size = var. instance_volume_size
165+ iops = var. instance_volume_iops
164166 delete_on_termination = true
165167 }
166168
@@ -170,20 +172,20 @@ resource "aws_launch_configuration" "rabbitmq" {
170172}
171173
172174resource "aws_autoscaling_group" "rabbitmq" {
173- name = " ${ local . cluster_name } "
174- min_size = " ${ var . min_size } "
175- desired_capacity = " ${ var . desired_size } "
176- max_size = " ${ var . max_size } "
175+ name = local. cluster_name
176+ min_size = var. min_size
177+ desired_capacity = var. desired_size
178+ max_size = var. max_size
177179 health_check_grace_period = 300
178180 health_check_type = " ELB"
179181 force_delete = true
180- launch_configuration = " ${ aws_launch_configuration . rabbitmq . name } "
181- load_balancers = [" ${ aws_elb . elb . name } " ]
182- vpc_zone_identifier = [ " ${ var . subnet_ids } " ]
182+ launch_configuration = aws_launch_configuration. rabbitmq . name
183+ load_balancers = [aws_elb . elb . name ]
184+ vpc_zone_identifier = var. subnet_ids
183185
184186 tag {
185187 key = " Name"
186- value = " ${ local . cluster_name } "
188+ value = local. cluster_name
187189 propagate_at_launch = true
188190 }
189191}
@@ -213,12 +215,12 @@ resource "aws_elb" "elb" {
213215 target = " TCP:5672"
214216 }
215217
216- subnets = [ " ${ var . subnet_ids } " ]
218+ subnets = var. subnet_ids
217219 idle_timeout = 3600
218220 internal = true
219- security_groups = [ " ${ aws_security_group . rabbitmq_elb . id } " , " ${ var . elb_additional_security_group_ids } " ]
221+ security_groups = concat ([ aws_security_group . rabbitmq_elb . id ], var. elb_additional_security_group_ids )
220222
221- tags {
222- Name = " ${ local . cluster_name } "
223+ tags = {
224+ Name = local.cluster_name
223225 }
224226}
0 commit comments