Terraform Remote-exec在VM资源和DHCP配套IP上失败

时间:2019-04-04 14:21:47

标签: terraform vsphere

我正在尝试在vSphere虚拟机资源上运行远程执行配置器,该资源是通过DHCP而不是通过网络适配器上的静态IP设置分配IP的(由于Ubuntu 18.04的TF问题)。

我发现,当尝试运行“ remote-exec”资源调配器时,它失败了,因为它找不到IP地址。我已经尝试了几件事,目前正在尝试将连接对象的“主机”属性设置为“ self.default_ip_address”,希望它使用的IP地址是在连接后通过DHCP自动分配给VM的进入我的网络...不幸的是,我仍然没有运气让它正常工作。

以下是我的资源声明的示例,使用我不知道丢失的DHCP时,有没有更好的方法来运行remote-exec?即使没有运行预配器,在构建完所有东西后,我什至似乎都无法正确输出IP。感谢您的帮助!

resource "vsphere_virtual_machine" "vm-nginx-2" {
  resource_pool_id = "${data.vsphere_resource_pool.pool.id}"
  name             = "vm-nginx-2"
  datastore_id     = "${data.vsphere_datastore.datastore.id}"
  folder           = "${var.vsphere_vm_folder}"

  enable_disk_uuid           = true
  wait_for_guest_net_timeout = 0

  num_cpus  = 2
  memory    = 2048
  guest_id  = "${data.vsphere_virtual_machine.template.guest_id}"
  scsi_type = "${data.vsphere_virtual_machine.template.scsi_type}"

  #scsi_type = "${data.vsphere_virtual_machine.template.scsi_type}"
  network_interface {
    network_id = "${data.vsphere_network.network.id}"
  }

  disk {
    label = "vm-nginx-2-disk"
    size  = "${data.vsphere_virtual_machine.template.disks.0.size}"
  }

  clone {
    template_uuid = "${data.vsphere_virtual_machine.template.id}"

    customize {
      timeout = 0

      linux_options {
        host_name = "vm-nginx-2"
        domain    = "adc-corp.com"
      }

      network_interface {}

      ipv4_gateway = "192.168.0.1"
    }
  }
  provisioner "remote-exec" {
    inline = [
      "sudo apt-get update -y",
      "sudo apt-get install -y nginx"
    ]

    connection {
      host = "${self.default_ip_address}"
      type = "ssh"
      user = "ubuntu"
      private_key = "${file("files/adc-prod.pem")}"
    }
  }  
}



#This also fails to print out an IP
output "vm-nginx-1-ip" {
  value = "${vsphere_virtual_machine.vm-nginx-1.default_ip_address}"
}

0 个答案:

没有答案