-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
99 lines (79 loc) · 3.66 KB
/
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
data "openstack_networking_network_v2" "rabbitmq_cluster_network" {
count = "${var.enable_rabbitmq}"
name = "${var.rabbitmq_cluster_network}"
}
data "openstack_networking_subnet_v2" "rabbitmq_cluster_subnet" {
count = "${var.enable_rabbitmq}"
name = "${var.rabbitmq_cluster_subnet}"
}
resource "random_string" "random_erlang_cookie" {
length = 48
special = false
}
resource "random_string" "random_default_username" {
length = 8
special = false
}
resource "random_string" "random_default_password" {
length = 32
special = false
}
locals {
rabbitmq_cluster_computed_erlang_cookie = "${var.rabbitmq_cluster_erlang_cookie != "" ? var.rabbitmq_cluster_erlang_cookie : random_string.random_erlang_cookie.result}"
}
data "http" "generic_user_data_template" {
url = "${var.generic_user_data_file_url}"
}
data "template_file" "rabbitmq_node_user_data" {
count = "${var.rabbitmq_nodes_count}"
template = "${data.http.generic_user_data_template.body}"
vars = {
consul_agent_mode = "client"
consul_cluster_domain = "${var.project_consul_domain}"
consul_cluster_datacenter = "${var.project_consul_datacenter}"
consul_cluster_name = "${var.project_name}-consul"
os_auth_domain_name = "${var.os_auth_domain_name}"
os_auth_username = "${var.os_auth_username}"
os_auth_password = "${var.os_auth_password}"
os_auth_url = "${var.os_auth_url}"
os_project_id = "${var.os_project_id}"
pre_configure_script = ""
custom_write_files_block = "${lookup(data.template_file.rabbitmq_node_custom_user_data[count.index], "rendered")}"
post_configure_script = <<-EOT
systemctl enable rabbitmq-server
systemctl start rabbitmq-server
EOT
}
}
data "template_file" "rabbitmq_node_custom_user_data" {
count = "${var.rabbitmq_nodes_count}"
template = "${file("${path.module}/templates/node-user-data.tpl")}"
vars = {
project_name = "${var.project_name}"
rabbitmq_cluster_name = "${var.rabbitmq_cluster_name}"
rabbitmq_cluster_default_username = "${random_string.random_default_username.result}"
rabbitmq_cluster_default_password = "${random_string.random_default_password.result}"
rabbitmq_cluster_default_vhost = "${var.rabbitmq_cluster_name}"
rabbitmq_cluster_erlang_cookie = "${local.rabbitmq_cluster_computed_erlang_cookie}"
rabbitmq_plugin_list = "${var.rabbitmq_plugin_list}"
}
}
module "rabbitmq_node_instance" {
source = "github.com/dinivas/terraform-openstack-instance"
instance_name = "${var.rabbitmq_cluster_name}"
instance_count = "${var.rabbitmq_nodes_count}"
image_name = "${var.rabbitmq_cluster_image_name}"
flavor_name = "${var.rabbitmq_cluster_compute_flavor_name}"
keypair = "${var.rabbitmq_cluster_keypair_name}"
network_ids = ["${data.openstack_networking_network_v2.rabbitmq_cluster_network.0.id}"]
subnet_ids = ["${data.openstack_networking_subnet_v2.rabbitmq_cluster_subnet.*.id}"]
instance_security_group_name = "${var.rabbitmq_cluster_name}-sg"
instance_security_group_rules = "${var.rabbitmq_cluster_security_group_rules}"
security_groups_to_associate = "${var.rabbitmq_cluster_security_groups_to_associate}"
user_data = "${data.template_file.rabbitmq_node_user_data.0.rendered}"
metadata = "${merge(var.rabbitmq_cluster_metadata, map("consul_cluster_name", format("%s-%s", var.project_name, "consul")), map("project", var.project_name))}"
enabled = "${var.enable_rabbitmq}"
availability_zone = "${var.rabbitmq_cluster_availability_zone}"
execute_on_destroy_instance_script = "${var.execute_on_destroy_rabbitmq_node_script}"
ssh_via_bastion_config = "${var.ssh_via_bastion_config}"
}