Skip to content

Commit 5637726

Browse files
committed
add terraform 0.12 support
1 parent 7ee5aee commit 5637726

File tree

7 files changed

+72
-60
lines changed

7 files changed

+72
-60
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
*.lock.info
55
.terraform
66
.idea
7+
test

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ before_script:
1717
- export TF_VAR_region=${AWS_REGION}
1818
- echo "using AWS_REGION=${AWS_REGION}"
1919
- export TF_WARN_OUTPUT_ERRORS=1
20-
- curl --silent --output terraform.zip https://releases.hashicorp.com/terraform/0.11.8/terraform_0.11.8_linux_amd64.zip
21-
- sha256sum terraform.zip | grep "84ccfb8e13b5fce63051294f787885b76a1fedef6bdbecf51c5e586c9e20c9b7"
20+
- curl --silent --output terraform.zip https://releases.hashicorp.com/terraform/0.12.6/terraform_0.12.6_linux_amd64.zip
21+
- sha256sum terraform.zip | grep "6544eb55b3e916affeea0a46fe785329c36de1ba1bdb51ca5239d3567101876f"
2222
- unzip terraform.zip ; rm -f terraform.zip; chmod +x terraform
2323
- mkdir -p ${HOME}/bin ; export PATH=${PATH}:${HOME}/bin; mv terraform ${HOME}/bin/
2424
- terraform -v

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ Copy and paste into your Terraform configuration:
2525
```
2626
module "rabbitmq" {
2727
source = "ulamlabs/rabbitmq/aws"
28-
version = "2.0.1"
29-
vpc_id = "${var.vpc_id}"
30-
ssh_key_name = "${var.ssh_key_name}"
31-
subnet_ids = "${var.subnet_ids}"
32-
elb_additional_security_group_ids = ["var.cluster_security_group_id"]
28+
version = "3.0.0"
29+
vpc_id = var.vpc_id
30+
ssh_key_name = var.ssh_key_name
31+
subnet_ids = var.subnet_ids
32+
elb_additional_security_group_ids = var.cluster_security_group_id
3333
min_size = "3"
3434
max_size = "3"
3535
desired_size = "3"

main.tf

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
data "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

78
data "aws_ami_ids" "ami" {
89
owners = ["amazon"]
@@ -44,27 +45,27 @@ data "aws_iam_policy_document" "policy_doc" {
4445
}
4546

4647
data "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

6061
resource "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

6566
resource "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
}
8586
EOF
87+
8688
}
8789

8890
resource "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

9395
resource "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

110112
resource "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

151153
resource "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

172174
resource "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
}

outputs.tf

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
output "rabbitmq_elb_dns" {
2-
value = "${aws_elb.elb.dns_name}"
2+
value = aws_elb.elb.dns_name
33
}
44

55
output "admin_password" {
6-
value = "${random_string.admin_password.result}"
6+
value = random_string.admin_password.result
77
sensitive = true
88
}
99

1010
output "rabbit_password" {
11-
value = "${random_string.rabbit_password.result}"
11+
value = random_string.rabbit_password.result
1212
sensitive = true
1313
}
1414

1515
output "secret_cookie" {
16-
value = "${random_string.secret_cookie.result}"
16+
value = random_string.secret_cookie.result
1717
sensitive = true
1818
}
19+

variables.tf

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
variable "vpc_id" {}
2-
variable "ssh_key_name" {}
1+
variable "vpc_id" {
2+
}
3+
4+
variable "ssh_key_name" {
5+
}
36

47
variable "name" {
58
default = "main"
@@ -22,16 +25,16 @@ variable "max_size" {
2225

2326
variable "subnet_ids" {
2427
description = "Subnets for RabbitMQ nodes"
25-
type = "list"
28+
type = list(string)
2629
}
2730

2831
variable "nodes_additional_security_group_ids" {
29-
type = "list"
32+
type = list(string)
3033
default = []
3134
}
3235

3336
variable "elb_additional_security_group_ids" {
34-
type = "list"
37+
type = list(string)
3538
default = []
3639
}
3740

@@ -50,3 +53,4 @@ variable "instance_volume_size" {
5053
variable "instance_volume_iops" {
5154
default = "0"
5255
}
56+

versions.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
terraform {
3+
required_version = ">= 0.12"
4+
}

0 commit comments

Comments
 (0)