2015-04-07 10:49:28 +00:00
|
|
|
provider "openstack" {
|
2018-10-24 15:02:38 +00:00
|
|
|
user_name = "${var.username}"
|
|
|
|
tenant_name = "${var.tenant_name}"
|
|
|
|
password = "${var.password}"
|
|
|
|
auth_url = "${var.auth_url}"
|
2015-04-07 10:49:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_compute_keypair_v2" "consul_keypair" {
|
2018-10-24 15:02:38 +00:00
|
|
|
name = "consul-keypair"
|
|
|
|
region = "${var.region}"
|
2015-04-07 10:49:28 +00:00
|
|
|
public_key = "${var.public_key}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_compute_floatingip_v2" "consul_ip" {
|
|
|
|
region = "${var.region}"
|
2018-10-24 15:02:38 +00:00
|
|
|
pool = "${lookup(var.pub_net_id, var.region)}"
|
|
|
|
count = "${var.servers}"
|
2015-04-07 10:49:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_compute_instance_v2" "consul_node" {
|
2018-10-24 15:02:38 +00:00
|
|
|
name = "consul-node-${count.index}"
|
|
|
|
region = "${var.region}"
|
|
|
|
image_id = "${lookup(var.image, var.region)}"
|
|
|
|
flavor_id = "${lookup(var.flavor, var.region)}"
|
2015-04-07 10:49:28 +00:00
|
|
|
floating_ip = "${element(openstack_compute_floatingip_v2.consul_ip.*.address,count.index)}"
|
2018-10-24 15:02:38 +00:00
|
|
|
key_pair = "consul-keypair"
|
|
|
|
count = "${var.servers}"
|
|
|
|
|
|
|
|
connection {
|
|
|
|
user = "${var.user_login}"
|
|
|
|
key_file = "${var.key_file_path}"
|
|
|
|
timeout = "1m"
|
|
|
|
}
|
|
|
|
|
|
|
|
provisioner "file" {
|
|
|
|
source = "${path.module}/scripts/upstart.conf"
|
|
|
|
destination = "/tmp/upstart.conf"
|
|
|
|
}
|
|
|
|
|
|
|
|
provisioner "file" {
|
|
|
|
source = "${path.module}/scripts/upstart-join.conf"
|
|
|
|
destination = "/tmp/upstart-join.conf"
|
|
|
|
}
|
|
|
|
|
|
|
|
provisioner "remote-exec" {
|
|
|
|
inline = [
|
|
|
|
"echo ${var.servers} > /tmp/consul-server-count",
|
|
|
|
"echo ${count.index} > /tmp/consul-server-index",
|
|
|
|
"echo ${openstack_compute_instance_v2.consul_node.0.network.0.fixed_ip_v4} > /tmp/consul-server-addr",
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
provisioner "remote-exec" {
|
|
|
|
scripts = [
|
|
|
|
"${path.module}/scripts/install.sh",
|
|
|
|
"${path.module}/scripts/server.sh",
|
|
|
|
"${path.module}/scripts/service.sh",
|
|
|
|
]
|
|
|
|
}
|
2015-04-07 10:49:28 +00:00
|
|
|
}
|