设置多个虚拟机时无法输入mac地址

时间:2019-01-31 09:36:30

标签: terraform

所以我试图部署多个虚拟机,但是当我尝试输出mac adrress时却失败了

output.mac:找不到变量'vsphere_virtual_machine.vm.network_interface.0.mac_address'的资源'vsphere_virtual_machine.vm'

有人可以告诉我为什么它失败或我的代码出了什么问题

   resource "vsphere_virtual_machine" "vm" {
      count="2"
      name             = "name-${count.index+1}"
      resource_pool_id = "${data.vsphere_resource_pool.pool.id}"
      datastore_id     = "${data.vsphere_datastore.datastore.id}"
      num_cpus = 2
      memory   = 1024
      guest_id = "${data.vsphere_virtual_machine.template.guest_id}"
      scsi_type = "${data.vsphere_virtual_machine.template.scsi_type}"

      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 {
          linux_options {
            host_name = "terraform-test1"
            domain    = "test.internal"
          }

          network_interface {
        ipv4_address = "10.0.0.${count.index+2}"
        ipv4_netmask = 24
      }

      ipv4_gateway = "10.0.0.1"
    }
  }
}

output "mac"{
value ="${vsphere_virtual_machine.vm.network_interface.0.mac_address}"
}

3 个答案:

答案 0 :(得分:1)

资源“ vsphere_virtual_machine”没有属性引用“ network_interface”,因此您无法输出网络接口详细信息。请检查资源文档链接https://www.terraform.io/docs/providers/vsphere/r/virtual_machine.html

Following attributes are exported on the base level of this resource:

id - The UUID of the virtual machine.
reboot_required - Value internal to Terraform used to determine if a configuration set change requires a reboot. This value is only useful during an update process and gets reset on refresh.
vmware_tools_status - The state of VMware tools in the guest. This will determine the proper course of action for some device operations.
vmx_path - The path of the virtual machine's configuration file in the VM's datastore.
imported - This is flagged if the virtual machine has been imported, or the state has been migrated from a previous version of the resource. It influences the behavior of the first post-import apply operation. See the section on importing below.
change_version - A unique identifier for a given version of the last configuration applied, such the timestamp of the last update to the configuration.
uuid - The UUID of the virtual machine. Also exposed as the id of the resource.
default_ip_address - The IP address selected by Terraform to be used with any provisioners configured on this resource. Whenever possible, this is the first IPv4 address that is reachable through the default gateway configured on the machine, then the first reachable IPv6 address, and then the first general discovered address if neither exist. If VMware tools is not running on the virtual machine, or if the VM is powered off, this value will be blank.
guest_ip_addresses - The current list of IP addresses on this machine, including the value of default_ip_address. If VMware tools is not running on the virtual machine, or if the VM is powered off, this list will be empty.
moid: The managed object reference ID of the created virtual machine.
vapp_transport - Computed value which is only valid for cloned virtual machines. A list of vApp transport methods supported by the source virtual machine or template.

答案 1 :(得分:0)

只要有兴趣,这对我有用:)

output "mac"{
value ="${vsphere_virtual_machine.vm.network_interface[0].mac_address}"
}

答案 2 :(得分:0)

在旧版Terraform(0.11.8)上,我必须使用:

output "mac"{
value ="${vsphere_virtual_machine.vm.network_interface.0.mac_address}"
}