无法从Terraform VSphere中的模板获取内存或num_cpus

时间:2020-04-15 14:35:22

标签: terraform vsphere

在尝试为VSphere中的虚拟机分配内存和num_cpus时,我试图从模板中提取内存和num_cpus。但是尝试这样做时出现错误。 这是我的资源:

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"
        }
      }
  }
}

这是我运行“ terraform validate”时遇到的错误:

错误:属性不受支持

在main.tf第39行的资源“ vsphere_virtual_machine”“ vm”中:
39:num_cpus = data.vsphere_virtual_machine.template.num_cpus

此对象没有参数,嵌套块或导出的属性,名称为 “ num_cpus”。

错误:属性不受支持

在main.tf第40行的资源“ vsphere_virtual_machine”“ vm”中:
40:内存= data.vsphere_virtual_machine.template.memory

此对象没有参数,嵌套块或导出的属性,名称为 “内存”。

1 个答案:

答案 0 :(得分:0)

num_cpus尚未在vsphere_virtual_machine resource中公开。

有人已经开始对其进行工作(see here),但是尚未合并。