如果之前没有设置密码,terraform 如何通过 ssh 连接到 vsphere 中的虚拟机

如果之前没有设置密码,terraform 如何通过 ssh 连接到 vsphere 中的虚拟机

我正在尝试使用 terrafom 在 Vmware ESXI 上部署 Linux VM,但我不明白文档中他们如何使用给定的用户名和密码在未事先设置此凭据的情况下通过 ssh 连接到计算机。现在我找到了设置 Windows 管理密码的指令

      windows_options {
    computer_name  = "terraform-test"
    workgroup      = "test"
    admin_password = "VMw4re"
  }

但是我没有找到任何类似 Linux 的东西,你可以在下面找到我所谈论的代码。

    provider "vsphere" {
  version = "6.0.7"
  vim_keep_alive = 30
  user           = "root"
  password       = "password"
  vsphere_server = "IP"

  # If you have a self-signed cert
  allow_unverified_ssl = true
}

data "vsphere_datacenter" "dc" {
  name = "Host"
}

data "vsphere_datastore" "datastore" {
  name          = "datastore1"
  datacenter_id = data.vsphere_datacenter.dc.id
}

data "vsphere_network" "network" {
  name          = "VM Network"
  datacenter_id = data.vsphere_datacenter.dc.id
}

resource "vsphere_virtual_machine" "vpn" {
  name             = "vpn"
  datastore_id     = data.vsphere_datastore.datastore.id

  num_cpus = 1
  memory   = 512
  guest_id = "ubuntu32"

  network_interface {
    network_id = data.vsphere_network.network.id
  }

  disk {
    label = "disk0"
    size  = 10
  }
    cdrom {
    datastore_id = "${data.vsphere_datastore.datastore.id}"
    path         = "ISO/ubuntu-16.04.6-server-i386.iso"
  }
   connection {
    user          = "$user" # using a username that wasn't set before ???
    password      = "${var.ssh_password}" # using a password that wasn't set before ???
  }

  provisioner "file" {
    source      = "${path.module}/config.sh"
    destination = "/tmp/config.sh"
  }

  provisioner "remote-exec" {
    inline = [
      "sudo chmod u+x /tmp/terraform_scripts/*.sh",
      "sudo /tmp/terraform_scripts/config.sh"
    ]
  }
}

相关内容