1

I am trying to deploy a linux VM on Vmware ESXI using terrafom but I don't understand how in the documentation they use a given username and password to ssh to a machine without having set this credentials beforehand. Now I found the directives to set the administrative password for windows

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

But I didn't find anything similar for linux, you can find below the code that I'm talking about.

    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"
    ]
  }
}
  • 1
    It seems like your using a CDROM image to run an installer from. Most people deploy new VM's from a template/image. That template often contains a default user/password combination. Often the image will contain cloud-init and when deploying a new VM the cloud-init code will trigger customization of the image, be it deploying a SSH key to a default user account, setting a password or much more. – Bob Nov 25 '20 at 16:24
  • Understandable, thanks for the answer. – Non Fungible Person Nov 26 '20 at 09:37

0 Answers0