### Comprehensive Hyper-V Resource Provisioning with Terraform Source: https://github.com/taliesins/terraform-provider-hyperv/blob/master/docs/data-sources/machine_instance.md This example demonstrates the full lifecycle of provisioning Hyper-V resources using the Terraform Hyper-V provider. It includes provider configuration, creation of an internal network switch, definition of a virtual hard disk (VHDX), and the setup of a Hyper-V virtual machine instance with detailed configurations for firmware, processor, integration services, and network adaptors. ```terraform terraform { required_providers { hyperv = { source = "taliesins/hyperv" version = ">= 1.0.3" } } } provider "hyperv" { } resource "hyperv_network_switch" "dmz_network_switch" { name = "DMZ" notes = "" allow_management_os = true enable_embedded_teaming = false enable_iov = false enable_packet_direct = false minimum_bandwidth_mode = "None" switch_type = "Internal" net_adapter_names = [] default_flow_minimum_bandwidth_absolute = 0 default_flow_minimum_bandwidth_weight = 0 default_queue_vmmq_enabled = false default_queue_vmmq_queue_pairs = 16 default_queue_vrss_enabled = false } resource "hyperv_vhd" "web_server_g2_vhd" { path = "c:\\web_server\\web_server_g2.vhdx" #Needs to be absolute path size = 10737418240 #10GB } resource "hyperv_machine_instance" "default" { name = "WebServer" generation = 2 automatic_critical_error_action = "Pause" automatic_critical_error_action_timeout = 30 automatic_start_action = "StartIfRunning" automatic_start_delay = 0 automatic_stop_action = "Save" checkpoint_type = "Production" guest_controlled_cache_types = false high_memory_mapped_io_space = 536870912 lock_on_disconnect = "Off" low_memory_mapped_io_space = 134217728 memory_maximum_bytes = 1099511627776 memory_minimum_bytes = 536870912 memory_startup_bytes = 536870912 notes = "" processor_count = 1 smart_paging_file_path = "C:\\ProgramData\\Microsoft\\Windows\\Hyper-V" snapshot_file_location = "C:\\ProgramData\\Microsoft\\Windows\\Hyper-V" #dynamic_memory = false static_memory = true state = "Running" # Configure firmware vm_firmware { enable_secure_boot = "Off" #secure_boot_template = "" preferred_network_boot_protocol = "IPv4" console_mode = "None" pause_after_boot_failure = "Off" boot_order { boot_type = "HardDiskDrive" controller_number = "0" controller_location = "0" } boot_order { boot_type = "NetworkAdapter" network_adapter_name = "wan" } } # Configure processor vm_processor { compatibility_for_migration_enabled = false compatibility_for_older_operating_systems_enabled = false hw_thread_count_per_core = 0 maximum = 100 reserve = 0 relative_weight = 100 maximum_count_per_numa_node = 0 maximum_count_per_numa_socket = 0 enable_host_resource_protection = false expose_virtualization_extensions = false } # Configure integration services integration_services = { "Guest Service Interface" = false "Heartbeat" = true "Key-Value Pair Exchange" = true "Shutdown" = true "Time Synchronization" = true "VSS" = true } # Create a network adaptor network_adaptors { name = "wan" switch_name = hyperv_network_switch.dmz_network_switch.name management_os = false is_legacy = false dynamic_mac_address = true static_mac_address = "" mac_address_spoofing = "Off" dhcp_guard = "Off" router_guard = "Off" port_mirroring = "None" ieee_priority_tag = "Off" vmq_weight = 100 iov_queue_pairs_requested = 1 iov_interrupt_moderation = "Off" iov_weight = 100 ipsec_offload_maximum_security_association = 512 maximum_bandwidth = 0 minimum_bandwidth_absolute = 0 minimum_bandwidth_weight = 0 } } ``` -------------------------------- ### Terraform Example: Retrieve Hyper-V VHD Information Source: https://github.com/taliesins/terraform-provider-hyperv/blob/master/docs/data-sources/vhd.md This example demonstrates how to configure the `hyperv` provider, define a `hyperv_vhd` resource to create or manage a VHD, and then use the `hyperv_vhd` data source to retrieve information about that VHD, outputting its details. It showcases typical provider and resource/data source declaration patterns. ```terraform terraform { required_providers { hyperv = { source = "taliesins/hyperv" version = ">= 1.0.3" } } } provider "hyperv" { } resource "hyperv_vhd" "web_server_vhd" { path = "c:\\web_server\\web_server_g2.vhdx" #source = "" #source_vm = "" #source_disk = 0 vhd_type = "Dynamic" #parent_path = "" size = 10737418240 #10GB #block_size = 0 #logical_sector_size = 0 #physical_sector_size = 0 } data "hyperv_vhd" "web_server_vhd" { path = hyperv_vhd.web_server_vhd.path } output "hyperv_vhd" { value = data.hyperv_vhd.web_server_vhd } ``` -------------------------------- ### Nested Schema for vm_firmware.boot_order Source: https://github.com/taliesins/terraform-provider-hyperv/blob/master/docs/data-sources/machine_instance.md Defines the specific boot device configuration within the vm_firmware schema, including boot type and controller details. ```APIDOC vm_firmware.boot_order: Required: boot_type (String): The type of boot device. Valid values to use are NetworkAdapter, HardDiskDrive and DvdDrive. Optional: controller_location (Number): Specifies the number of the location on the controller at which the hard disk drive or dvd drive. controller_number (Number): Specifies the number of the controller to which the hard disk drive or dvd drive. mac_address (String): Specifies the mac address of ethernet adapter. network_adapter_name (String): Specifies the name of ethernet adapter. path (String): Specifies the file path of hard disk drive or dvd drive. switch_name (String): Specifies the name of ethernet adapter switch. ``` -------------------------------- ### Nested Schema for vm_firmware Source: https://github.com/taliesins/terraform-provider-hyperv/blob/master/docs/data-sources/machine_instance.md Defines the firmware configuration for a Hyper-V virtual machine, including boot order, console mode, secure boot settings, and network boot preferences. ```APIDOC vm_firmware: Optional: boot_order (Block List): The boot order of the devices that the generation 2 virtual machine should try to use for boot up. (see nestedblock--vm_firmware--boot_order) console_mode (String): Specifies the console mode type for the virtual machine. This parameter allows a virtual machine to run without graphical user interface. Valid values to use are Default, COM1, COM2, None. enable_secure_boot (String): Specifies whether to enable secure boot. Valid values to use are On, Off. pause_after_boot_failure (String): Specifies the behavior of the virtual machine after a start failure. For a value of On, if the virtual machine fails to start correctly from a device, the virtual machine is paused. Valid values to use are On, Off. preferred_network_boot_protocol (String): Specifies the IP protocol version to use during a network boot. Valid values to use are IPv4, IPv6. secure_boot_template (String): Specifies the name of the secure boot template. If secure boot is enabled, you must have a valid secure boot template for the guest operating system to start. Example values to use are MicrosoftWindows, MicrosoftUEFICertificateAuthority, OpenSourceShieldedVM. ``` -------------------------------- ### Terraform Provider VM Firmware Nested Schema Placeholder Source: https://github.com/taliesins/terraform-provider-hyperv/blob/master/docs/resources/machine_instance.md Indicates a placeholder for the nested schema definition related to virtual machine firmware settings. Actual details are not provided in the current text. ```APIDOC Nested Schema: vm_firmware (Details not provided in current documentation) ``` -------------------------------- ### Nested Schema for dvd_drives Source: https://github.com/taliesins/terraform-provider-hyperv/blob/master/docs/data-sources/machine_instance.md Defines the configuration parameters for a virtual DVD drive within Hyper-V, including controller location and optional path or resource pool association. ```APIDOC dvd_drives: Required: controller_location (Number): Specifies the number of the location on the controller at which the DVD drive is to be added. controller_number (Number): Specifies the number of the controller to which the DVD drive is to be added. Optional: path (String): Specifies the full path to the virtual hard disk file or physical hard disk volume for the added DVD drive. resource_pool_name (String): Specifies the friendly name of the ISO resource pool to which this DVD drive is to be associated. ``` -------------------------------- ### Terraform Hyper-V Provider: vm_firmware Nested Schema Source: https://github.com/taliesins/terraform-provider-hyperv/blob/master/docs/resources/machine_instance.md Defines the configuration options for a Hyper-V virtual machine's firmware settings, including boot order, console mode, secure boot, and network boot protocols. ```APIDOC vm_firmware: boot_order (Block List, Optional): The boot order of the devices that the generation 2 virtual machine should try to use for boot up. console_mode (String, Optional): Specifies the console mode type for the virtual machine. Valid values: Default, COM1, COM2, None. enable_secure_boot (String, Optional): Specifies whether to enable secure boot. Valid values: On, Off. pause_after_boot_failure (String, Optional): Specifies the behavior of the virtual machine after a start failure. Valid values: On, Off. preferred_network_boot_protocol (String, Optional): Specifies the IP protocol version to use during a network boot. Valid values: IPv4, IPv6. secure_boot_template (String, Optional): Specifies the name of the secure boot template. Example values: MicrosoftWindows, MicrosoftUEFICertificateAuthority, OpenSourceShieldedVM. ``` -------------------------------- ### Hyper-V Machine Instance Schema Definition Source: https://github.com/taliesins/terraform-provider-hyperv/blob/master/docs/data-sources/machine_instance.md This API documentation defines the schema for the `hyperv_machine_instance` resource or data source, specifically detailing the required `name` attribute as a String. ```APIDOC ## Schema ### Required - `name` (String) The name of the virtual machine. ``` -------------------------------- ### Terraform Hyper-V Provider: vm_firmware.boot_order Nested Schema Source: https://github.com/taliesins/terraform-provider-hyperv/blob/master/docs/resources/machine_instance.md Defines the individual boot order entries for a Hyper-V virtual machine's firmware, specifying the boot device type and optional controller/network details. ```APIDOC vm_firmware.boot_order: boot_type (String, Required): The type of boot device. Valid values: NetworkAdapter, HardDiskDrive, DvdDrive. controller_location (Number, Optional): Specifies the number of the location on the controller at which the hard disk drive or dvd drive. controller_number (Number, Optional): Specifies the number of the controller to which the hard disk drive or dvd drive. mac_address (String, Optional): Specifies the mac address of ethernet adapter. network_adapter_name (String, Optional): Specifies the name of ethernet adapter. path (String, Optional): Specifies the file path of hard disk drive or dvd drive. switch_name (String, Optional): Specifies the name of ethernet adapter switch. ``` -------------------------------- ### Hyper-V Network Adaptor Configuration Schema Source: https://github.com/taliesins/terraform-provider-hyperv/blob/master/docs/resources/machine_instance.md Defines the structure and properties available for configuring virtual network adapters in Hyper-V environments, including settings for teaming, MAC addressing, bandwidth management, and SR-IOV. ```APIDOC network_adaptors: Required: - name (String): Specifies the name for the virtual network adapter. Optional: - allow_teaming (String): Specifies whether the virtual network adapter can be teamed with other network adapters connected to the same virtual switch. Valid values to use are `On`, `Off`. - device_naming (String): Specifies whether this adapter uses device naming. Valid values to use are `On`, `Off`. - dhcp_guard (String): Specifies whether to drop DHCP messages from a virtual machine claiming to be a DHCP server. Valid values to use are `On`, `Off`. - dynamic_ip_address_limit (Number): Specifies the dynamic IP address limit. - dynamic_mac_address (Boolean): Assigns a dynamically generated MAC address to the virtual network adapter. - fix_speed_10g (String): Specifies whether the adapter uses fix speed of 10G. Valid values to use are `On`, `Off`. - ieee_priority_tag (String): Specifies whether IEEE 802.1p tagged packets from the virtual machine should be trusted. If it is on, the IEEE 802.1p tagged packets will be let go as is. If it is off, the priority value is reset to 0. Valid values to use are `On`, `Off`. - iov_interrupt_moderation (String): Specifies the interrupt moderation value for a single-root I/O virtualization (SR-IOV) virtual function assigned to a virtual network adapter. If Default is chosen, the value is determined by the physical network adapter vendor's setting. If Adaptive is chosen, the interrupt moderation rate will be based on the runtime traffic pattern. Valid values to use are `Default`, `Adaptive`, `Off`, `Low `, `Medium`, `High`. - iov_queue_pairs_requested (Number): Specifies the number of hardware queue pairs to be allocated to an SR-IOV virtual function. If receive-side scaling (RSS) is required, and if the physical network adapter that binds to the virtual switch supports RSS on SR-IOV virtual functions, then more than one queue pair is required. Valid values to use are between `1` to `4294967295`. - iov_weight (Number): Specifies whether single-root I/O virtualization (SR-IOV) is to be enabled on this virtual network adapter. The relative weight sets the affinity of the virtual network adapter to the assigned SR-IOV virtual function. Specify 0 to disable SR-IOV on the virtual network adapter. Valid values to use are between `0` to `100`. - ipsec_offload_maximum_security_association (Number): Specifies the maximum number of security associations that can be offloaded to the physical network adapter that is bound to the virtual switch and that supports IPSec Task Offload. Specify zero to disable the feature. - is_legacy (Boolean): Specifies whether the virtual network adapter is the legacy type. - mac_address_spoofing (String): Specifies whether virtual machines may change the source MAC address in outgoing packets to one not assigned to them. On allows the virtual machine to use a different MAC address. Off only allows the virtual machine to use the MAC address assigned to it. Valid values to use are `On`, `Off`. - management_os (Boolean): Specifies the virtual network adapter in the management operating system to be configured. - mandatory_feature_id (Set of String): Specifies the unique identifiers of the virtual switch extension features that are required for this virtual network adapter to operate. - maximum_bandwidth (Number): Specifies the maximum bandwidth, in bits per second, for the virtual network adapter. The specified value is rounded to the nearest multiple of eight. Specify zero to disable the feature. - minimum_bandwidth_absolute (Number): Specifies the minimum bandwidth, in bits per second, for the virtual network adapter. The specified value is rounded to the nearest multiple of eight. A value larger than 100 Mbps is recommended. - minimum_bandwidth_weight (Number): Specifies the minimum bandwidth, in terms of relative weight, for the virtual network adapter. The weight describes how much bandwidth to provide to the virtual network adapter relative to other virtual network adapters connected to the same virtual switch. Specify 0 to disable the feature. Valid values to use are between `0` to `100`. - not_monitored_in_cluster (Boolean): Indicates whether to not monitor the network adapter if the virtual machine that it belongs to is part of a cluster. By default, network adapters for clustered virtual machines are monitored. - packet_direct_moderation_count (Number): Specifies the number of packets to wait for before signaling an interrupt. - packet_direct_moderation_interval (Number): Specifies the amount of time, in milliseconds, to wait before signaling an interrupt after a packet arrives. - packet_direct_num_procs (Number): Specifies the number of processors to use for virtual switch processing inside of the host. ``` -------------------------------- ### Provision Hyper-V Resources with Terraform Source: https://github.com/taliesins/terraform-provider-hyperv/blob/master/docs/resources/machine_instance.md This Terraform configuration sets up the Hyper-V provider and defines multiple Hyper-V resources. It includes creating an ISO image from a local directory, configuring an internal network switch, defining a virtual hard disk (VHDX), and provisioning a Generation 2 virtual machine instance with detailed settings for firmware, processor, integration services, and network adapters. ```terraform terraform { required_providers { hyperv = { source = "taliesins/hyperv" version = ">= 1.0.3" } } } provider "hyperv" { } data "archive_file" "bootstrap" { type = "zip" source_dir = "bootstrap" output_path = "bootstrap.zip" } resource "hyperv_iso_image" "bootstrap" { volume_name = "BOOTSTRAP" source_zip_file_path = data.archive_file.bootstrap.output_path source_zip_file_path_hash = data.archive_file.bootstrap.output_sha destination_iso_file_path = "c:\\web_server\\bootstrap.iso" iso_media_type = "dvdplusrw_duallayer" iso_file_system_type = "unknown" } resource "hyperv_network_switch" "dmz_network_switch" { name = "DMZ" notes = "" allow_management_os = true enable_embedded_teaming = false enable_iov = false enable_packet_direct = false minimum_bandwidth_mode = "None" switch_type = "Internal" net_adapter_names = [] default_flow_minimum_bandwidth_absolute = 0 default_flow_minimum_bandwidth_weight = 0 default_queue_vmmq_enabled = false default_queue_vmmq_queue_pairs = 16 default_queue_vrss_enabled = false } resource "hyperv_vhd" "web_server_g2_vhd" { path = "c:\\web_server\\web_server_g2.vhdx" #Needs to be absolute path size = 10737418240 #10GB } resource "hyperv_machine_instance" "default" { name = "WebServer" generation = 2 automatic_critical_error_action = "Pause" automatic_critical_error_action_timeout = 30 automatic_start_action = "StartIfRunning" automatic_start_delay = 0 automatic_stop_action = "Save" checkpoint_type = "Production" guest_controlled_cache_types = false high_memory_mapped_io_space = 536870912 lock_on_disconnect = "Off" low_memory_mapped_io_space = 134217728 memory_maximum_bytes = 1099511627776 memory_minimum_bytes = 536870912 memory_startup_bytes = 536870912 notes = "" processor_count = 1 smart_paging_file_path = "C:\\ProgramData\\Microsoft\\Windows\\Hyper-V" snapshot_file_location = "C:\\ProgramData\\Microsoft\\Windows\\Hyper-V" #dynamic_memory = false static_memory = true state = "Running" # Configure firmware vm_firmware { enable_secure_boot = "Off" #secure_boot_template = "" preferred_network_boot_protocol = "IPv4" console_mode = "None" pause_after_boot_failure = "Off" boot_order { boot_type = "HardDiskDrive" controller_number = "0" controller_location = "0" } boot_order { boot_type = "NetworkAdapter" network_adapter_name = "wan" } } # Configure processor vm_processor { compatibility_for_migration_enabled = false compatibility_for_older_operating_systems_enabled = false hw_thread_count_per_core = 0 maximum = 100 reserve = 0 relative_weight = 100 maximum_count_per_numa_node = 0 maximum_count_per_numa_socket = 0 enable_host_resource_protection = false expose_virtualization_extensions = false } # Configure integration services integration_services = { "Guest Service Interface" = false "Heartbeat" = true "Key-Value Pair Exchange" = true "Shutdown" = true "Time Synchronization" = true "VSS" = true } # Create a network adaptor network_adaptors { name = "wan" switch_name = hyperv_network_switch.dmz_network_switch.name management_os = false is_legacy = false dynamic_mac_address = true static_mac_address = "" mac_address_spoofing = "Off" dhcp_guard = "Off" router_guard = "Off" port_mirroring = "None" } ``` -------------------------------- ### Nested Schema for vm_processor Source: https://github.com/taliesins/terraform-provider-hyperv/blob/master/docs/data-sources/machine_instance.md Defines the processor configuration for a Hyper-V virtual machine, including compatibility settings, resource protection, and NUMA node configurations. ```APIDOC vm_processor: Optional: compatibility_for_migration_enabled (Boolean): Specifies whether the virtual processor's features are to be limited for compatibility when migrating the virtual machine to another host. compatibility_for_older_operating_systems_enabled (Boolean): Specifies whether the virtual processor's features are to be limited for compatibility with older operating systems. enable_host_resource_protection (Boolean): Specifies whether to enable host resource protection on the virtual machine. When enabled, the host will enforce limits on some aspects of the virtual machine's activity, preventing excessive consumption of host compute resources. VM activities controlled by this setting include the VMbus pipe messages associated with a subset of the VM's virtual devices, and intercepts generated by the VM. The virtual devices affected include the video, keyboard, mouse, and dynamic memory VDEVs. expose_virtualization_extensions (Boolean): Specifies whether the hypervisor should expose the presence of virtualization extensions to the virtual machine, which enables support for nested virtualization. hw_thread_count_per_core (Number): Specifies the number of virtual SMT threads exposed to the virtual machine. Setting this value to 0 indicates the virtual machine will inherit the host's number of threads per core. This setting may not exceed the host's number of threads per core. Note: Windows Server 2016 does not support setting HwThreadCountPerCore to 0. For more details, see Configuring VM SMT settings using PowerShell. maximum (Number): Specifies the maximum percentage of resources available to the virtual machine processor to be configured. Allowed values range from 0 to 100. maximum_count_per_numa_node (Number): Specifies the maximum number of processors per NUMA node to be configured for the virtual machine. maximum_count_per_numa_socket (Number): Specifies the maximum number of sockets per NUMA node to be configured for the virtual machine. relative_weight (Number): Specifies the priority for allocating the physical computer's processing power to this virtual machine relative to others. Allowed values range from 1 to 10000. reserve (Number): Specifies the percentage of processor resources to be reserved for this virtual machine. Allowed values range from 0 to 100. ``` -------------------------------- ### Nested Schema for DVD Drives Source: https://github.com/taliesins/terraform-provider-hyperv/blob/master/docs/resources/machine_instance.md Defines the properties for configuring DVD drives within a Hyper-V virtual machine resource. It specifies required controller details and optional path and resource pool associations. ```APIDOC dvd_drives: controller_location (Number): Specifies the number of the location on the controller at which the DVD drive is to be added. (Required) controller_number (Number): Specifies the number of the controller to which the DVD drive is to be added. (Required) path (String): Specifies the full path to the virtual hard disk file or physical hard disk volume for the added DVD drive. (Optional) resource_pool_name (String): Specifies the friendly name of the ISO resource pool to which this DVD drive is to be associated. (Optional) ``` -------------------------------- ### Look Up Hyper-V Machine Instance Data Source: https://github.com/taliesins/terraform-provider-hyperv/blob/master/docs/data-sources/machine_instance.md This HCL snippet shows how to use the `hyperv_machine_instance` data source to retrieve information about an existing virtual machine instance by its name, typically for referencing in other configurations. ```HCL data "hyperv_machine_instance" "default" { name = hyperv_machine_instance.default.name } ``` -------------------------------- ### Output Hyper-V Machine Instance Data Source: https://github.com/taliesins/terraform-provider-hyperv/blob/master/docs/data-sources/machine_instance.md This HCL snippet defines an output variable that exposes the data retrieved from the `hyperv_machine_instance` data source, making it accessible to other Terraform configurations or for display after applying. ```HCL output "hyperv_machine_instance" { value = data.hyperv_machine_instance.default } ``` -------------------------------- ### Configure Hyper-V Virtual Machine Network Adapters, DVD, and Hard Disks Source: https://github.com/taliesins/terraform-provider-hyperv/blob/master/docs/data-sources/machine_instance.md This HCL snippet demonstrates how to define network adapter settings, DVD drives, and hard disk drives within a Hyper-V virtual machine resource. It includes various properties for network features, storage controllers, and disk paths. ```HCL mandatory_feature_id = [] resource_pool_name = "" test_replica_pool_name = "" test_replica_switch_name = "" virtual_subnet_id = 0 allow_teaming = "On" not_monitored_in_cluster = false storm_limit = 0 dynamic_ip_address_limit = 0 device_naming = "Off" fix_speed_10g = "Off" packet_direct_num_procs = 0 packet_direct_moderation_count = 0 packet_direct_moderation_interval = 0 vrss_enabled = true vmmq_enabled = false vmmq_queue_pairs = 16 } # Create dvd drive dvd_drives { controller_number = "0" controller_location = "1" path = "" #path = "c:/iso/windows-server-2016.iso" resource_pool_name = "" } # Create a hard disk drive hard_disk_drives { controller_type = "Scsi" controller_number = "0" controller_location = "0" path = hyperv_vhd.web_server_g2_vhd.path disk_number = 4294967295 resource_pool_name = "Primordial" support_persistent_reservations = false maximum_iops = 0 minimum_iops = 0 qos_policy_id = "00000000-0000-0000-0000-000000000000" override_cache_attributes = "Default" } ``` -------------------------------- ### Example Usage for hyperv_network_switch Data Source Source: https://github.com/taliesins/terraform-provider-hyperv/blob/master/docs/data-sources/network_switch.md This Terraform configuration demonstrates how to define the `hyperv` provider, create a `hyperv_network_switch` resource, and then use the `hyperv_network_switch` data source to retrieve its properties. It also shows how to output the data source's value. ```terraform terraform { required_providers { hyperv = { source = "taliesins/hyperv" version = ">= 1.0.3" } } } provider "hyperv" { } resource "hyperv_network_switch" "default" { name = "DMZ" notes = "" allow_management_os = true enable_embedded_teaming = false enable_iov = false enable_packet_direct = false minimum_bandwidth_mode = "None" switch_type = "Internal" net_adapter_names = [] default_flow_minimum_bandwidth_absolute = 0 default_flow_minimum_bandwidth_weight = 0 default_queue_vmmq_enabled = false default_queue_vmmq_queue_pairs = 16 default_queue_vrss_enabled = false } data "hyperv_network_switch" "default" { name = hyperv_network_switch.default.name } output "hyperv_network_switch" { value = data.hyperv_network_switch.default } ``` -------------------------------- ### Nested Schema for hard_disk_drives Source: https://github.com/taliesins/terraform-provider-hyperv/blob/master/docs/data-sources/machine_instance.md Defines the configuration parameters for a virtual hard disk drive within Hyper-V, including controller details, disk number, IOPS settings, caching attributes, and QoS policy. ```APIDOC hard_disk_drives: Required: controller_location (Number): Specifies the number of the location on the controller at which the hard disk drive is to be added. controller_number (Number): Specifies the number of the controller to which the hard disk drive is to be added. Optional: controller_type (String): Specifies the type of the controller to which the hard disk drive is to be added. Valid values to use are `Ide`, `Scsi`. disk_number (Number): Specifies the disk number of the offline physical hard drive to be connected as a passthrough disk. If value is 4294967295 then disk number is ignored. maximum_iops (Number): Specifies the maximum normalized I/O operations per second (IOPS) for the hard disk. Hyper-V calculates normalized IOPS as the total size of I/O per second divided by 8 KB. If value is 0 then iops is ignored. minimum_iops (Number): Specifies the minimum normalized I/O operations per second (IOPS) for the hard disk. Hyper-V calculates normalized IOPS as the total size of I/O per second divided by 8 KB. If maximum iops value is 0 then iops is ignored. override_cache_attributes (String): With Default it is equivalent of WriteCacheDisabled. With WriteCacheEnabled write I/O is acknowledged as written before it is committed to stable media. If your internal disks, DAS, SAN, or NAS has a battery backup system that can guarantee clean cache flushes on a power outage, write caching is generally safe. Internal batteries that report their status and/or automatically disable caching are best. UPS-backed systems are sometimes OK, but they are not foolproof. With WriteCacheAndFUAEnabled write I/O is committed to stable media BEFORE the I/O is acknowledged as written. With WriteCacheDisabled when I/O is written it is acknowledged as written as there is no cache in between. Valid values to use are `Default`, `WriteCacheEnabled`, `WriteCacheAndFUAEnabled`, `WriteCacheDisabled`. path (String): Specifies the full path of the hard disk drive file to be added. qos_policy_id (String): Specifies the unique ID for a storage QoS policy that this cmdlet associates with the hard disk drive. If value is 00000000-0000-0000-0000-000000000000 then qos policy id is ignored. resource_pool_name (String): Specifies the friendly name of the resource pool to which this virtual hard disk is to be associated. support_persistent_reservations (Boolean): Indicates that the hard disk supports SCSI persistent reservation semantics. Specify this parameter when the hard disk is a shared disk that is used by multiple virtual machines. ``` -------------------------------- ### Hyper-V Virtual Machine Optional Configuration Properties Source: https://github.com/taliesins/terraform-provider-hyperv/blob/master/docs/resources/machine_instance.md Defines the optional configuration parameters that can be set for a Hyper-V virtual machine resource in Terraform. These properties control various aspects of VM behavior, memory, storage, and networking. ```APIDOC automatic_critical_error_action (String) Specifies the action to take when the VM encounters a critical error, and exceeds the timeout duration specified by the AutomaticCriticalErrorActionTimeout cmdlet. Valid values to use are `Pause`, `None`. automatic_critical_error_action_timeout (Number) Specifies the amount of time, in minutes, to wait in critical pause before powering off the virtual machine. automatic_start_action (String) Specifies the action the virtual machine is to take upon start. Valid values to use are `Nothing`, `StartIfRunning`, `Start`. automatic_start_delay (Number) Specifies the number of seconds by which the virtual machine's start should be delayed. automatic_stop_action (String) Specifies the action the virtual machine is to take when the virtual machine host shuts down. Valid values to use are `TurnOff`, `Save`, `ShutDown`. checkpoint_type (String) Allows you to configure the type of checkpoints created by Hyper-V. If `Disabled` is specified, block creation of checkpoints. If `Standard` is specified, create standard checkpoints. If `Production` is specified, create production checkpoints if supported by guest operating system. Otherwise, create standard checkpoints. If `ProductionOnly` is specified, create production checkpoints if supported by guest operating system. Otherwise, the operation fails. Valid values to use are `Disabled`, `Standard`, `Production`, `ProductionOnly`. dvd_drives (Block List) (see [below for nested schema](#nestedblock--dvd_drives)) dynamic_memory (Boolean) Specifies if machine instance will have dynamic memory enabled. generation (Number) Specifies the generation, as an integer, for the virtual machine. Valid values to use are `1`, `2`. guest_controlled_cache_types (Boolean) Specifies if the machine instance will use guest controlled cache types. hard_disk_drives (Block List) (see [below for nested schema](#nestedblock--hard_disk_drives)) high_memory_mapped_io_space (Number) integration_services (Map of Boolean) lock_on_disconnect (String) Specifies whether virtual machine connection in basic mode locks the console after a user disconnects. Valid values to use are `On`, `Off`. low_memory_mapped_io_space (Number) memory_maximum_bytes (Number) Specifies the maximum amount of memory that the virtual machine is to be allocated. (Applies only to virtual machines using dynamic memory.) memory_minimum_bytes (Number) Specifies the minimum amount of memory that the virtual machine is to be allocated. (Applies only to virtual machines using dynamic memory.) memory_startup_bytes (Number) Specifies the amount of memory that the virtual machine is to be allocated upon startup. (If the virtual machine does not use dynamic memory, then this is the static amount of memory to be allocated.) network_adaptors (Block List) (see [below for nested schema](#nestedblock--network_adaptors)) notes (String) Specifies a note to be associated with the machine to be created. path (String) The path of the virtual machine. processor_count (Number) Specifies the number of virtual processors for the virtual machine. smart_paging_file_path (String) Specifies the folder in which the Smart Paging file is to be stored. snapshot_file_location (String) Specifies the folder in which the virtual machine is to store its snapshot files. state (String) Valid values to use are `Running`, `Off`. Specifies if the machine instance will be running or off. static_memory (Boolean) Specifies if the machine instance will use static memory. timeouts (Block, Optional) (see [below for nested schema](#nestedblock--timeouts)) vm_firmware (Block List, Max: 1) (see [below for nested schema](#nestedblock--vm_firmware)) vm_processor (Block List, Max: 1) (see [below for nested schema](#nestedblock--vm_processor)) wait_for_ips_poll_period (Number) The amount of time in seconds to wait between trying to get ip addresses for network cards on the virtual machine. wait_for_ips_timeout (Number) The amount of time in seconds to wait before throwing an exception when trying to get ip addresses for network cards on the virtual machine. wait_for_state_poll_period (Number) The amount of time in seconds to wait between trying to change for the virtual machine to the desired state. wait_for_state_timeout (Number) The amount of time in seconds to wait before throwing an exception when trying to change for the virtual machine to the desired state. ``` -------------------------------- ### Hyper-V Virtual Network Adapter Configuration Parameters Source: https://github.com/taliesins/terraform-provider-hyperv/blob/master/docs/data-sources/machine_instance.md Defines the configurable and read-only parameters for a Hyper-V virtual network adapter resource in the Terraform provider. This includes network-specific settings, performance tuning options, and replication-related properties. ```APIDOC port_mirroring (String) Specifies the port mirroring mode for the network adapter to be configured. If a virtual network adapter is configured as Source, every packet it sends or receives is copied and forwarded to a virtual network adapter configured to receive the packets. If a virtual network adapter is configured as Destination, it receives copied packets from the source virtual network adapter. The source and destination virtual network adapters must be connected to the same virtual switch. Specify None to disable the feature. Valid values: None, Source, Destination ``` ```APIDOC resource_pool_name (String) Specifies the name of the resource pool. ``` ```APIDOC router_guard (String) Specifies whether to drop Router Advertisement and Redirection messages from unauthorized virtual machines. If On is specified, such messages are dropped. If Off is specified, such messages are sent. Valid values: On, Off ``` ```APIDOC static_mac_address (String) Assigns a specific a MAC addresss to the virtual network adapter. ``` ```APIDOC storm_limit (Number) Specifies the number of broadcast, multicast, and unknown unicast packets per second a virtual machine is allowed to send through the specified virtual network adapter. Broadcast, multicast, and unknown unicast packets beyond the limit during that one second interval are dropped. A value of zero (0) means there is no limit. ``` ```APIDOC switch_name (String) Specifies the name of the virtual switch to connect to the new network adapter. If the switch name is not unique, then the operation fails. ``` ```APIDOC test_replica_pool_name (String) This parameter applies only to virtual machines that are enabled for replication. It specifies the name of the network resource pool that will be used by this virtual network adapter when its virtual machine is created during a test failover. ``` ```APIDOC test_replica_switch_name (String) This parameter applies only to virtual machines that are enabled for replication. It specifies the name of the virtual switch to which the virtual network adapter should be connected when its virtual machine is created during a test failover. ``` ```APIDOC virtual_subnet_id (Number) Specifies the virtual subnet ID to use with Hyper-V Network Virtualization. Use 0 to clear this parameter. Valid values: 0 or between 4096 to 16777215 (2^24 - 1) ``` ```APIDOC vlan_access (Boolean) ``` ```APIDOC vlan_id (Number) ``` ```APIDOC vmmq_enabled (Boolean) Should Virtual Machine Multi-Queue be enabled. With set to true multiple queues are allocated to a single VM with each queue affinitized to a core in the VM. ``` ```APIDOC vmmq_queue_pairs (Number) The number of Virtual Machine Multi-Queues to create for this VM. ``` ```APIDOC vmq_weight (Number) Specifies whether virtual machine queue (VMQ) is to be enabled on the virtual network adapter. The relative weight describes the affinity of the virtual network adapter to use VMQ. Specify 0 to disable VMQ on the virtual network adapter. Valid values: between 1 to 100 ``` ```APIDOC vrss_enabled (Boolean) Should Virtual Receive Side Scaling be enabled. This configuration allows the load from a virtual network adapter to be distributed across multiple virtual processors in a virtual machine (VM), allowing the VM to process more network traffic more rapidly than it can with a single logical processor. ``` ```APIDOC wait_for_ips (Boolean) Wait for the network card to be assigned an ip address. ``` ```APIDOC ip_addresses (List of String) - Read-Only The current list of IP addresses on this machine. If HyperV integration tools is not running on the virtual machine, or if the VM is powered off, or has not been assigned an ip address, this list will be empty. ``` ```APIDOC Nested Schema: timeouts read (String) - Optional ``` -------------------------------- ### Hyper-V Virtual Machine Resource Schema Definition Source: https://github.com/taliesins/terraform-provider-hyperv/blob/master/docs/resources/machine_instance.md This API documentation defines the schema for the Hyper-V virtual machine resource in Terraform. It specifies the required attributes, such as the 'name' of the virtual machine, along with its type and description. ```APIDOC ## Schema ### Required - `name` (String) Specifies the name of the new virtual machine. ``` -------------------------------- ### Hyper-V Virtual Network Adapter Configuration Properties Source: https://github.com/taliesins/terraform-provider-hyperv/blob/master/docs/resources/machine_instance.md Defines the configurable attributes for a virtual network adapter resource in the Terraform Hyper-V provider, including network settings, performance features, and replication options. It also lists read-only attributes. ```APIDOC port_mirroring (String) Description: Specifies the port mirroring mode for the network adapter to be configured. If a virtual network adapter is configured as Source, every packet it sends or receives is copied and forwarded to a virtual network adapter configured to receive the packets. If a virtual network adapter is configured as Destination, it receives copied packets from the source virtual network adapter. The source and destination virtual network adapters must be connected to the same virtual switch. Specify None to disable the feature. Valid values: "None", "Source", "Destination" resource_pool_name (String) Description: Specifies the name of the resource pool. router_guard (String) Description: Specifies whether to drop Router Advertisement and Redirection messages from unauthorized virtual machines. If On is specified, such messages are dropped. If Off is specified, such messages are sent. Valid values: "On", "Off" static_mac_address (String) Description: Assigns a specific a MAC addresss to the virtual network adapter. storm_limit (Number) Description: Specifies the number of broadcast, multicast, and unknown unicast packets per second a virtual machine is allowed to send through the specified virtual network adapter. Broadcast, multicast, and unknown unicast packets beyond the limit during that one second interval are dropped. A value of zero (0) means there is no limit. switch_name (String) Description: Specifies the name of the virtual switch to connect to the new network adapter. If the switch name is not unique, then the operation fails. test_replica_pool_name (String) Description: This parameter applies only to virtual machines that are enabled for replication. It specifies the name of the network resource pool that will be used by this virtual network adapter when its virtual machine is created during a test failover. test_replica_switch_name (String) Description: This parameter applies only to virtual machines that are enabled for replication. It specifies the name of the virtual switch to which the virtual network adapter should be connected when its virtual machine is created during a test failover. virtual_subnet_id (Number) Description: Specifies the virtual subnet ID to use with Hyper-V Network Virtualization. Use 0 to clear this parameter. Valid values: "0" or between "4096" to "16777215" (2^24 - 1) vlan_access (Boolean) vlan_id (Number) vmmq_enabled (Boolean) Description: Should Virtual Machine Multi-Queue be enabled. With set to true multiple queues are allocated to a single VM with each queue affinitized to a core in the VM. vmmq_queue_pairs (Number) Description: The number of Virtual Machine Multi-Queues to create for this VM. vmq_weight (Number) Description: Specifies whether virtual machine queue (VMQ) is to be enabled on the virtual network adapter. The relative weight describes the affinity of the virtual network adapter to use VMQ. Specify 0 to disable VMQ on the virtual network adapter. Valid values: between "1" to "100" vrss_enabled (Boolean) Description: Should Virtual Receive Side Scaling be enabled. This configuration allows the load from a virtual network adapter to be distributed across multiple virtual processors in a virtual machine (VM), allowing the VM to process more network traffic more rapidly than it can with a single logical processor. wait_for_ips (Boolean) Description: Wait for the network card to be assigned an ip address. Read-Only Properties: ip_addresses (List of String) Description: The current list of IP addresses on this machine. If HyperV integration tools is not running on the virtual machine, or if the VM is powered off, or has not been assigned an ip address, this list will be empty. ``` -------------------------------- ### Create HyperV Resources (Switch, VHD, Machine) Source: https://github.com/taliesins/terraform-provider-hyperv/blob/master/docs/index.md This snippet shows examples of declaring common HyperV resources using the `hyperv` Terraform provider, such as a network switch, a virtual hard disk (VHD), and a virtual machine instance. ```terraform resource "hyperv_network_switch" "dmz" { } # Create a vhd resource "hyperv_vhd" "webserver" { } # Create a machine resource "hyperv_machine_instance" "webserver" { } ``` -------------------------------- ### Attach DVD Drive to Hyper-V Virtual Machine Source: https://github.com/taliesins/terraform-provider-hyperv/blob/master/docs/resources/machine_instance.md This HCL snippet defines a DVD drive attachment for a Hyper-V virtual machine. It specifies the controller location and the path to the ISO image to be mounted, typically from a `hyperv_iso_image` resource. ```HCL dvd_drives { controller_number = "0" controller_location = "1" //path = "" path = hyperv_iso_image.bootstrap.destination_file_path resource_pool_name = "" } ``` -------------------------------- ### Configure Hyper-V VM Network Adapter and General Properties Source: https://github.com/taliesins/terraform-provider-hyperv/blob/master/docs/resources/machine_instance.md This HCL snippet configures various advanced properties for a Hyper-V virtual machine, including network adapter settings like QoS, SR-IOV, packet direct options, and other general VM attributes. These settings optimize network performance and resource allocation. ```HCL ieee_priority_tag = "Off" vmq_weight = 100 iov_queue_pairs_requested = 1 iov_interrupt_moderation = "Off" iov_weight = 100 ipsec_offload_maximum_security_association = 512 maximum_bandwidth = 0 minimum_bandwidth_absolute = 0 minimum_bandwidth_weight = 0 mandatory_feature_id = [] resource_pool_name = "" test_replica_pool_name = "" test_replica_switch_name = "" virtual_subnet_id = 0 allow_teaming = "On" not_monitored_in_cluster = false storm_limit = 0 dynamic_ip_address_limit = 0 device_naming = "Off" fix_speed_10g = "Off" packet_direct_num_procs = 0 packet_direct_moderation_count = 0 packet_direct_moderation_interval = 0 vrss_enabled = true vmmq_enabled = false vmmq_queue_pairs = 16 ```