provider "vsphere" { user = var.user password = var.password vsphere_server = var.vsphere_server # If you have a self-signed cert allow_unverified_ssl = true } data "vsphere_datacenter" "dc" { name = var.vsphere_datacenter } data "vsphere_host" "host" { count = length(var.esxi_hosts) name = var.esxi_hosts[count.index] datacenter_id = data.vsphere_datacenter.dc.id } //vMotion-FT-Management vSwitch Configuration //To create and set up the VMkernel ports and port groups on each management server resource "vsphere_distributed_virtual_switch" "vMotion_FT_Mgmt_DSwitch" { name = "vMotion_FT_Mgmt_DSwitch" datacenter_id = "${data.vsphere_datacenter.dc.id}" network_resource_control_enabled = true max_mtu = 9000 uplinks = ["uplink1", "uplink2", "uplink3", "uplink4"] active_uplinks = ["uplink1", "uplink2"] standby_uplinks = ["uplink3", "uplink4"] // Adding Management host and selecting the second Nic in use by vswitch0 step12 a to e host { host_system_id = data.vsphere_host.host.0.id devices = ["${var.network_interfaces[1]}"] } } //Adding 4 Port Groups to the DSwitch crated resource "vsphere_distributed_port_group" "FT_Mgmt_vMotion_DPortGroup" { for_each = var.DPortGroups name = each.value.name distributed_virtual_switch_uuid = "${vsphere_distributed_virtual_switch.vMotion_FT_Mgmt_DSwitch.id}" type = each.value.type //"earlyBinding" vlan_id = each.value.vlan_id //need to check and change accordingly number_of_ports = each.value.number_of_ports active_uplinks = ["uplink1", "uplink2"] } //Migrating mgmt uplink from VSS to vMotion_FT_Mgmt_DSwitch steps import this to migrate we will have to import this resource to fetch the details of existing config resource "vsphere_vnic" "v1" { for_each = {for no_of_host in data.vsphere_host.host : no_of_host.id => no_of_host } host = each.key //host = data.vsphere_host.host.0.id distributed_switch_port = vsphere_distributed_virtual_switch.vMotion_FT_Mgmt_DSwitch.id distributed_port_group = vsphere_distributed_port_group.FT_Mgmt_vMotion_DPortGroup["Management_Kernel"].id ipv4 { dhcp="true" } } //import this to remove vSwitch0 after the migration. resource "vsphere_host_virtual_switch" "switch" { for_each = {for no_of_host in data.vsphere_host.host : no_of_host.id => no_of_host } host_system_id = each.key name = "vSwitch0" //host_system_id = "${data.vsphere_host.host.0.id}" network_adapters = ["vmnic4"] active_nics = ["vmnic4"] standby_nics = [] allow_forged_transmits = false allow_mac_changes = false }