Infrastructure as Code: Deploying distributed switch

 Deploying a VMware vSphere Distributed Switch (VDS) using Terraform and add the VLANs 200, 201, 202, 203, and 204 with two uplink NICs:

provider "vsphere" {
  user           = "your-username"
  password       = "your-password"
  vsphere_server = "your-vsphere-server"

  # If you have a self-signed cert
  allow_unverified_ssl = true
}

resource "vsphere_distributed_virtual_switch" "dvs" {
  name                 = "MyDistributedSwitch"
  datacenter_id        = data.vsphere_datacenter.dc.id
  uplink_portgroup_num = 2  # Number of uplink NICs

  # Define the uplink port group
  uplink_portgroup {
    name = "Uplink1"
  }

  uplink_portgroup {
    name = "Uplink2"
  }
}

resource "vsphere_distributed_port_group" "vlan_200" {
  name                   = "VLAN_200"
  distributed_switch_uuid = vsphere_distributed_virtual_switch.dvs.id
  vlan_id                = 200
  active_uplinks         = "Uplink1", "Uplink2"
}

resource "vsphere_distributed_port_group" "vlan_201" {
  name                   = "VLAN_201"
  distributed_switch_uuid = vsphere_distributed_virtual_switch.dvs.id
  vlan_id                = 201
  active_uplinks         = "Uplink1", "Uplink2"
}

resource "vsphere_distributed_port_group" "vlan_202" {
  name                   = "VLAN_202"
  distributed_switch_uuid = vsphere_distributed_virtual_switch.dvs.id
  vlan_id                = 202
  active_uplinks         = "Uplink1", "Uplink2"
}

resource "vsphere_distributed_port_group" "vlan_203" {
  name                   = "VLAN_203"
  distributed_switch_uuid = vsphere_distributed_virtual_switch.dvs.id
  vlan_id                = 203
  active_uplinks         = "Uplink1", "Uplink2"
}

resource "vsphere_distributed_port_group" "vlan_204" {
  name                   = "VLAN_204"
  distributed_switch_uuid = vsphere_distributed_virtual_switch.dvs.id
  vlan_id                = 204
  active_uplinks         = "Uplink1", "Uplink2"
}

data "vsphere_datacenter" "dc" {
  name = "YourDatacenterName"
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Share on Social Media