0
votes

While trying to allocate memory and num_cpus for a virtual machine in VSphere, I am trying to extract the memory and num_cpus from the template. But I am getting an error while trying to do so. Here is my resource:

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

resource "vsphere_virtual_machine" "vm" {
  count = var.vm-count
  name = "${var.vm-name}-${count.index + 1}"
  resource_pool_id = data.vsphere_compute_cluster.cluster.resource_pool_id
  datastore_id = data.vsphere_datastore.datastore.id
  folder = var.vm-folder
  #####Problem Area############################################
  num_cpus = data.vsphere_virtual_machine.template.num_cpus
  memory = data.vsphere_virtual_machine.template.memory
  #############################################################
  guest_id = data.vsphere_virtual_machine.template.guest_id
  scsi_type = data.vsphere_virtual_machine.template.scsi_type
  firmware = data.vsphere_virtual_machine.template.firmware

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

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

  clone {
    template_uuid = data.vsphere_virtual_machine.template.id

    customize {
        windows_options {
          auto_logon_count = 2
          computer_name = "HarshitDev"
          organization_name = "Philips"
        }
      }
  }
}

And here is the error I am getting when I run 'terraform validate':

Error: Unsupported attribute

on main.tf line 39, in resource "vsphere_virtual_machine" "vm":
39: num_cpus = data.vsphere_virtual_machine.template.num_cpus

This object has no argument, nested block, or exported attribute named "num_cpus".

Error: Unsupported attribute

on main.tf line 40, in resource "vsphere_virtual_machine" "vm":
40: memory = data.vsphere_virtual_machine.template.memory

This object has no argument, nested block, or exported attribute named "memory".

1
Do you have reason to believe it should? According to the documentation, it does not. terraform.io/docs/providers/vsphere/d/…pst

1 Answers

0
votes

num_cpus has not been exposed in the vsphere_virtual_machine resource.

Someone has started work on it (see here), but it is yet to be merged.