1. Packages
  2. Vsphere Provider
  3. API Docs
  4. getDistributedVirtualSwitch
vSphere v4.13.1 published on Wednesday, Feb 5, 2025 by Pulumi

vsphere.getDistributedVirtualSwitch

Explore with Pulumi AI

The vsphere.DistributedVirtualSwitch data source can be used to discover the ID and uplink data of a of a vSphere distributed switch (VDS). This can then be used with resources or data sources that require a VDS, such as the vsphere.DistributedPortGroup resource, for which an example is shown below.

NOTE: This data source requires vCenter Server and is not available on direct ESXi host connections.

Example Usage

The following example locates a distributed switch named vds-01, in the datacenter dc-01. It then uses this distributed switch to set up a vsphere.DistributedPortGroup resource that uses the first uplink as a primary uplink and the second uplink as a secondary.

import * as pulumi from "@pulumi/pulumi";
import * as vsphere from "@pulumi/vsphere";

const datacenter = vsphere.getDatacenter({
    name: "dc-01",
});
const vds = datacenter.then(datacenter => vsphere.getDistributedVirtualSwitch({
    name: "vds-01",
    datacenterId: datacenter.id,
}));
const dvpg = new vsphere.DistributedPortGroup("dvpg", {
    name: "dvpg-01",
    distributedVirtualSwitchUuid: vds.then(vds => vds.id),
    activeUplinks: [vds.then(vds => vds.uplinks?.[0])],
    standbyUplinks: [vds.then(vds => vds.uplinks?.[1])],
});
Copy
import pulumi
import pulumi_vsphere as vsphere

datacenter = vsphere.get_datacenter(name="dc-01")
vds = vsphere.get_distributed_virtual_switch(name="vds-01",
    datacenter_id=datacenter.id)
dvpg = vsphere.DistributedPortGroup("dvpg",
    name="dvpg-01",
    distributed_virtual_switch_uuid=vds.id,
    active_uplinks=[vds.uplinks[0]],
    standby_uplinks=[vds.uplinks[1]])
Copy
package main

