terraform-provider-vsphere: vsphere_virtual_machine "cannot locate virtual machine or template with UUID"

Terraform Version

Terraform v0.11.1
+ provider.vsphere v1.0.1

vSphere Provider Version

.
└── provider.vsphere ~> 1.0.1

Affected Resource(s)

Data Sources

  • vsphere_virtual_machine

Resources

  • vsphere_virtual_machine

Terraform Configuration Files

# Providers
provider "vsphere" {
    version = "~> 1.0.1"
    vsphere_server = "vCenter.domain.local"
    user = "${var.vsphere_user}"
    password = "${var.vsphere_password}"
}

# Data
data "vsphere_datacenter" "dc" {
  name = "MyDataCenter"
}

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

data "vsphere_resource_pool" "pool" {
  name          = "Cluster1/Resources"
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

data "vsphere_network" "network" {
  name          = "vlan_555"
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

data "vsphere_virtual_machine" "template" {
    name = "Server2012_R2_Template"
    datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

# Resources
resource "vsphere_virtual_machine" "server1" {
    name = "${var.vsphere_virtual_machine_name}"
    num_cpus = "${var.vsphere_virtual_machine_vcpu}"
    memory = "${var.vsphere_virtual_machine_memory}"
    resource_pool_id = "${data.vsphere_resource_pool.pool.id}"
    datastore_id = "${data.vsphere_datastore.datastore.id}"
    guest_id = "${data.vsphere_virtual_machine.template.guest_id}"
    scsi_type = "${data.vsphere_virtual_machine.template.scsi_type}"
    folder = "My/Vm/Folder"

    cpu_hot_add_enabled = true
    memory_hot_add_enabled = true

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

    disk {
        name = "${var.vsphere_virtual_machine_name}.vmdk"
        //size = "${data.vsphere_virtual_machine.template.disk_sizes[0]}"
        size = 50
        thin_provisioned = true
    }

    clone {
        template_uuid = "${data.vsphere_virtual_machine.template.id}"
        
        customize {
            windows_options {
                computer_name = "${var.vsphere_virtual_machine_name}"
                admin_password = "REDACTED"
                join_domain = "domain.local"
                domain_admin_user = "${var.domainjoin_user}"
                domain_admin_password = "${var.domainjoin_password}"
                time_zone = "035"
                organization_name = "Test"
            }

            network_interface {
                ipv4_address = "${var.network_interface_ipv4_address}" 
                ipv4_netmask = 24
                dns_server_list = ["10.1.1.1", "10.1.1.2", "10.1.1.3", "10.1.1.4"]
                dns_domain = "domain.local"
            }

            ipv4_gateway = "10.10.10.50"
        }
    }
}

Debug Output

DebugGist

Expected Behavior

The VM template should have been located from its datasource.

Actual Behavior

The following was displayed

Error: Error running plan: 1 error(s) occurred:

* vsphere_virtual_machine.server1: 1 error(s) occurred:

* vsphere_virtual_machine.server1: cannot locate virtual machine or template with UUID "421659f0-e810-e754-c31a-5364df597d79": virtual machine with UUID "421659f0-e810-e754-c31a-5364df597d79" not found

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

terraform apply or terraform plan

Important Factoids

vSphere version is 5.5 U3.

References

NA

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 27 (10 by maintainers)

Most upvoted comments

Hey @johnjelinek, indeed this is the method we will be using - this was documented in #318 as well. We have used this method for searching other MO’s (namely networks). It will be implemented as a fallback method for vSphere versions previous to a specific version so that we can continue to use more direct calls on versions that support it.

Thanks!

Great thanks for replying @genevievelesperance - I’ll take it over based on our discussions in #318.

@ephos this is interesting data - thank you for checking!

I also see something here that at some point in time in the past, FindByUuid actually did not work on templates.

I did not necessarily test VMs marked as templates on our 5.5f installation, I’ll try that and report back the results.

Thanks!