Create VM on vSphere with Terraform

By | 01/12/2019

Introduction

In this post and this post, we created respectively some EC2 instances on AWS and some network contructs on Cisco’s ACI solution.

We will apply the same principle but instead of creating some servers on AWS, we will create some servers on vSphere.

Terraform code

We will create a main.tf file which contains the entire configuration. It’s quite a lengthy file but it’s not really complicated to be honest.

First, we retrieve all values from our existing vSphere setup. Reason for doing this is that we will use them somewhat later in the file. For the server creation, we are essentially cloning a template, in my case a Ubuntu 16.04 server template which was created already before. We will also assign a static IP address (and DNS, domain…) to the servers.

provider "vsphere" {
  user                 = var.vsphere_user
  password             = var.vsphere_password
  vsphere_server       = var.vsphere_server
  allow_unverified_ssl = true
}

data "vsphere_datacenter" "dc" {
  name = var.vsphere_datacenter
}

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

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

data "vsphere_datastore" "ds" {
  name          = var.vsphere_datastore
  datacenter_id = data.vsphere_datacenter.dc.id
}

data "vsphere_compute_cluster" "cl" {
  name          = var.vsphere_compute_cluster
  datacenter_id = data.vsphere_datacenter.dc.id
}

data "vsphere_virtual_machine" "template" {
  name          = var.vsphere_template
  datacenter_id = data.vsphere_datacenter.dc.id
}

resource "vsphere_virtual_machine" "aci_vm1" {
  count            = 1
  name             = var.aci_vm1_name
  resource_pool_id = data.vsphere_compute_cluster.cl.resource_pool_id
  datastore_id     = data.vsphere_datastore.ds.id

  num_cpus  = 2
  memory    = 4096
  guest_id  = data.vsphere_virtual_machine.template.guest_id
  scsi_type = data.vsphere_virtual_machine.template.scsi_type

  disk {
    label            = "disk0"
    size             = data.vsphere_virtual_machine.template.disks[0].size
    thin_provisioned = data.vsphere_virtual_machine.template.disks[0].thin_provisioned
  }

  folder = var.folder

  network_interface {
    network_id   = data.vsphere_network.vm1_net.id
    adapter_type = data.vsphere_virtual_machine.template.network_interface_types[0]
  }

  clone {
    linked_clone  = "false"
    template_uuid = data.vsphere_virtual_machine.template.id

    customize {
      linux_options {
        host_name = var.aci_vm1_name
        domain    = var.domain_name
      }

      network_interface {
        ipv4_address = var.aci_vm1_address
        ipv4_netmask = "24"
      }

      ipv4_gateway    = var.gateway
      dns_server_list = [var.dns_list]
      dns_suffix_list = [var.dns_search]
    }
  }
}

resource "vsphere_virtual_machine" "aci_vm2" {
  count            = 1
  name             = var.aci_vm2_name
  resource_pool_id = data.vsphere_compute_cluster.cl.resource_pool_id
  datastore_id     = data.vsphere_datastore.ds.id

  num_cpus = 2
  memory   = 4096
  guest_id = data.vsphere_virtual_machine.template.guest_id

  scsi_type = data.vsphere_virtual_machine.template.scsi_type

  disk {
    label            = "disk0"
    size             = data.vsphere_virtual_machine.template.disks[0].size
    thin_provisioned = data.vsphere_virtual_machine.template.disks[0].thin_provisioned
  }

  folder = var.folder

  network_interface {
    network_id   = data.vsphere_network.vm2_net.id
    adapter_type = data.vsphere_virtual_machine.template.network_interface_types[0]
  }

  clone {
    linked_clone  = "false"
    template_uuid = data.vsphere_virtual_machine.template.id

    customize {
      linux_options {
        host_name = var.aci_vm2_name
        domain    = var.domain_name
      }

      network_interface {
        ipv4_address = var.aci_vm2_address
        ipv4_netmask = "24"
      }

      ipv4_gateway    = var.gateway
      dns_server_list = [var.dns_list]
      dns_suffix_list = [var.dns_search]
    }
  }
}

The corresponding variables file can be found below.

variable "vsphere_server" {
  default = "10.x.y.z"
}

variable "vsphere_user" {
  default = "administrator@vsphere.local"
}

variable "vsphere_password" {
  default = "****!"
}

variable "vsphere_datacenter" {
  default = "SaS-DC"
}

variable "vsphere_datastore" {
  default = "datastore-UCS-POD1-2"
}

variable "vsphere_compute_cluster" {
  default = "SaS-Cluster"
}

