<% variables.each do |variable| -%>
variable "<%= variable %>" {}
<% end -%>

provider "openstack" {
  user_name  = "${var.os_user_name}"
  tenant_name = "${var.os_tenant_name}"
  password  = "${var.os_password}"
  auth_url  = "${var.os_auth_url}"
}

<% modules.each do |m| %>
module "<%= m.name %>" {
  source = "<%= m.source %>"
  <%- m.variables.each do |key, value| -%>
  <%= key %> = "<%= value %>"
  <%- end -%>
}
<% end %>

resource "null_resource" "consul_bootstrap" {
  count = "${var.bootstrap_expect}"
  triggers {
    cluster_addresses = "${join(", ", <%= collect_outputs('cluster_addresses') %>)}"
  }
  provisioner "remote-exec" {
    inline = [
      "sudo su -c \"sed -i -e '/BOOTSTRAP_EXPECT/d' /opt/cloudconductor/config\"",
      "sudo su -c \"/bin/echo BOOTSTRAP_EXPECT=${var.bootstrap_expect} >> /opt/cloudconductor/config\"",
      "sudo service consul restart"
      ]
    connection {
      user = "ec2-user"
      key_file = "${var.ssh_key_file}"
      host = "${element(<%= collect_outputs('cluster_addresses') %>, count.index)}"
      bastion_user = "ec2-user"
      bastion_key_file = "${var.ssh_key_file}"
      bastion_host = "${element(<%= collect_outputs('frontend_addresses') %>, 0)}"
    }
  }
}

resource "null_resource" "consul_join" {
  depends_on = ["null_resource.consul_bootstrap"]
  count = "${var.bootstrap_expect}"
  triggers {
    cluster_addresses = "${join(", ", <%= collect_outputs('cluster_addresses') %>)}"
  }
  provisioner "remote-exec" {
    inline = [
      "for i in `seq 10 `; do",
      "  sleep 3",
      "  consul join ${element(<%= collect_outputs('cluster_addresses') %>, count.index)}",
      "  if [ $? -ne 0 ]; then",
      "    continue 1",
      "  fi",
      "  exit 0",
      "done",
      "exit 1"
    ]
    connection {
      user = "ec2-user"
      key_file = "${var.ssh_key_file}"
      host = "${element(<%= collect_outputs('frontend_addresses') %>, 0)}"
    }
  }
}

<% modules.each do |m| -%>
<% m.outputs.each do |key| -%>
output "<%= m.name %>.<%= key %>" {
  value = "${module.<%= m.name %>.<%= key %>}"
}
<% end %>
<% end %>

Add terraform template for openstack
Add terraform template for openstack