import (
	"github.com/pulumi/pulumi-vsphere/sdk/v4/go/vsphere"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		datacenter, err := vsphere.LookupDatacenter(ctx, &vsphere.LookupDatacenterArgs{
			Name: pulumi.StringRef("dc-01"),
		}, nil)
		if err != nil {
			return err
		}
		vds, err := vsphere.LookupDistributedVirtualSwitch(ctx, &vsphere.LookupDistributedVirtualSwitchArgs{
			Name:         "vds-01",
			DatacenterId: pulumi.StringRef(datacenter.Id),
		}, nil)
		if err != nil {
			return err
		}
		_, err = vsphere.NewDistributedPortGroup(ctx, "dvpg", &vsphere.DistributedPortGroupArgs{
			Name:                         pulumi.String("dvpg-01"),
			DistributedVirtualSwitchUuid: pulumi.String(vds.Id),
			ActiveUplinks: pulumi.StringArray{
				pulumi.String(vds.Uplinks[0]),
			},
			StandbyUplinks: pulumi.StringArray{
				pulumi.String(vds.Uplinks[1]),
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using VSphere = Pulumi.VSphere;

return await Deployment.RunAsync(() => 
{
    var datacenter = VSphere.GetDatacenter.Invoke(new()
    {
        Name = "dc-01",
    });

    var vds = VSphere.GetDistributedVirtualSwitch.Invoke(new()
    {
        Name = "vds-01",
        DatacenterId = datacenter.Apply(getDatacenterResult => getDatacenterResult.Id),
    });

    var dvpg = new VSphere.DistributedPortGroup("dvpg", new()
    {
        Name = "dvpg-01",
        DistributedVirtualSwitchUuid = vds.Apply(getDistributedVirtualSwitchResult => getDistributedVirtualSwitchResult.Id),
        ActiveUplinks = new[]
        {
            vds.Apply(getDistributedVirtualSwitchResult => getDistributedVirtualSwitchResult.Uplinks[0]),
        },
        StandbyUplinks = new[]
        {
            vds.Apply(getDistributedVirtualSwitchResult => getDistributedVirtualSwitchResult.Uplinks[1]),
        },
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.vsphere.VsphereFunctions;
import com.pulumi.vsphere.inputs.GetDatacenterArgs;
import com.pulumi.vsphere.inputs.GetDistributedVirtualSwitchArgs;
import com.pulumi.vsphere.DistributedPortGroup;
import com.pulumi.vsphere.DistributedPortGroupArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        final var datacenter = VsphereFunctions.getDatacenter(GetDatacenterArgs.builder()
            .name("dc-01")
            .build());

        final var vds = VsphereFunctions.getDistributedVirtualSwitch(GetDistributedVirtualSwitchArgs.builder()
            .name("vds-01")
            .datacenterId(datacenter.applyValue(getDatacenterResult -> getDatacenterResult.id()))
            .build());

        var dvpg = new DistributedPortGroup("dvpg", DistributedPortGroupArgs.builder()
            .name("dvpg-01")
            .distributedVirtualSwitchUuid(vds.applyValue(getDistributedVirtualSwitchResult -> getDistributedVirtualSwitchResult.id()))
            .activeUplinks(vds.applyValue(getDistributedVirtualSwitchResult -> getDistributedVirtualSwitchResult.uplinks()[0]))
            .standbyUplinks(vds.applyValue(getDistributedVirtualSwitchResult -> getDistributedVirtualSwitchResult.uplinks()[1]))
            .build());

    }
}
Copy
resources:
  dvpg:
    type: vsphere:DistributedPortGroup
    properties:
      name: dvpg-01
      distributedVirtualSwitchUuid: ${vds.id}
      activeUplinks:
        - ${vds.uplinks[0]}
      standbyUplinks:
        - ${vds.uplinks[1]}
variables:
  datacenter:
    fn::invoke:
      function: vsphere:getDatacenter
      arguments:
        name: dc-01
  vds:
    fn::invoke:
      function: vsphere:getDistributedVirtualSwitch
      arguments:
        name: vds-01
        datacenterId: ${datacenter.id}
Copy

Using getDistributedVirtualSwitch

Two invocation forms are available. The direct form accepts plain arguments and either blocks until the result value is available, or returns a Promise-wrapped result. The output form accepts Input-wrapped arguments and returns an Output-wrapped result.

function getDistributedVirtualSwitch(args: GetDistributedVirtualSwitchArgs, opts?: InvokeOptions): Promise<GetDistributedVirtualSwitchResult>
function getDistributedVirtualSwitchOutput(args: GetDistributedVirtualSwitchOutputArgs, opts?: InvokeOptions): Output<GetDistributedVirtualSwitchResult>
Copy
def get_distributed_virtual_switch(datacenter_id: Optional[str] = None,
                                   name: Optional[str] = None,
                                   opts: Optional[InvokeOptions] = None) -> GetDistributedVirtualSwitchResult
def get_distributed_virtual_switch_output(datacenter_id: Optional[pulumi.Input[str]] = None,
                                   name: Optional[pulumi.Input[str]] = None,
                                   opts: Optional[InvokeOptions] = None) -> Output[GetDistributedVirtualSwitchResult]
Copy
func LookupDistributedVirtualSwitch(ctx *Context, args *LookupDistributedVirtualSwitchArgs, opts ...InvokeOption) (*LookupDistributedVirtualSwitchResult, error)
func LookupDistributedVirtualSwitchOutput(ctx *Context, args *LookupDistributedVirtualSwitchOutputArgs, opts ...InvokeOption) LookupDistributedVirtualSwitchResultOutput
Copy

> Note: This function is named LookupDistributedVirtualSwitch in the Go SDK.

public static class GetDistributedVirtualSwitch 
{
    public static Task<GetDistributedVirtualSwitchResult> InvokeAsync(GetDistributedVirtualSwitchArgs args, InvokeOptions? opts = null)
    public static Output<GetDistributedVirtualSwitchResult> Invoke(GetDistributedVirtualSwitchInvokeArgs args, InvokeOptions? opts = null)
}
Copy
public static CompletableFuture<GetDistributedVirtualSwitchResult> getDistributedVirtualSwitch(GetDistributedVirtualSwitchArgs args, InvokeOptions options)
public static Output<GetDistributedVirtualSwitchResult> getDistributedVirtualSwitch(GetDistributedVirtualSwitchArgs args, InvokeOptions options)
Copy
fn::invoke:
  function: vsphere:index/getDistributedVirtualSwitch:getDistributedVirtualSwitch
  arguments:
    # arguments dictionary
Copy

The following arguments are supported:

Name This property is required. string
The name of the VDS. This can be a name or path.
DatacenterId string
The managed object reference ID of the datacenter the VDS is located in. This can be omitted if the search path used in name is an absolute path. For default datacenters, use the id attribute from an empty vsphere.Datacenter data source.
Name This property is required. string
The name of the VDS. This can be a name or path.
DatacenterId string
The managed object reference ID of the datacenter the VDS is located in. This can be omitted if the search path used in name is an absolute path. For default datacenters, use the id attribute from an empty vsphere.Datacenter data source.
name This property is required. String
The name of the VDS. This can be a name or path.
datacenterId String
The managed object reference ID of the datacenter the VDS is located in. This can be omitted if the search path used in name is an absolute path. For default datacenters, use the id attribute from an empty vsphere.Datacenter data source.
name This property is required. string
The name of the VDS. This can be a name or path.
datacenterId string
The managed object reference ID of the datacenter the VDS is located in. This can be omitted if the search path used in name is an absolute path. For default datacenters, use the id attribute from an empty vsphere.Datacenter data source.
name This property is required. str
The name of the VDS. This can be a name or path.
datacenter_id str
The managed object reference ID of the datacenter the VDS is located in. This can be omitted if the search path used in name is an absolute path. For default datacenters, use the id attribute from an empty vsphere.Datacenter data source.
name This property is required. String
The name of the VDS. This can be a name or path.
datacenterId String
The managed object reference ID of the datacenter the VDS is located in. This can be omitted if the search path used in name is an absolute path. For default datacenters, use the id attribute from an empty vsphere.Datacenter data source.

getDistributedVirtualSwitch Result

The following output properties are available:

Id string
The provider-assigned unique ID for this managed resource.
Name string
Uplinks List<string>
The list of the uplinks on this vSphere distributed switch, as per the uplinks argument to the vsphere.DistributedVirtualSwitch resource.
DatacenterId string
Id string
The provider-assigned unique ID for this managed resource.
Name string
Uplinks []string
The list of the uplinks on this vSphere distributed switch, as per the uplinks argument to the vsphere.DistributedVirtualSwitch resource.
DatacenterId string
id String
The provider-assigned unique ID for this managed resource.
name String
uplinks List<String>
The list of the uplinks on this vSphere distributed switch, as per the uplinks argument to the vsphere.DistributedVirtualSwitch resource.
datacenterId String
id string
The provider-assigned unique ID for this managed resource.
name string
uplinks string[]
The list of the uplinks on this vSphere distributed switch, as per the uplinks argument to the vsphere.DistributedVirtualSwitch resource.
datacenterId string
id str
The provider-assigned unique ID for this managed resource.
name str
uplinks Sequence[str]
The list of the uplinks on this vSphere distributed switch, as per the uplinks argument to the vsphere.DistributedVirtualSwitch resource.
datacenter_id str
id String
The provider-assigned unique ID for this managed resource.
name String
uplinks List<String>
The list of the uplinks on this vSphere distributed switch, as per the uplinks argument to the vsphere.DistributedVirtualSwitch resource.
datacenterId String

Package Details

Repository
vSphere pulumi/pulumi-vsphere
License
Apache-2.0
Notes
This Pulumi package is based on the vsphere Terraform Provider.