variable "vsphere_template" {
  default = "ubuntu-1604-server-template"
}

variable "folder" {
  default = "wauterw"
}

variable "aci_vm1_name" {
  default = "vSphere1"
}

variable "aci_vm2_name" {
  default = "vSphere2"
}

variable "aci_vm1_address" {
  default = "10.16.2.233"
}

variable "aci_vm2_address" {
  default = "10.16.2.234"
}

variable "gateway" {
  default = "10.16.2.254"
}

variable "dns_list" {
  default = "10.9.15.1"
}

variable "dns_search" {
  default = "cisco.com"
}

variable "domain_name" {
  default = "cisco.com"
}

Deploy infrastructure

As we did with AWS resources (see here), we will follow exactly the same pattern.

First we will perform ‘terraform init’. This will essentially download the vSphere provider from Terraform repo.

cisco@wauterw-ubuntu-desktop:~/software/Terraform/vSphere$ terraform init

Initializing the backend...

Initializing provider plugins...
- Checking for available provider plugins...
- Downloading plugin for provider "vsphere" (hashicorp/vsphere) 1.13.0...

The following providers do not have any version constraints in configuration,
so the latest version was installed.

To prevent automatic upgrades to new major versions that may contain breaking
changes, it is recommended to add version = "..." constraints to the
corresponding provider blocks in configuration, with the constraint strings
suggested below.

* provider.vsphere: version = "~> 1.13"

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.

Then, we will perform a ‘terraform plan’

cisco@wauterw-ubuntu-desktop:~/software/Terraform/vSphere$ terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

data.vsphere_datacenter.dc: Refreshing state...
data.vsphere_network.vm1_net: Refreshing state...
data.vsphere_network.vm2_net: Refreshing state...
data.vsphere_compute_cluster.cl: Refreshing state...
data.vsphere_virtual_machine.template: Refreshing state...
data.vsphere_datastore.ds: Refreshing state...

