github.com/sl1pm4t/consul@v1.4.5-0.20190325224627-74c31c540f9c/terraform/openstack/consul.tf (about) 1 provider "openstack" { 2 user_name = "${var.username}" 3 tenant_name = "${var.tenant_name}" 4 password = "${var.password}" 5 auth_url = "${var.auth_url}" 6 } 7 8 resource "openstack_compute_keypair_v2" "consul_keypair" { 9 name = "consul-keypair" 10 region = "${var.region}" 11 public_key = "${var.public_key}" 12 } 13 14 resource "openstack_compute_floatingip_v2" "consul_ip" { 15 region = "${var.region}" 16 pool = "${lookup(var.pub_net_id, var.region)}" 17 count = "${var.servers}" 18 } 19 20 resource "openstack_compute_instance_v2" "consul_node" { 21 name = "consul-node-${count.index}" 22 region = "${var.region}" 23 image_id = "${lookup(var.image, var.region)}" 24 flavor_id = "${lookup(var.flavor, var.region)}" 25 floating_ip = "${element(openstack_compute_floatingip_v2.consul_ip.*.address,count.index)}" 26 key_pair = "consul-keypair" 27 count = "${var.servers}" 28 29 connection { 30 user = "${var.user_login}" 31 key_file = "${var.key_file_path}" 32 timeout = "1m" 33 } 34 35 provisioner "file" { 36 source = "${path.module}/scripts/upstart.conf" 37 destination = "/tmp/upstart.conf" 38 } 39 40 provisioner "file" { 41 source = "${path.module}/scripts/upstart-join.conf" 42 destination = "/tmp/upstart-join.conf" 43 } 44 45 provisioner "remote-exec" { 46 inline = [ 47 "echo ${var.servers} > /tmp/consul-server-count", 48 "echo ${count.index} > /tmp/consul-server-index", 49 "echo ${openstack_compute_instance_v2.consul_node.0.network.0.fixed_ip_v4} > /tmp/consul-server-addr", 50 ] 51 } 52 53 provisioner "remote-exec" { 54 scripts = [ 55 "${path.module}/scripts/install.sh", 56 "${path.module}/scripts/server.sh", 57 "${path.module}/scripts/service.sh", 58 ] 59 } 60 }