Ready to level-up your engineering skills? Join a Pulumi Workshop. Register Now

getDistributedVirtualSwitch

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

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

Example Usage

using Pulumi;
using VSphere = Pulumi.VSphere;

class MyStack : Stack
{
    public MyStack()
    {
        var datacenter = Output.Create(VSphere.GetDatacenter.InvokeAsync(new VSphere.GetDatacenterArgs
        {
            Name = "dc1",
        }));
        var dvs = datacenter.Apply(datacenter => Output.Create(VSphere.GetDistributedVirtualSwitch.InvokeAsync(new VSphere.GetDistributedVirtualSwitchArgs
        {
            DatacenterId = datacenter.Id,
            Name = "test-dvs",
        })));
        var pg = new VSphere.DistributedPortGroup("pg", new VSphere.DistributedPortGroupArgs
        {
            ActiveUplinks = 
            {
                dvs.Apply(dvs => dvs.Uplinks[0]),
            },
            DistributedVirtualSwitchUuid = dvs.Apply(dvs => dvs.Id),
            StandbyUplinks = 
            {
                dvs.Apply(dvs => dvs.Uplinks[1]),
            },
        });
    }

}
package main

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

func main() {
    pulumi.Run(func(ctx *pulumi.Context) error {
        opt0 := "dc1"
        datacenter, err := vsphere.LookupDatacenter(ctx, &vsphere.LookupDatacenterArgs{
            Name: &opt0,
        }, nil)
        if err != nil {
            return err
        }
        opt1 := datacenter.Id
        dvs, err := vsphere.LookupDistributedVirtualSwitch(ctx, &vsphere.LookupDistributedVirtualSwitchArgs{
            DatacenterId: &opt1,
            Name:         "test-dvs",
        }, nil)
        if err != nil {
            return err
        }
        _, err = vsphere.NewDistributedPortGroup(ctx, "pg", &vsphere.DistributedPortGroupArgs{
            ActiveUplinks: pulumi.StringArray{
                pulumi.String(dvs.Uplinks[0]),
            },
            DistributedVirtualSwitchUuid: pulumi.String(dvs.Id),
            StandbyUplinks: pulumi.StringArray{
                pulumi.String(dvs.Uplinks[1]),
            },
        })
        if err != nil {
            return err
        }
        return nil
    })
}
import pulumi
import pulumi_vsphere as vsphere

datacenter = vsphere.get_datacenter(name="dc1")
dvs = vsphere.get_distributed_virtual_switch(datacenter_id=datacenter.id,
    name="test-dvs")
pg = vsphere.DistributedPortGroup("pg",
    active_uplinks=[dvs.uplinks[0]],
    distributed_virtual_switch_uuid=dvs.id,
    standby_uplinks=[dvs.uplinks[1]])
import * as pulumi from "@pulumi/pulumi";
import * as vsphere from "@pulumi/vsphere";

const datacenter = pulumi.output(vsphere.getDatacenter({
    name: "dc1",
}, { async: true }));
const dvs = datacenter.apply(datacenter => vsphere.getDistributedVirtualSwitch({
    datacenterId: datacenter.id,
    name: "test-dvs",
}, { async: true }));
const pg = new vsphere.DistributedPortGroup("pg", {
    activeUplinks: [dvs.apply(dvs => dvs.uplinks[0])],
    distributedVirtualSwitchUuid: dvs.id,
    standbyUplinks: [dvs.apply(dvs => dvs.uplinks[1])],
});

Using getDistributedVirtualSwitch

function getDistributedVirtualSwitch(args: GetDistributedVirtualSwitchArgs, opts?: InvokeOptions): Promise<GetDistributedVirtualSwitchResult>
def get_distributed_virtual_switch(datacenter_id: Optional[str] = None, name: Optional[str] = None, opts: Optional[InvokeOptions] = None) -> GetDistributedVirtualSwitchResult
func LookupDistributedVirtualSwitch(ctx *Context, args *LookupDistributedVirtualSwitchArgs, opts ...InvokeOption) (*LookupDistributedVirtualSwitchResult, error)

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

public static class GetDistributedVirtualSwitch {
    public static Task<GetDistributedVirtualSwitchResult> InvokeAsync(GetDistributedVirtualSwitchArgs args, InvokeOptions? opts = null)
}

The following arguments are supported:

Name string

The name of the distributed virtual switch. This can be a name or path.

DatacenterId string

The managed object reference ID of the datacenter the DVS 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 string

The name of the distributed virtual switch. This can be a name or path.

DatacenterId string

The managed object reference ID of the datacenter the DVS 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 string

The name of the distributed virtual switch. This can be a name or path.

datacenterId string

The managed object reference ID of the datacenter the DVS 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 str

The name of the distributed virtual switch. This can be a name or path.

datacenter_id str

The managed object reference ID of the datacenter the DVS 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>
DatacenterId string
Id string

The provider-assigned unique ID for this managed resource.

Name string
Uplinks []string
DatacenterId string
id string

The provider-assigned unique ID for this managed resource.

name string
uplinks string[]
datacenterId string
id str

The provider-assigned unique ID for this managed resource.

name str
uplinks Sequence[str]
datacenter_id str

Package Details

Repository
https://github.com/pulumi/pulumi-vsphere
License
Apache-2.0
Notes
This Pulumi package is based on the vsphere Terraform Provider.