------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # vsphere_virtual_machine.aci_vm1[0] will be created
  + resource "vsphere_virtual_machine" "aci_vm1" {
      + boot_retry_delay                        = 10000
      + change_version                          = (known after apply)
      + cpu_limit                               = -1
      + cpu_share_count                         = (known after apply)
      + cpu_share_level                         = "normal"
      + datastore_id                            = "datastore-267"
      + default_ip_address                      = (known after apply)
      + ept_rvi_mode                            = "automatic"
      + firmware                                = "bios"
      + folder                                  = "wauterw"
      + force_power_off                         = true
      + guest_id                                = "ubuntu64Guest"
      + guest_ip_addresses                      = (known after apply)
      + host_system_id                          = (known after apply)
      + hv_mode                                 = "hvAuto"
      + id                                      = (known after apply)
      + imported                                = (known after apply)
      + latency_sensitivity                     = "normal"
      + memory                                  = 4096
      + memory_limit                            = -1
      + memory_share_count                      = (known after apply)
      + memory_share_level                      = "normal"
      + migrate_wait_timeout                    = 30
      + moid                                    = (known after apply)
      + name                                    = "vSphere1"
      + num_cores_per_socket                    = 1
      + num_cpus                                = 2
      + reboot_required                         = (known after apply)
      + resource_pool_id                        = "resgroup-308"
      + run_tools_scripts_after_power_on        = true
      + run_tools_scripts_after_resume          = true
      + run_tools_scripts_before_guest_shutdown = true
      + run_tools_scripts_before_guest_standby  = true
      + scsi_bus_sharing                        = "noSharing"
      + scsi_controller_count                   = 1
      + scsi_type                               = "pvscsi"
      + shutdown_wait_timeout                   = 3
      + swap_placement_policy                   = "inherit"
      + uuid                                    = (known after apply)
      + vapp_transport                          = (known after apply)
      + vmware_tools_status                     = (known after apply)
      + vmx_path                                = (known after apply)
      + wait_for_guest_ip_timeout               = 0
      + wait_for_guest_net_routable             = true
      + wait_for_guest_net_timeout              = 5

      + clone {
          + linked_clone  = false
          + template_uuid = "423c759f-8c32-d183-8e8d-8f5ff2c266af"
          + timeout       = 30

          + customize {
              + dns_server_list = [
                  + "10.9.15.1",
                ]
              + dns_suffix_list = [
                  + "cisco.com",
                ]
              + ipv4_gateway    = "10.16.2.254"
              + timeout         = 10

              + linux_options {
                  + domain       = "cisco.com"
                  + host_name    = "vSphere1"
                  + hw_clock_utc = true
                }

              + network_interface {
                  + ipv4_address = "10.16.2.233"
                  + ipv4_netmask = 24
                }
            }
        }

      + disk {
          + attach           = false
          + datastore_id     = ""
          + device_address   = (known after apply)
          + disk_mode        = "persistent"
          + disk_sharing     = "sharingNone"
          + eagerly_scrub    = false
          + io_limit         = -1
          + io_reservation   = 0
          + io_share_count   = 0
          + io_share_level   = "normal"
          + keep_on_remove   = false
          + key              = 0
          + label            = "disk0"
          + path             = (known after apply)
          + size             = 16
          + thin_provisioned = false
          + unit_number      = 0
          + uuid             = (known after apply)
          + write_through    = false
        }

      + network_interface {
          + adapter_type          = "vmxnet3"
          + bandwidth_limit       = -1
          + bandwidth_reservation = 0
          + bandwidth_share_count = (known after apply)
          + bandwidth_share_level = "normal"
          + device_address        = (known after apply)
          + key                   = (known after apply)
          + mac_address           = (known after apply)
          + network_id            = "network-245"
        }
    }

  # vsphere_virtual_machine.aci_vm2[0] will be created
  + resource "vsphere_virtual_machine" "aci_vm2" {
      + boot_retry_delay                        = 10000
      + change_version                          = (known after apply)
      + cpu_limit                               = -1
      + cpu_share_count                         = (known after apply)
      + cpu_share_level                         = "normal"
      + datastore_id                            = "datastore-267"
      + default_ip_address                      = (known after apply)
      + ept_rvi_mode                            = "automatic"
      + firmware                                = "bios"
      + folder                                  = "wauterw"
      + force_power_off                         = true
      + guest_id                                = "ubuntu64Guest"
      + guest_ip_addresses                      = (known after apply)
      + host_system_id                          = (known after apply)
      + hv_mode                                 = "hvAuto"
      + id                                      = (known after apply)
      + imported                                = (known after apply)
      + latency_sensitivity                     = "normal"
      + memory                                  = 4096
      + memory_limit                            = -1
      + memory_share_count                      = (known after apply)
      + memory_share_level                      = "normal"
      + migrate_wait_timeout                    = 30
      + moid                                    = (known after apply)
      + name                                    = "vSphere2"
      + num_cores_per_socket                    = 1
      + num_cpus                                = 2
      + reboot_required                         = (known after apply)
      + resource_pool_id                        = "resgroup-308"
      + run_tools_scripts_after_power_on        = true
      + run_tools_scripts_after_resume          = true
      + run_tools_scripts_before_guest_shutdown = true
      + run_tools_scripts_before_guest_standby  = true
      + scsi_bus_sharing                        = "noSharing"
      + scsi_controller_count                   = 1
      + scsi_type                               = "pvscsi"
      + shutdown_wait_timeout                   = 3
      + swap_placement_policy                   = "inherit"
      + uuid                                    = (known after apply)
      + vapp_transport                          = (known after apply)
      + vmware_tools_status                     = (known after apply)
      + vmx_path                                = (known after apply)
      + wait_for_guest_ip_timeout               = 0
      + wait_for_guest_net_routable             = true
      + wait_for_guest_net_timeout              = 5

      + clone {
          + linked_clone  = false
          + template_uuid = "423c759f-8c32-d183-8e8d-8f5ff2c266af"
          + timeout       = 30

          + customize {
              + dns_server_list = [
                  + "10.9.15.1",
                ]
              + dns_suffix_list = [
                  + "cisco.com",
                ]
              + ipv4_gateway    = "10.16.2.254"
              + timeout         = 10

              + linux_options {
                  + domain       = "cisco.com"
                  + host_name    = "vSphere2"
                  + hw_clock_utc = true
                }

              + network_interface {
                  + ipv4_address = "10.16.2.234"
                  + ipv4_netmask = 24
                }
            }
        }

      + disk {
          + attach           = false
          + datastore_id     = ""
          + device_address   = (known after apply)
          + disk_mode        = "persistent"
          + disk_sharing     = "sharingNone"
          + eagerly_scrub    = false
          + io_limit         = -1
          + io_reservation   = 0
          + io_share_count   = 0
          + io_share_level   = "normal"
          + keep_on_remove   = false
          + key              = 0
          + label            = "disk0"
          + path             = (known after apply)
          + size             = 16
          + thin_provisioned = false
          + unit_number      = 0
          + uuid             = (known after apply)
          + write_through    = false
        }

      + network_interface {
          + adapter_type          = "vmxnet3"
          + bandwidth_limit       = -1
          + bandwidth_reservation = 0
          + bandwidth_share_count = (known after apply)
          + bandwidth_share_level = "normal"
          + device_address        = (known after apply)
          + key                   = (known after apply)
          + mac_address           = (known after apply)
          + network_id            = "network-245"
        }
    }

