Skip to content

Commit

Permalink
add terraform 0.12 support
Browse files Browse the repository at this point in the history
  • Loading branch information
krotkiewicz committed Aug 26, 2019
1 parent 7ee5aee commit 5637726
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 60 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
*.lock.info
.terraform
.idea
test
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ before_script:
- export TF_VAR_region=${AWS_REGION}
- echo "using AWS_REGION=${AWS_REGION}"
- export TF_WARN_OUTPUT_ERRORS=1
- curl --silent --output terraform.zip https://releases.hashicorp.com/terraform/0.11.8/terraform_0.11.8_linux_amd64.zip
- sha256sum terraform.zip | grep "84ccfb8e13b5fce63051294f787885b76a1fedef6bdbecf51c5e586c9e20c9b7"
- curl --silent --output terraform.zip https://releases.hashicorp.com/terraform/0.12.6/terraform_0.12.6_linux_amd64.zip
- sha256sum terraform.zip | grep "6544eb55b3e916affeea0a46fe785329c36de1ba1bdb51ca5239d3567101876f"
- unzip terraform.zip ; rm -f terraform.zip; chmod +x terraform
- mkdir -p ${HOME}/bin ; export PATH=${PATH}:${HOME}/bin; mv terraform ${HOME}/bin/
- terraform -v
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ Copy and paste into your Terraform configuration:
```
module "rabbitmq" {
source = "ulamlabs/rabbitmq/aws"
version = "2.0.1"
vpc_id = "${var.vpc_id}"
ssh_key_name = "${var.ssh_key_name}"
subnet_ids = "${var.subnet_ids}"
elb_additional_security_group_ids = ["var.cluster_security_group_id"]
version = "3.0.0"
vpc_id = var.vpc_id
ssh_key_name = var.ssh_key_name
subnet_ids = var.subnet_ids
elb_additional_security_group_ids = var.cluster_security_group_id
min_size = "3"
max_size = "3"
desired_size = "3"
Expand Down
90 changes: 46 additions & 44 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
data "aws_vpc" "vpc" {
id = "${var.vpc_id}"
id = var.vpc_id
}

data "aws_region" "current" {}
data "aws_region" "current" {
}

data "aws_ami_ids" "ami" {
owners = ["amazon"]
Expand Down Expand Up @@ -44,27 +45,27 @@ data "aws_iam_policy_document" "policy_doc" {
}

data "template_file" "cloud-init" {
template = "${file("${path.module}/cloud-init.yaml")}"
template = file("${path.module}/cloud-init.yaml")

vars {
vars = {
sync_node_count = 3
asg_name = "${local.cluster_name}"
region = "${data.aws_region.current.name}"
admin_password = "${random_string.admin_password.result}"
rabbit_password = "${random_string.rabbit_password.result}"
secret_cookie = "${random_string.secret_cookie.result}"
message_timeout = "${3 * 24 * 60 * 60 * 1000}" # 3 days
asg_name = local.cluster_name
region = data.aws_region.current.name
admin_password = random_string.admin_password.result
rabbit_password = random_string.rabbit_password.result
secret_cookie = random_string.secret_cookie.result
message_timeout = 3 * 24 * 60 * 60 * 1000 # 3 days
}
}

resource "aws_iam_role" "role" {
name = "${local.cluster_name}"
assume_role_policy = "${data.aws_iam_policy_document.policy_doc.json}"
name = local.cluster_name
assume_role_policy = data.aws_iam_policy_document.policy_doc.json
}

resource "aws_iam_role_policy" "policy" {
name = "${local.cluster_name}"
role = "${aws_iam_role.role.id}"
name = local.cluster_name
role = aws_iam_role.role.id

policy = <<EOF
{
Expand All @@ -83,16 +84,17 @@ resource "aws_iam_role_policy" "policy" {
]
}
EOF

}

resource "aws_iam_instance_profile" "profile" {
name_prefix = "${local.cluster_name}"
role = "${aws_iam_role.role.name}"
name_prefix = local.cluster_name
role = aws_iam_role.role.name
}

resource "aws_security_group" "rabbitmq_elb" {
name = "rabbitmq_elb-${var.name}"
vpc_id = "${var.vpc_id}"
vpc_id = var.vpc_id
description = "Security Group for the rabbitmq elb"

egress {
Expand All @@ -102,14 +104,14 @@ resource "aws_security_group" "rabbitmq_elb" {
cidr_blocks = ["0.0.0.0/0"]
}

tags {
tags = {
Name = "rabbitmq ${var.name} ELB"
}
}

resource "aws_security_group" "rabbitmq_nodes" {
name = "${local.cluster_name}-nodes"
vpc_id = "${var.vpc_id}"
vpc_id = var.vpc_id
description = "Security Group for the rabbitmq nodes"

ingress {
Expand All @@ -123,14 +125,14 @@ resource "aws_security_group" "rabbitmq_nodes" {
protocol = "tcp"
from_port = 5672
to_port = 5672
security_groups = ["${aws_security_group.rabbitmq_elb.id}"]
security_groups = [aws_security_group.rabbitmq_elb.id]
}

ingress {
protocol = "tcp"
from_port = 15672
to_port = 15672
security_groups = ["${aws_security_group.rabbitmq_elb.id}"]
security_groups = [aws_security_group.rabbitmq_elb.id]
}

egress {
Expand All @@ -143,24 +145,24 @@ resource "aws_security_group" "rabbitmq_nodes" {
]
}

tags {
tags = {
Name = "rabbitmq ${var.name} nodes"
}
}

resource "aws_launch_configuration" "rabbitmq" {
name = "${local.cluster_name}"
image_id = "${data.aws_ami_ids.ami.ids[0]}"
instance_type = "${var.instance_type}"
key_name = "${var.ssh_key_name}"
security_groups = ["${aws_security_group.rabbitmq_nodes.id}", "${var.nodes_additional_security_group_ids}"]
iam_instance_profile = "${aws_iam_instance_profile.profile.id}"
user_data = "${data.template_file.cloud-init.rendered}"
name = local.cluster_name
image_id = data.aws_ami_ids.ami.ids[0]
instance_type = var.instance_type
key_name = var.ssh_key_name
security_groups = concat([aws_security_group.rabbitmq_nodes.id], var.nodes_additional_security_group_ids)
iam_instance_profile = aws_iam_instance_profile.profile.id
user_data = data.template_file.cloud-init.rendered

root_block_device {
volume_type = "${var.instance_volume_type}"
volume_size = "${var.instance_volume_size}"
iops = "${var.instance_volume_iops}"
volume_type = var.instance_volume_type
volume_size = var.instance_volume_size
iops = var.instance_volume_iops
delete_on_termination = true
}

Expand All @@ -170,20 +172,20 @@ resource "aws_launch_configuration" "rabbitmq" {
}

resource "aws_autoscaling_group" "rabbitmq" {
name = "${local.cluster_name}"
min_size = "${var.min_size}"
desired_capacity = "${var.desired_size}"
max_size = "${var.max_size}"
name = local.cluster_name
min_size = var.min_size
desired_capacity = var.desired_size
max_size = var.max_size
health_check_grace_period = 300
health_check_type = "ELB"
force_delete = true
launch_configuration = "${aws_launch_configuration.rabbitmq.name}"
load_balancers = ["${aws_elb.elb.name}"]
vpc_zone_identifier = ["${var.subnet_ids}"]
launch_configuration = aws_launch_configuration.rabbitmq.name
load_balancers = [aws_elb.elb.name]
vpc_zone_identifier = var.subnet_ids

tag {
key = "Name"
value = "${local.cluster_name}"
value = local.cluster_name
propagate_at_launch = true
}
}
Expand Down Expand Up @@ -213,12 +215,12 @@ resource "aws_elb" "elb" {
target = "TCP:5672"
}

subnets = ["${var.subnet_ids}"]
subnets = var.subnet_ids
idle_timeout = 3600
internal = true
security_groups = ["${aws_security_group.rabbitmq_elb.id}", "${var.elb_additional_security_group_ids}"]
security_groups = concat([aws_security_group.rabbitmq_elb.id], var.elb_additional_security_group_ids)

tags {
Name = "${local.cluster_name}"
tags = {
Name = local.cluster_name
}
}
9 changes: 5 additions & 4 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
output "rabbitmq_elb_dns" {
value = "${aws_elb.elb.dns_name}"
value = aws_elb.elb.dns_name
}

output "admin_password" {
value = "${random_string.admin_password.result}"
value = random_string.admin_password.result
sensitive = true
}

output "rabbit_password" {
value = "${random_string.rabbit_password.result}"
value = random_string.rabbit_password.result
sensitive = true
}

output "secret_cookie" {
value = "${random_string.secret_cookie.result}"
value = random_string.secret_cookie.result
sensitive = true
}

14 changes: 9 additions & 5 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
variable "vpc_id" {}
variable "ssh_key_name" {}
variable "vpc_id" {
}

variable "ssh_key_name" {
}

variable "name" {
default = "main"
Expand All @@ -22,16 +25,16 @@ variable "max_size" {

variable "subnet_ids" {
description = "Subnets for RabbitMQ nodes"
type = "list"
type = list(string)
}

variable "nodes_additional_security_group_ids" {
type = "list"
type = list(string)
default = []
}

variable "elb_additional_security_group_ids" {
type = "list"
type = list(string)
default = []
}

Expand All @@ -50,3 +53,4 @@ variable "instance_volume_size" {
variable "instance_volume_iops" {
default = "0"
}

4 changes: 4 additions & 0 deletions versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

terraform {
required_version = ">= 0.12"
}

0 comments on commit 5637726

Please sign in to comment.