@@ -13,6 +13,10 @@ data "aws_ami_ids" "ami" {
1313 }
1414}
1515
16+ locals {
17+ cluster_name = " rabbitmq-${ var . name } "
18+ }
19+
1620resource "random_string" "admin_password" {
1721 length = 32
1822 special = false
@@ -44,6 +48,7 @@ data "template_file" "cloud-init" {
4448
4549 vars {
4650 sync_node_count = 3
51+ asg_name = " ${ local . cluster_name } "
4752 region = " ${ data . aws_region . current . name } "
4853 admin_password = " ${ random_string . admin_password . result } "
4954 rabbit_password = " ${ random_string . rabbit_password . result } "
@@ -53,12 +58,12 @@ data "template_file" "cloud-init" {
5358}
5459
5560resource "aws_iam_role" "role" {
56- name = " rabbitmq- ${ var . name } "
61+ name = " ${ local . cluster_name } "
5762 assume_role_policy = " ${ data . aws_iam_policy_document . policy_doc . json } "
5863}
5964
6065resource "aws_iam_role_policy" "policy" {
61- name = " rabbitmq- ${ var . name } "
66+ name = " ${ local . cluster_name } "
6267 role = " ${ aws_iam_role . role . id } "
6368
6469 policy = << EOF
8186}
8287
8388resource "aws_iam_instance_profile" "profile" {
84- name_prefix = " rabbitmq- ${ var . name } "
89+ name_prefix = " ${ local . cluster_name } "
8590 role = " ${ aws_iam_role . role . name } "
8691}
8792
@@ -103,7 +108,7 @@ resource "aws_security_group" "rabbitmq_elb" {
103108}
104109
105110resource "aws_security_group" "rabbitmq_nodes" {
106- name = " rabbitmq- ${ var . name } -nodes"
111+ name = " ${ local . cluster_name } -nodes"
107112 vpc_id = " ${ var . vpc_id } "
108113 description = " Security Group for the rabbitmq nodes"
109114
@@ -144,7 +149,7 @@ resource "aws_security_group" "rabbitmq_nodes" {
144149}
145150
146151resource "aws_launch_configuration" "rabbitmq" {
147- name_prefix = " rabbitmq- ${ var . name } - "
152+ name = " ${ local . cluster_name } "
148153 image_id = " ${ data . aws_ami_ids . ami . ids [0 ]} "
149154 instance_type = " ${ var . instance_type } "
150155 key_name = " ${ var . ssh_key_name } "
@@ -165,7 +170,7 @@ resource "aws_launch_configuration" "rabbitmq" {
165170}
166171
167172resource "aws_autoscaling_group" "rabbitmq" {
168- name_prefix = " rabbitmq- ${ var . name } - "
173+ name = " ${ local . cluster_name } "
169174 min_size = " ${ var . min_size } "
170175 desired_capacity = " ${ var . desired_size } "
171176 max_size = " ${ var . max_size } "
@@ -178,13 +183,13 @@ resource "aws_autoscaling_group" "rabbitmq" {
178183
179184 tag {
180185 key = " Name"
181- value = " rabbitmq- ${ var . name } "
186+ value = " ${ local . cluster_name } "
182187 propagate_at_launch = true
183188 }
184189}
185190
186191resource "aws_elb" "elb" {
187- name = " rabbitmq- ${ var . name } -elb"
192+ name = " ${ local . cluster_name } -elb"
188193
189194 listener {
190195 instance_port = 5672
@@ -214,6 +219,6 @@ resource "aws_elb" "elb" {
214219 security_groups = [" ${ aws_security_group . rabbitmq_elb . id } " , " ${ var . elb_additional_security_group_ids } " ]
215220
216221 tags {
217- Name = " rabbitmq- ${ var . name } "
222+ Name = " ${ local . cluster_name } "
218223 }
219224}
0 commit comments