Plan: 2 to add, 0 to change, 0 to destroy.

------------------------------------------------------------------------

Note: You didn't specify an "-out" parameter to save this plan, so Terraform
can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.

Next, let’s apply the configuration. You should know the drill by now 🙂


And finally, let's apply the configuration.

cisco@wauterw-ubuntu-desktop:~/software/Terraform/vSphere$ terraform apply
data.vsphere_datacenter.dc: Refreshing state...
data.vsphere_network.vm2_net: Refreshing state...
data.vsphere_compute_cluster.cl: Refreshing state...
data.vsphere_datastore.ds: Refreshing state...
data.vsphere_virtual_machine.template: Refreshing state...
data.vsphere_network.vm1_net: Refreshing state...

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # vsphere_virtual_machine.aci_vm1[0] will be created
  + resource "vsphere_virtual_machine" "aci_vm1" {
      + boot_retry_delay                        = 10000
      + change_version                          = (known after apply)
      + cpu_limit                               = -1
      + cpu_share_count                         = (known after apply)
      + cpu_share_level                         = "normal"
      + datastore_id                            = "datastore-267"
      + default_ip_address                      = (known after apply)
      + ept_rvi_mode                            = "automatic"
      + firmware                                = "bios"
      + folder                                  = "wauterw"
      + force_power_off                         = true
      + guest_id                                = "ubuntu64Guest"
      + guest_ip_addresses                      = (known after apply)
      + host_system_id                          = (known after apply)
      + hv_mode                                 = "hvAuto"
      + id                                      = (known after apply)
      + imported                                = (known after apply)
      + latency_sensitivity                     = "normal"
      + memory                                  = 4096
      + memory_limit                            = -1
      + memory_share_count                      = (known after apply)
      + memory_share_level                      = "normal"
      + migrate_wait_timeout                    = 30
      + moid                                    = (known after apply)
      + name                                    = "vSphere1"
      + num_cores_per_socket                    = 1
      + num_cpus                                = 2
      + reboot_required                         = (known after apply)
      + resource_pool_id                        = "resgroup-308"
      + run_tools_scripts_after_power_on        = true
      + run_tools_scripts_after_resume          = true
      + run_tools_scripts_before_guest_shutdown = true
      + run_tools_scripts_before_guest_standby  = true
      + scsi_bus_sharing                        = "noSharing"
      + scsi_controller_count                   = 1
      + scsi_type                               = "pvscsi"
      + shutdown_wait_timeout                   = 3
      + swap_placement_policy                   = "inherit"
      + uuid                                    = (known after apply)
      + vapp_transport                          = (known after apply)
      + vmware_tools_status                     = (known after apply)
      + vmx_path                                = (known after apply)
      + wait_for_guest_ip_timeout               = 0
      + wait_for_guest_net_routable             = true
      + wait_for_guest_net_timeout              = 5

      + clone {
          + linked_clone  = false
          + template_uuid = "423c759f-8c32-d183-8e8d-8f5ff2c266af"
          + timeout       = 30

          + customize {
              + dns_server_list = [
                  + "10.9.15.1",
                ]
              + dns_suffix_list = [
                  + "cisco.com",
                ]
              + ipv4_gateway    = "10.16.2.254"
              + timeout         = 10

              + linux_options {
                  + domain       = "cisco.com"
                  + host_name    = "vSphere1"
                  + hw_clock_utc = true
                }

              + network_interface {
                  + ipv4_address = "10.16.2.233"
                  + ipv4_netmask = 24
                }
            }
        }

      + disk {
          + attach           = false
          + datastore_id     = ""
          + device_address   = (known after apply)
          + disk_mode        = "persistent"
          + disk_sharing     = "sharingNone"
          + eagerly_scrub    = false
          + io_limit         = -1
          + io_reservation   = 0
          + io_share_count   = 0
          + io_share_level   = "normal"
          + keep_on_remove   = false
          + key              = 0
          + label            = "disk0"
          + path             = (known after apply)
          + size             = 16
          + thin_provisioned = false
          + unit_number      = 0
          + uuid             = (known after apply)
          + write_through    = false
        }

      + network_interface {
          + adapter_type          = "vmxnet3"
          + bandwidth_limit       = -1
          + bandwidth_reservation = 0
          + bandwidth_share_count = (known after apply)
          + bandwidth_share_level = "normal"
          + device_address        = (known after apply)
          + key                   = (known after apply)
          + mac_address           = (known after apply)
          + network_id            = "network-245"
        }
    }

  # vsphere_virtual_machine.aci_vm2[0] will be created
  + resource "vsphere_virtual_machine" "aci_vm2" {
      + boot_retry_delay                        = 10000
      + change_version                          = (known after apply)
      + cpu_limit                               = -1
      + cpu_share_count                         = (known after apply)
      + cpu_share_level                         = "normal"
      + datastore_id                            = "datastore-267"
      + default_ip_address                      = (known after apply)
      + ept_rvi_mode                            = "automatic"
      + firmware                                = "bios"
      + folder                                  = "wauterw"
      + force_power_off                         = true
      + guest_id                                = "ubuntu64Guest"
      + guest_ip_addresses                      = (known after apply)
      + host_system_id                          = (known after apply)
      + hv_mode                                 = "hvAuto"
      + id                                      = (known after apply)
      + imported                                = (known after apply)
      + latency_sensitivity                     = "normal"
      + memory                                  = 4096
      + memory_limit                            = -1
      + memory_share_count                      = (known after apply)
      + memory_share_level                      = "normal"
      + migrate_wait_timeout                    = 30
      + moid                                    = (known after apply)
      + name                                    = "vSphere2"
      + num_cores_per_socket                    = 1
      + num_cpus                                = 2
      + reboot_required                         = (known after apply)
      + resource_pool_id                        = "resgroup-308"
      + run_tools_scripts_after_power_on        = true
      + run_tools_scripts_after_resume          = true
      + run_tools_scripts_before_guest_shutdown = true
      + run_tools_scripts_before_guest_standby  = true
      + scsi_bus_sharing                        = "noSharing"
      + scsi_controller_count                   = 1
      + scsi_type                               = "pvscsi"
      + shutdown_wait_timeout                   = 3
      + swap_placement_policy                   = "inherit"
      + uuid                                    = (known after apply)
      + vapp_transport                          = (known after apply)
      + vmware_tools_status                     = (known after apply)
      + vmx_path                                = (known after apply)
      + wait_for_guest_ip_timeout               = 0
      + wait_for_guest_net_routable             = true
      + wait_for_guest_net_timeout              = 5

      + clone {
          + linked_clone  = false
          + template_uuid = "423c759f-8c32-d183-8e8d-8f5ff2c266af"
          + timeout       = 30

          + customize {
              + dns_server_list = [
                  + "10.9.15.1",
                ]
              + dns_suffix_list = [
                  + "cisco.com",
                ]
              + ipv4_gateway    = "10.16.2.254"
              + timeout         = 10

              + linux_options {
                  + domain       = "cisco.com"
                  + host_name    = "vSphere2"
                  + hw_clock_utc = true
                }

              + network_interface {
                  + ipv4_address = "10.16.2.234"
                  + ipv4_netmask = 24
                }
            }
        }

      + disk {
          + attach           = false
          + datastore_id     = ""
          + device_address   = (known after apply)
          + disk_mode        = "persistent"
          + disk_sharing     = "sharingNone"
          + eagerly_scrub    = false
          + io_limit         = -1
          + io_reservation   = 0
          + io_share_count   = 0
          + io_share_level   = "normal"
          + keep_on_remove   = false
          + key              = 0
          + label            = "disk0"
          + path             = (known after apply)
          + size             = 16
          + thin_provisioned = false
          + unit_number      = 0
          + uuid             = (known after apply)
          + write_through    = false
        }

      + network_interface {
          + adapter_type          = "vmxnet3"
          + bandwidth_limit       = -1
          + bandwidth_reservation = 0
          + bandwidth_share_count = (known after apply)
          + bandwidth_share_level = "normal"
          + device_address        = (known after apply)
          + key                   = (known after apply)
          + mac_address           = (known after apply)
          + network_id            = "network-245"
        }
    }

