Skip to content

Commit 063f1f6

Browse files
committed
feat: add vgpu to vm resource
Add a new option `shared-pci-device-id` to the `virtual machine` resource. This enables users to 1 or more vGPU to the VM as an update to the resource or during the clone operation.
1 parent dea5add commit 063f1f6

File tree

3 files changed

+226
-30
lines changed

3 files changed

+226
-30
lines changed

docs/resources/virtual_machine.md

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,8 @@ The following options are general virtual machine and provider workflow options:
628628

629629
* `clone` - (Optional) When specified, the virtual machine will be created as a clone of a specified template. Optional customization options can be submitted for the resource. See [creating a virtual machine from a template](#creating-a-virtual-machine-from-a-template) for more information.
630630

631+
~> **NOTE:** Cloning requires vCenter Server and is not supported on direct ESXi host connections.
632+
631633
* `extra_config_reboot_required` - (Optional) Allow the virtual machine to be rebooted when a change to `extra_config` occurs. Default: `true`.
632634

633635
* `custom_attributes` - (Optional) Map of custom attribute ids to attribute value strings to set for virtual machine. Please refer to the [`vsphere_custom_attributes`][docs-setting-custom-attributes] resource for more information on setting custom attributes.
@@ -656,7 +658,7 @@ The following options are general virtual machine and provider workflow options:
656658

657659
* `firmware` - (Optional) The firmware for the virtual machine. One of `bios` or `efi`.
658660

659-
* `folder` - (Optional) The path to the virtual machine folder in which to place the virtual machine, relative to the datacenter path (`/<datacenter-name>/vm`). For example, `/dc-01/vm/foo`
661+
* `folder` - (Optional) The path to the virtual machine folder in which to place the virtual machine, relative to the datacenter path (`/<datacenter-name>/vm`). For example, `/dc-01/vm/foo`
660662

661663
* `guest_id` - (Optional) The guest ID for the operating system type. Default: `otherGuest64`.
662664

@@ -684,13 +686,13 @@ The following options are general virtual machine and provider workflow options:
684686

685687
* `pci_device_id` - (Optional) List of host PCI device IDs in which to create PCI passthroughs.
686688

687-
~> **NOTE:** Cloning requires vCenter Server and is not supported on direct ESXi host connections.
689+
* `shared_pci_device_id` - (Optional) A shared PCI device ID to create PCI passthrough.
688690

689691
* `ovf_deploy` - (Optional) When specified, the virtual machine will be deployed from the provided OVF/OVA template. See [creating a virtual machine from an OVF/OVA template](#creating-a-virtual-machine-from-an-ovf-ova-template) for more information.
690692

691693
* `replace_trigger` - (Optional) Triggers replacement of resource whenever it changes.
692694

693-
For example, `replace_trigger = sha256(format("%s-%s",data.template_file.cloud_init_metadata.rendered,data.template_file.cloud_init_userdata.rendered))` will fingerprint the changes in cloud-init metadata and userdata templates. This will enable a replacement of the resource whenever the dependant template renders a new configuration. (Forces a replacement.)
695+
For example, `replace_trigger = sha256(format("%s-%s",data.template_file.cloud_init_metadata.rendered,data.template_file.cloud_init_userdata.rendered))` will fingerprint the changes in cloud-init metadata and user-data templates. This will enable a replacement of the resource whenever the dependant template renders a new configuration. (Forces a replacement.)
694696

695697
* `resource_pool_id` - (Required) The [managed object reference ID][docs-about-morefs] of the resource pool in which to place the virtual machine. See the [Virtual Machine Migration](#virtual-machine-migration) section for more information on modifying this value.
696698

@@ -706,6 +708,17 @@ For example, `replace_trigger = sha256(format("%s-%s",data.template_file.cloud_i
706708

707709
* `storage_policy_id` - (Optional) The ID of the storage policy to assign to the home directory of a virtual machine.
708710

711+
* `shared_pci_device_id` - (Optional) List of shared PCI device(s) to create
712+
shared PCI passthrough.
713+
714+
For example, attaching a vGPU to the virtual machine: `shared_pci_device_id = ["grid_a100d-40c"]`
715+
716+
~> **NOTE:** The use of vGPU requires that the VM has memory reservation set equal
717+
to the amount of provisioned memory. This can be accomplished by leveraging
718+
the [`memory_reservation`](#memory_reservation) option.
719+
720+
* `storage_policy_id` - (Optional) The ID of the storage policy to assign to the home directory of a virtual machine.
721+
709722
* `tags` - (Optional) The IDs of any tags to attach to this resource. Please refer to the [`vsphere_tag`][docs-applying-tags] resource for more information on applying tags to virtual machine resources.
710723

711724
[docs-applying-tags]: /docs/providers/vsphere/r/tag.html#using-tags-in-a-supported-resource
@@ -850,7 +863,7 @@ The options are:
850863

851864
Virtual disks are managed by adding one or more instance of the `disk` block.
852865

853-
At a minimum, both the `label` and `size` attributes must be provided. The `unit_number` is required for any disk other than the first, and there must be at least one resource with the implicit number of `0`.
866+
At a minimum, both the `label` and `size` attributes must be provided. The `unit_number` is required for any disk other than the first, and there must be at least one resource with the implicit number of `0`.
854867

855868
The following example demonstrates an abridged multi-disk configuration:
856869

@@ -903,7 +916,7 @@ an error if you try to label a disk with this prefix.
903916

904917
[vmware-docs-disk-mode]: https://developer.broadcom.com/xapis/virtual-infrastructure-json-api/latest/data-structures/VirtualDiskMode/enum/
905918

906-
* `eagerly_scrub` - (Optional) If set to `true`, the disk space is zeroed out when the virtual machine is created. This will delay the creation of the virtual disk. Cannot be set to `true` when `thin_provisioned` is `true`. See the section on [picking a disk type](#picking-a-disk-type) for more information. Default: `false`.
919+
* `eagerly_scrub` - (Optional) If set to `true`, the disk space is zeroed out when the virtual machine is created. This will delay the creation of the virtual disk. Cannot be set to `true` when `thin_provisioned` is `true`. See the section on [picking a disk type](#picking-a-disk-type) for more information. Default: `false`.
907920

908921
* `thin_provisioned` - (Optional) If `true`, the disk is thin provisioned, with space for the file being allocated on an as-needed basis. Cannot be set to `true` when `eagerly_scrub` is `true`. See the section on [selecting a disk type](#selecting-a-disk-type) for more information. Default: `true`.
909922

@@ -913,7 +926,7 @@ an error if you try to label a disk with this prefix.
913926

914927
* `io_limit` - (Optional) The upper limit of IOPS that this disk can use. The default is no limit.
915928

916-
* `io_reservation` - (Optional) The I/O reservation (guarantee) for the virtual disk has, in IOPS. The default is no reservation.
929+
* `io_reservation` - (Optional) The I/O reservation (guarantee) for the virtual disk has, in IOPS. The default is no reservation.
917930

918931
* `io_share_level` - (Optional) The share allocation level for the virtual disk. One of `low`, `normal`, `high`, or `custom`. Default: `normal`.
919932

@@ -1041,6 +1054,7 @@ there are a few requirements
10411054
* The `memory_reservation` must be fully set (that is, equal to the `memory`) for the VM.
10421055

10431056
* The `network_interface` sub-resource takes a `physical_function` argument:
1057+
10441058
* This **must** be set if your adapter type is `sriov`.
10451059
* This **must not** be set if your adapter type is not `sriov`.
10461060
* This can be found by navigating to the relevant host in the vSphere Client,
@@ -1221,7 +1235,7 @@ The options are:
12211235

12221236
* `ipv6_address` - (Optional) The IPv6 address assigned to the network adapter. If blank or not included, auto-configuration is used.
12231237

1224-
* `ipv6_netmask` - (Optional) The IPv6 subnet mask, in bits (_e.g._ `32`).
1238+
* `ipv6_netmask` - (Optional) The IPv6 subnet mask, in bits (_e.g._ `32`).
12251239

12261240
~> **NOTE:** The minimum setting for IPv4 in a customization specification is DHCP. If you are setting up an IPv6-exclusive network without DHCP, you may need to set [`wait_for_guest_net_timeout`](#wait_for_guest_net_timeout) to a high enough value to cover the DHCP timeout of your virtual machine, or disable by supplying a zero or negative value. Disabling `wait_for_guest_net_timeout` may result in IP addresses not being reported to any provisioners you may have configured on the resource.
12271241

@@ -1313,7 +1327,7 @@ The options are:
13131327

13141328
* `admin_password` - (Optional) The administrator password for the virtual machine.
13151329

1316-
~> **NOTE:** `admin_password` is a sensitive field and will not be output on-screen, but is stored in state and sent to the virtual machine in plain text.
1330+
~> \*_NOTE:_* `admin_password` is a sensitive field and will not be output on-screen, but is stored in state and sent to the virtual machine in plain text.
13171331

13181332
* `workgroup` - (Optional) The workgroup name for the virtual machine. One of this or `join_domain` must be included.
13191333

@@ -1346,7 +1360,7 @@ resource "vsphere_virtual_machine" "vm" {
13461360

13471361
* `domain_admin_password` - (Optional) The password user account with administrative privileges used to join the virtual machine to the domain. Required if setting `join_domain`.
13481362

1349-
~> **NOTE:** `domain_admin_password` is a sensitive field and will not be output on-screen, but is stored in state and sent to the virtual machine in plain text
1363+
~> \*_NOTE:_* `domain_admin_password` is a sensitive field and will not be output on-screen, but is stored in state and sent to the virtual machine in plain text
13501364

13511365
* `full_name` - (Optional) The full name of the organization owner of the virtual machine. This populates the "user" field in the general Windows system information. Default: `Administrator`.
13521366

@@ -1507,13 +1521,13 @@ resource "vsphere_virtual_machine" "vm" {
15071521

15081522
When cloning from a template, there are additional requirements in both the resource configuration and source template:
15091523

1510-
* The virtual machine must not be powered on at the time of cloning.
1511-
* All disks on the virtual machine must be SCSI disks.
1512-
* You must specify at least the same number of `disk` devices as there are disks that exist in the template. These devices are ordered and lined up by the `unit_number` attribute. Additional disks can be added past this.
1513-
* The `size` of a virtual disk must be at least the same size as its counterpart disk in the source template.
1514-
* When using `linked_clone`, the `size`, `thin_provisioned`, and `eagerly_scrub` settings for each disk must be an exact match to the individual disk's counterpart in the source template.
1515-
* The storage controller count settings should be configured as necessary to cover all of the disks on the template. For best results, only configure this setting for the number of controllers you will need to cover your disk quantity and bandwidth needs, and configure your template accordingly. For most workloads, this setting should be kept at the default of `1` SCSI controller, and all disks in the template should reside on the single, primary controller.
1516-
* Some operating systems do not respond well to a change in disk controller type. Ensure that `scsi_type` is set to an exact match of the template's controller set. For maximum compatibility, make sure the SCSI controllers on the source template are all the same type.
1524+
- The virtual machine must not be powered on at the time of cloning.
1525+
- All disks on the virtual machine must be SCSI disks.
1526+
- You must specify at least the same number of `disk` devices as there are disks that exist in the template. These devices are ordered and lined up by the `unit_number` attribute. Additional disks can be added past this.
1527+
- The `size` of a virtual disk must be at least the same size as its counterpart disk in the source template.
1528+
- When using `linked_clone`, the `size`, `thin_provisioned`, and `eagerly_scrub` settings for each disk must be an exact match to the individual disk's counterpart in the source template.
1529+
- The storage controller count settings should be configured as necessary to cover all of the disks on the template. For best results, only configure this setting for the number of controllers you will need to cover your disk quantity and bandwidth needs, and configure your template accordingly. For most workloads, this setting should be kept at the default of `1` SCSI controller, and all disks in the template should reside on the single, primary controller.
1530+
- Some operating systems do not respond well to a change in disk controller type. Ensure that `scsi_type` is set to an exact match of the template's controller set. For maximum compatibility, make sure the SCSI controllers on the source template are all the same type.
15171531

15181532
You can use the [`vsphere_virtual_machine`][tf-vsphere-virtual-machine-ds] data source, which provides disk attributes, network interface types, SCSI bus types, and the guest ID of the source template, to return this information. See the section on [cloning and customization](#cloning-and-customization) for more information.
15191533

@@ -1549,9 +1563,9 @@ The same rules apply for migration as they do for virtual machine creation - any
15491563

15501564
Storage migration can be done on two levels:
15511565

1552-
* Global datastore migration can be handled by changing the global `datastore_id` attribute. This triggers a storage migration for all disks that do not have an explicit `datastore_id` specified.
1553-
* When using Storage DRS through the `datastore_cluster_id` attribute, the entire virtual machine can be migrated from one datastore cluster to another by changing the value of this setting. In addition, when `datastore_cluster_id` is in use, any disks that drift to datastores outside of the datastore cluster via such actions as manual modification will be migrated back to the datastore cluster on the next apply.
1554-
* An individual `disk` device can be migrated by manually specifying the `datastore_id` in its configuration block. This also pins it to the specific datastore that is specified - if at a later time the virtual machine and any unpinned disks migrate to another host, the disk will stay on the specified datastore.
1566+
- Global datastore migration can be handled by changing the global `datastore_id` attribute. This triggers a storage migration for all disks that do not have an explicit `datastore_id` specified.
1567+
- When using Storage DRS through the `datastore_cluster_id` attribute, the entire virtual machine can be migrated from one datastore cluster to another by changing the value of this setting. In addition, when `datastore_cluster_id` is in use, any disks that drift to datastores outside of the datastore cluster via such actions as manual modification will be migrated back to the datastore cluster on the next apply.
1568+
- An individual `disk` device can be migrated by manually specifying the `datastore_id` in its configuration block. This also pins it to the specific datastore that is specified - if at a later time the virtual machine and any unpinned disks migrate to another host, the disk will stay on the specified datastore.
15551569

15561570
An example of datastore pinning is below. As long as the datastore in the `pinned_datastore` data source does not change, any change to the standard `vm_datastore` data source will not affect the data disk - the disk will stay where it is.
15571571

@@ -1629,7 +1643,7 @@ The following attributes are exported on the base level of this resource:
16291643

16301644
* `reboot_required` - Value internal to Terraform used to determine if a configuration set change requires a reboot. This value is most useful during an update process and gets reset on refresh.
16311645

1632-
* `vmware_tools_status` - The state of VMware Tools in the guest. This will determine the proper course of action for some device operations.
1646+
* `vmware_tools_status` - The state of VMware Tools in the guest. This will determine the proper course of action for some device operations.
16331647

16341648
* `vmx_path` - The path of the virtual machine configuration file on the datastore in which the virtual machine is placed.
16351649

@@ -1681,17 +1695,17 @@ The following requirements apply to import:
16811695

16821696
~> **NOTE:** Any custom `label` set at deployment of machine through Terraform, on import will not have the custom `label` and will default to `Hard Disk _x_`.
16831697

1684-
* Disks are always imported with [`keep_on_remove`](#keep_on_remove) enabled until the first `terraform apply` run which will remove the setting for known disks. This process safeguards against naming or accounting mistakes in the disk configuration.
1698+
- Disks are always imported with [`keep_on_remove`](#keep_on_remove) enabled until the first `terraform apply` run which will remove the setting for known disks. This process safeguards against naming or accounting mistakes in the disk configuration.
16851699

1686-
* The storage controller count for the resource is set to the number of contiguous storage controllers found, starting with the controller at SCSI bus number `0`. If no storage controllers are discovered, the virtual machine is not eligible for import. For maximum compatibility, ensure that the virtual machine has the exact number of storage controllers needed and set the storage controller count accordingly.
1700+
- The storage controller count for the resource is set to the number of contiguous storage controllers found, starting with the controller at SCSI bus number `0`. If no storage controllers are discovered, the virtual machine is not eligible for import. For maximum compatibility, ensure that the virtual machine has the exact number of storage controllers needed and set the storage controller count accordingly.
16871701

16881702
After importing, you should run `terraform plan`. Unless you have changed anything else in the configuration that would cause other attributes to change. The only difference should be configuration-only changes, which are typically comprised of:
16891703

1690-
* The [`imported`](#imported) flag will transition from `true` to `false`.
1704+
- The [`imported`](#imported) flag will transition from `true` to `false`.
16911705

1692-
* The [`keep_on_remove`](#keep_on_remove) of known disks will transition from `true` to `false`.
1706+
- The [`keep_on_remove`](#keep_on_remove) of known disks will transition from `true` to `false`.
16931707

1694-
* Configuration supplied in the [`clone`](#clone) block, if present, will be persisted to state. This initial persistence operation does not perform any cloning or customization actions, nor does it force a new resource. After the first apply operation, further changes to `clone` will force the creation of a new resource.
1708+
- Configuration supplied in the [`clone`](#clone) block, if present, will be persisted to state. This initial persistence operation does not perform any cloning or customization actions, nor does it force a new resource. After the first apply operation, further changes to `clone` will force the creation of a new resource.
16951709

16961710
~> **NOTE:** Do not make any configuration changes to `clone` after importing or upgrading from a legacy version of the provider before doing an initial `terraform apply` as these changes will not correctly force a new resource and your changes will have persisted to state, preventing further plans from correctly triggering a diff.
16971711

0 commit comments

Comments
 (0)