terraformterraform-provider-vsphere

Terraform provision 2 resources in parallel while using variables from each other


I am fairly new to terraform and hoping to get some input.

Terraform 0.14.5

vsphere provider v1.24.1

Trying to provision 2 VMs in parallel.

First I was trying to just use a local-exec provisioner and 'sed' to give the the master resource's IP address to a config file for the minion resource to use. The problem was that the file was not getting edited in time for the minion resource to get the updated version of the file. So I found this: https://discuss.hashicorp.com/t/edit-files-using-local-exec-and-use-them-for-configuration/1616

I have now configured terraform to update the file like so:

Lets say minion.tmplt content is The master ip is ${master_ip}

locals {
  template_file_init = templatefile("${path.module}/minion.tmplt", {master_ip = vsphere_virtual_machine.master_vm[0].default_ip_address})
}

And in the minion resource:

  provisioner "file" {
    content     =  local.template_file_init
    source      = "minion.cfg"
    destination = "/etc/minion.cfg"
    on_failure = fail
  }

And now it works, the minion connects to the master but terraform refuses to deploy them in parallel, and update and provision the file as soon as the master gets an IP address. It provisions the whole master resource first then starts on the minion resource, resulting in 20 minute provision time instead of 10 if it were to do them in parallel. Can anybody help?


Solution

  • If the minion at all uses the "default_ip_address" value of the master, it will wait for the master to get provisioned. Maybe it's updated in the most recent version of terraform, but ideally it would still provision the node and then run the templatefile once the ip is available.