Plan: 2 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

vsphere_virtual_machine.aci_vm1[0]: Creating...
vsphere_virtual_machine.aci_vm2[0]: Creating...
vsphere_virtual_machine.aci_vm1[0]: Still creating... [10s elapsed]
vsphere_virtual_machine.aci_vm2[0]: Still creating... [10s elapsed]
vsphere_virtual_machine.aci_vm1[0]: Still creating... [20s elapsed]
...
...
vsphere_virtual_machine.aci_vm2[0]: Still creating... [4m20s elapsed]
vsphere_virtual_machine.aci_vm1[0]: Creation complete after 6m32s [id=423c546b-2c1a-3cf4-0360-e0d300c7684d]
vsphere_virtual_machine.aci_vm2[0]: Creation complete after 6m33s [id=423c54c3-b2ac-d866-2ba7-3b231ddfc804]

Apply complete! Resources: 2 added, 0 changed, 0 destroyed.

Let's verify on vSphere

Destroy configuration

Next, we will destroy the two servers as we don't immediately require them. Note that destroying goes much faster (6s) compared to creating the servers (6min). Reason is obviously the cloning step of the template during the creation.

cisco@wauterw-ubuntu-desktop:~/software/Terraform/vSphere$ terraform destroy
data.vsphere_datacenter.dc: Refreshing state...
data.vsphere_virtual_machine.template: Refreshing state...
data.vsphere_datastore.ds: Refreshing state...
data.vsphere_network.vm1_net: Refreshing state...
data.vsphere_network.vm2_net: Refreshing state...
data.vsphere_compute_cluster.cl: Refreshing state...
vsphere_virtual_machine.aci_vm2[0]: Refreshing state... [id=423c54c3-b2ac-d866-2ba7-3b231ddfc804]
vsphere_virtual_machine.aci_vm1[0]: Refreshing state... [id=423c546b-2c1a-3cf4-0360-e0d300c7684d]

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  - destroy

Terraform will perform the following actions:

  # vsphere_virtual_machine.aci_vm1[0] will be destroyed
  - resource "vsphere_virtual_machine" "aci_vm1" {
      - boot_delay                              = 0 -> null
      - boot_retry_delay                        = 10000 -> null
      - boot_retry_enabled                      = false -> null
      - change_version                          = "2019-11-23T15:28:42.507933Z" -> null
      - cpu_hot_add_enabled                     = false -> null
      - cpu_hot_remove_enabled                  = false -> null
      - cpu_limit                               = -1 -> null
      - cpu_performance_counters_enabled        = false -> null
      - cpu_reservation                         = 0 -> null
      - cpu_share_count                         = 2000 -> null
      - cpu_share_level                         = "normal" -> null
      - custom_attributes                       = {} -> null
      - datastore_id                            = "datastore-267" -> null
      - default_ip_address                      = "10.16.2.233" -> null
      - efi_secure_boot_enabled                 = false -> null
      - enable_disk_uuid                        = false -> null
      - enable_logging                          = false -> null
      - ept_rvi_mode                            = "automatic" -> null
      - extra_config                            = {} -> null
      - firmware                                = "bios" -> null
      - folder                                  = "wauterw" -> null
      - force_power_off                         = true -> null
      - guest_id                                = "ubuntu64Guest" -> null
      - guest_ip_addresses                      = [
          - "10.16.2.233",
          - "fe80::250:56ff:febc:7404",
        ] -> null
      - host_system_id                          = "host-266" -> null
      - hv_mode                                 = "hvAuto" -> null
      - id                                      = "423c546b-2c1a-3cf4-0360-e0d300c7684d" -> null
      - latency_sensitivity                     = "normal" -> null
      - memory                                  = 4096 -> null
      - memory_hot_add_enabled                  = false -> null
      - memory_limit                            = -1 -> null
      - memory_reservation                      = 0 -> null
      - memory_share_count                      = 40960 -> null
      - memory_share_level                      = "normal" -> null
      - migrate_wait_timeout                    = 30 -> null
      - moid                                    = "vm-724" -> null
      - name                                    = "vSphere1" -> null
      - nested_hv_enabled                       = false -> null
      - num_cores_per_socket                    = 1 -> null
      - num_cpus                                = 2 -> null
      - reboot_required                         = false -> null
      - resource_pool_id                        = "resgroup-308" -> null
      - run_tools_scripts_after_power_on        = true -> null
      - run_tools_scripts_after_resume          = true -> null
      - run_tools_scripts_before_guest_reboot   = false -> null
      - run_tools_scripts_before_guest_shutdown = true -> null
      - run_tools_scripts_before_guest_standby  = true -> null
      - scsi_bus_sharing                        = "noSharing" -> null
      - scsi_controller_count                   = 1 -> null
      - scsi_type                               = "pvscsi" -> null
      - shutdown_wait_timeout                   = 3 -> null
      - swap_placement_policy                   = "inherit" -> null
      - sync_time_with_host                     = false -> null
      - tags                                    = [] -> null
      - uuid                                    = "423c546b-2c1a-3cf4-0360-e0d300c7684d" -> null
      - vapp_transport                          = [] -> null
      - vmware_tools_status                     = "guestToolsRunning" -> null
      - vmx_path                                = "vSphere1/vSphere1.vmx" -> null
      - wait_for_guest_ip_timeout               = 0 -> null
      - wait_for_guest_net_routable             = true -> null
      - wait_for_guest_net_timeout              = 5 -> null

      - clone {
          - linked_clone  = false -> null
          - template_uuid = "423c759f-8c32-d183-8e8d-8f5ff2c266af" -> null
          - timeout       = 30 -> null

          - customize {
              - dns_server_list = [
                  - "10.9.15.1",
                ] -> null
              - dns_suffix_list = [
                  - "cisco.com",
                ] -> null
              - ipv4_gateway    = "10.16.2.254" -> null
              - timeout         = 10 -> null

              - linux_options {
                  - domain       = "cisco.com" -> null
                  - host_name    = "vSphere1" -> null
                  - hw_clock_utc = true -> null
                }

              - network_interface {
                  - dns_server_list = [] -> null
                  - ipv4_address    = "10.16.2.233" -> null
                  - ipv4_netmask    = 24 -> null
                  - ipv6_netmask    = 0 -> null
                }
            }
        }

      - disk {
          - attach           = false -> null
          - datastore_id     = "datastore-267" -> null
          - device_address   = "scsi:0:0" -> null
          - disk_mode        = "persistent" -> null
          - disk_sharing     = "sharingNone" -> null
          - eagerly_scrub    = false -> null
          - io_limit         = -1 -> null
          - io_reservation   = 0 -> null
          - io_share_count   = 1000 -> null
          - io_share_level   = "normal" -> null
          - keep_on_remove   = false -> null
          - key              = 2000 -> null
          - label            = "disk0" -> null
          - path             = "vSphere1/vSphere1.vmdk" -> null
          - size             = 16 -> null
          - thin_provisioned = false -> null
          - unit_number      = 0 -> null
          - uuid             = "6000C293-fd0a-4f15-2b60-2473c4dcc197" -> null
          - write_through    = false -> null
        }

      - network_interface {
          - adapter_type          = "vmxnet3" -> null
          - bandwidth_limit       = -1 -> null
          - bandwidth_reservation = 0 -> null
          - bandwidth_share_count = 50 -> null
          - bandwidth_share_level = "normal" -> null
          - device_address        = "pci:0:7" -> null
          - key                   = 4000 -> null
          - mac_address           = "00:50:56:bc:74:04" -> null
          - network_id            = "network-245" -> null
          - use_static_mac        = false -> null
        }
    }

  # vsphere_virtual_machine.aci_vm2[0] will be destroyed
  - resource "vsphere_virtual_machine" "aci_vm2" {
      - boot_delay                              = 0 -> null
      - boot_retry_delay                        = 10000 -> null
      - boot_retry_enabled                      = false -> null
      - change_version                          = "2019-11-23T15:28:45.488548Z" -> null
      - cpu_hot_add_enabled                     = false -> null
      - cpu_hot_remove_enabled                  = false -> null
      - cpu_limit                               = -1 -> null
      - cpu_performance_counters_enabled        = false -> null
      - cpu_reservation                         = 0 -> null
      - cpu_share_count                         = 2000 -> null
      - cpu_share_level                         = "normal" -> null
      - custom_attributes                       = {} -> null
      - datastore_id                            = "datastore-267" -> null
      - default_ip_address                      = "10.16.2.234" -> null
      - efi_secure_boot_enabled                 = false -> null
      - enable_disk_uuid                        = false -> null
      - enable_logging                          = false -> null
      - ept_rvi_mode                            = "automatic" -> null
      - extra_config                            = {} -> null
      - firmware                                = "bios" -> null
      - folder                                  = "wauterw" -> null
      - force_power_off                         = true -> null
      - guest_id                                = "ubuntu64Guest" -> null
      - guest_ip_addresses                      = [
          - "10.16.2.234",
          - "fe80::250:56ff:febc:2b9b",
        ] -> null
      - host_system_id                          = "host-266" -> null
      - hv_mode                                 = "hvAuto" -> null
      - id                                      = "423c54c3-b2ac-d866-2ba7-3b231ddfc804" -> null
      - latency_sensitivity                     = "normal" -> null
      - memory                                  = 4096 -> null
      - memory_hot_add_enabled                  = false -> null
      - memory_limit                            = -1 -> null
      - memory_reservation                      = 0 -> null
      - memory_share_count                      = 40960 -> null
      - memory_share_level                      = "normal" -> null
      - migrate_wait_timeout                    = 30 -> null
      - moid                                    = "vm-723" -> null
      - name                                    = "vSphere2" -> null
      - nested_hv_enabled                       = false -> null
      - num_cores_per_socket                    = 1 -> null
      - num_cpus                                = 2 -> null
      - reboot_required                         = false -> null
      - resource_pool_id                        = "resgroup-308" -> null
      - run_tools_scripts_after_power_on        = true -> null
      - run_tools_scripts_after_resume          = true -> null
      - run_tools_scripts_before_guest_reboot   = false -> null
      - run_tools_scripts_before_guest_shutdown = true -> null
      - run_tools_scripts_before_guest_standby  = true -> null
      - scsi_bus_sharing                        = "noSharing" -> null
      - scsi_controller_count                   = 1 -> null
      - scsi_type                               = "pvscsi" -> null
      - shutdown_wait_timeout                   = 3 -> null
      - swap_placement_policy                   = "inherit" -> null
      - sync_time_with_host                     = false -> null
      - tags                                    = [] -> null
      - uuid                                    = "423c54c3-b2ac-d866-2ba7-3b231ddfc804" -> null
      - vapp_transport                          = [] -> null
      - vmware_tools_status                     = "guestToolsRunning" -> null
      - vmx_path                                = "vSphere2/vSphere2.vmx" -> null
      - wait_for_guest_ip_timeout               = 0 -> null
      - wait_for_guest_net_routable             = true -> null
      - wait_for_guest_net_timeout              = 5 -> null

      - clone {
          - linked_clone  = false -> null
          - template_uuid = "423c759f-8c32-d183-8e8d-8f5ff2c266af" -> null
          - timeout       = 30 -> null

          - customize {
              - dns_server_list = [
                  - "10.9.15.1",
                ] -> null
              - dns_suffix_list = [
                  - "cisco.com",
                ] -> null
              - ipv4_gateway    = "10.16.2.254" -> null
              - timeout         = 10 -> null

              - linux_options {
                  - domain       = "cisco.com" -> null
                  - host_name    = "vSphere2" -> null
                  - hw_clock_utc = true -> null
                }

              - network_interface {
                  - dns_server_list = [] -> null
                  - ipv4_address    = "10.16.2.234" -> null
                  - ipv4_netmask    = 24 -> null
                  - ipv6_netmask    = 0 -> null
                }
            }
        }

      - disk {
          - attach           = false -> null
          - datastore_id     = "datastore-267" -> null
          - device_address   = "scsi:0:0" -> null
          - disk_mode        = "persistent" -> null
          - disk_sharing     = "sharingNone" -> null
          - eagerly_scrub    = false -> null
          - io_limit         = -1 -> null
          - io_reservation   = 0 -> null
          - io_share_count   = 1000 -> null
          - io_share_level   = "normal" -> null
          - keep_on_remove   = false -> null
          - key              = 2000 -> null
          - label            = "disk0" -> null
          - path             = "vSphere2/vSphere2.vmdk" -> null
          - size             = 16 -> null
          - thin_provisioned = false -> null
          - unit_number      = 0 -> null
          - uuid             = "6000C29e-322f-077a-728f-2223206e8016" -> null
          - write_through    = false -> null
        }

      - network_interface {
          - adapter_type          = "vmxnet3" -> null
          - bandwidth_limit       = -1 -> null
          - bandwidth_reservation = 0 -> null
          - bandwidth_share_count = 50 -> null
          - bandwidth_share_level = "normal" -> null
          - device_address        = "pci:0:7" -> null
          - key                   = 4000 -> null
          - mac_address           = "00:50:56:bc:2b:9b" -> null
          - network_id            = "network-245" -> null
          - use_static_mac        = false -> null
        }
    }

Plan: 0 to add, 0 to change, 2 to destroy.

Do you really want to destroy all resources?
  Terraform will destroy all your managed infrastructure, as shown above.
  There is no undo. Only 'yes' will be accepted to confirm.

  Enter a value: yes

vsphere_virtual_machine.aci_vm1[0]: Destroying... [id=423c546b-2c1a-3cf4-0360-e0d300c7684d]
vsphere_virtual_machine.aci_vm2[0]: Destroying... [id=423c54c3-b2ac-d866-2ba7-3b231ddfc804]
vsphere_virtual_machine.aci_vm2[0]: Destruction complete after 9s
vsphere_virtual_machine.aci_vm1[0]: Destruction complete after 9s

Destroy complete! Resources: 2 destroyed.

Pretty simple but good to make a blog post about it for future reference.

Ciao!

Leave a Reply

Your email address will not be published. Required fields are marked *