1. Packages
  2. Vsphere Provider
  3. API Docs
  4. getNetwork
vSphere v4.12.1 published on Tuesday, Oct 22, 2024 by Pulumi

vsphere.getNetwork

Explore with Pulumi AI

vsphere logo
vSphere v4.12.1 published on Tuesday, Oct 22, 2024 by Pulumi

    The vsphere.getNetwork data source can be used to discover the ID of a network in vSphere. This can be any network that can be used as the backing for a network interface for vsphere.VirtualMachine or any other vSphere resource that requires a network. This includes standard (host-based) port groups, distributed port groups, or opaque networks such as those managed by NSX.

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as vsphere from "@pulumi/vsphere";
    
    const datacenter = vsphere.getDatacenter({
        name: "dc-01",
    });
    const network = datacenter.then(datacenter => vsphere.getNetwork({
        name: "VM Network",
        datacenterId: datacenter.id,
    }));
    
    import pulumi
    import pulumi_vsphere as vsphere
    
    datacenter = vsphere.get_datacenter(name="dc-01")
    network = vsphere.get_network(name="VM Network",
        datacenter_id=datacenter.id)
    
    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
    		}
    		_, err = vsphere.GetNetwork(ctx, &vsphere.GetNetworkArgs{
    			Name:         "VM Network",
    			DatacenterId: pulumi.StringRef(datacenter.Id),
    		}, nil)
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    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 network = VSphere.GetNetwork.Invoke(new()
        {
            Name = "VM Network",
            DatacenterId = datacenter.Apply(getDatacenterResult => getDatacenterResult.Id),
        });
    
    });
    
    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.GetNetworkArgs;
    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 network = VsphereFunctions.getNetwork(GetNetworkArgs.builder()
                .name("VM Network")
                .datacenterId(datacenter.applyValue(getDatacenterResult -> getDatacenterResult.id()))
                .build());
    
        }
    }
    
    variables:
      datacenter:
        fn::invoke:
          Function: vsphere:getDatacenter
          Arguments:
            name: dc-01
      network:
        fn::invoke:
          Function: vsphere:getNetwork
          Arguments:
            name: VM Network
            datacenterId: ${datacenter.id}
    

    Additional Examples

    import * as pulumi from "@pulumi/pulumi";
    import * as vsphere from "@pulumi/vsphere";
    
    const datacenter = vsphere.getDatacenter({
        name: "dc-01",
    });
    const myPortGroup = datacenter.then(datacenter => vsphere.getNetwork({
        datacenterId: datacenter.id,
        name: "VM Network",
        filters: [{
            networkType: "Network",
        }],
    }));
    
    import pulumi
    import pulumi_vsphere as vsphere
    
    datacenter = vsphere.get_datacenter(name="dc-01")
    my_port_group = vsphere.get_network(datacenter_id=datacenter.id,
        name="VM Network",
        filters=[{
            "network_type": "Network",
        }])
    
    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
    		}
    		_, err = vsphere.GetNetwork(ctx, &vsphere.GetNetworkArgs{
    			DatacenterId: pulumi.StringRef(datacenter.Id),
    			Name:         "VM Network",
    			Filters: []vsphere.GetNetworkFilter{
    				{
    					NetworkType: pulumi.StringRef("Network"),
    				},
    			},
    		}, nil)
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    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 myPortGroup = VSphere.GetNetwork.Invoke(new()
        {
            DatacenterId = datacenter.Apply(getDatacenterResult => getDatacenterResult.Id),
            Name = "VM Network",
            Filters = new[]
            {
                new VSphere.Inputs.GetNetworkFilterInputArgs
                {
                    NetworkType = "Network",
                },
            },
        });
    
    });
    
    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.GetNetworkArgs;
    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 myPortGroup = VsphereFunctions.getNetwork(GetNetworkArgs.builder()
                .datacenterId(datacenter.applyValue(getDatacenterResult -> getDatacenterResult.id()))
                .name("VM Network")
                .filters(GetNetworkFilterArgs.builder()
                    .networkType("Network")
                    .build())
                .build());
    
        }
    }
    
    variables:
      datacenter:
        fn::invoke:
          Function: vsphere:getDatacenter
          Arguments:
            name: dc-01
      myPortGroup:
        fn::invoke:
          Function: vsphere:getNetwork
          Arguments:
            datacenterId: ${datacenter.id}
            name: VM Network
            filters:
              - networkType: Network
    

    Using getNetwork

    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 getNetwork(args: GetNetworkArgs, opts?: InvokeOptions): Promise<GetNetworkResult>
    function getNetworkOutput(args: GetNetworkOutputArgs, opts?: InvokeOptions): Output<GetNetworkResult>
    def get_network(datacenter_id: Optional[str] = None,
                    distributed_virtual_switch_uuid: Optional[str] = None,
                    filters: Optional[Sequence[GetNetworkFilter]] = None,
                    name: Optional[str] = None,
                    opts: Optional[InvokeOptions] = None) -> GetNetworkResult
    def get_network_output(datacenter_id: Optional[pulumi.Input[str]] = None,
                    distributed_virtual_switch_uuid: Optional[pulumi.Input[str]] = None,
                    filters: Optional[pulumi.Input[Sequence[pulumi.Input[GetNetworkFilterArgs]]]] = None,
                    name: Optional[pulumi.Input[str]] = None,
                    opts: Optional[InvokeOptions] = None) -> Output[GetNetworkResult]
    func GetNetwork(ctx *Context, args *GetNetworkArgs, opts ...InvokeOption) (*GetNetworkResult, error)
    func GetNetworkOutput(ctx *Context, args *GetNetworkOutputArgs, opts ...InvokeOption) GetNetworkResultOutput

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

    public static class GetNetwork 
    {
        public static Task<GetNetworkResult> InvokeAsync(GetNetworkArgs args, InvokeOptions? opts = null)
        public static Output<GetNetworkResult> Invoke(GetNetworkInvokeArgs args, InvokeOptions? opts = null)
    }
    public static CompletableFuture<GetNetworkResult> getNetwork(GetNetworkArgs args, InvokeOptions options)
    // Output-based functions aren't available in Java yet
    
    fn::invoke:
      function: vsphere:index/getNetwork:getNetwork
      arguments:
        # arguments dictionary

    The following arguments are supported:

    Name string
    The name of the network. This can be a name or path.
    DatacenterId string
    The managed object reference ID of the datacenter the network 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.
    DistributedVirtualSwitchUuid string
    For distributed port group type network objects, the ID of the distributed virtual switch for which the port group belongs. It is useful to differentiate port groups with same name using the distributed virtual switch ID.
    Filters List<Pulumi.VSphere.Inputs.GetNetworkFilter>
    Apply a filter for the discovered network.
    Name string
    The name of the network. This can be a name or path.
    DatacenterId string
    The managed object reference ID of the datacenter the network 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.
    DistributedVirtualSwitchUuid string
    For distributed port group type network objects, the ID of the distributed virtual switch for which the port group belongs. It is useful to differentiate port groups with same name using the distributed virtual switch ID.
    Filters []GetNetworkFilter
    Apply a filter for the discovered network.
    name String
    The name of the network. This can be a name or path.
    datacenterId String
    The managed object reference ID of the datacenter the network 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.
    distributedVirtualSwitchUuid String
    For distributed port group type network objects, the ID of the distributed virtual switch for which the port group belongs. It is useful to differentiate port groups with same name using the distributed virtual switch ID.
    filters List<GetNetworkFilter>
    Apply a filter for the discovered network.
    name string
    The name of the network. This can be a name or path.
    datacenterId string
    The managed object reference ID of the datacenter the network 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.
    distributedVirtualSwitchUuid string
    For distributed port group type network objects, the ID of the distributed virtual switch for which the port group belongs. It is useful to differentiate port groups with same name using the distributed virtual switch ID.
    filters GetNetworkFilter[]
    Apply a filter for the discovered network.
    name str
    The name of the network. This can be a name or path.
    datacenter_id str
    The managed object reference ID of the datacenter the network 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.
    distributed_virtual_switch_uuid str
    For distributed port group type network objects, the ID of the distributed virtual switch for which the port group belongs. It is useful to differentiate port groups with same name using the distributed virtual switch ID.
    filters Sequence[GetNetworkFilter]
    Apply a filter for the discovered network.
    name String
    The name of the network. This can be a name or path.
    datacenterId String
    The managed object reference ID of the datacenter the network 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.
    distributedVirtualSwitchUuid String
    For distributed port group type network objects, the ID of the distributed virtual switch for which the port group belongs. It is useful to differentiate port groups with same name using the distributed virtual switch ID.
    filters List<Property Map>
    Apply a filter for the discovered network.

    getNetwork Result

    The following output properties are available:

    Id string
    The provider-assigned unique ID for this managed resource.
    Name string
    Type string
    The managed object type for the discovered network. This will be one of DistributedVirtualPortgroup for distributed port groups, Network for standard (host-based) port groups, or OpaqueNetwork for networks managed externally, such as those managed by NSX.
    DatacenterId string
    DistributedVirtualSwitchUuid string
    Filters List<Pulumi.VSphere.Outputs.GetNetworkFilter>
    Id string
    The provider-assigned unique ID for this managed resource.
    Name string
    Type string
    The managed object type for the discovered network. This will be one of DistributedVirtualPortgroup for distributed port groups, Network for standard (host-based) port groups, or OpaqueNetwork for networks managed externally, such as those managed by NSX.
    DatacenterId string
    DistributedVirtualSwitchUuid string
    Filters []GetNetworkFilter
    id String
    The provider-assigned unique ID for this managed resource.
    name String
    type String
    The managed object type for the discovered network. This will be one of DistributedVirtualPortgroup for distributed port groups, Network for standard (host-based) port groups, or OpaqueNetwork for networks managed externally, such as those managed by NSX.
    datacenterId String
    distributedVirtualSwitchUuid String
    filters List<GetNetworkFilter>
    id string
    The provider-assigned unique ID for this managed resource.
    name string
    type string
    The managed object type for the discovered network. This will be one of DistributedVirtualPortgroup for distributed port groups, Network for standard (host-based) port groups, or OpaqueNetwork for networks managed externally, such as those managed by NSX.
    datacenterId string
    distributedVirtualSwitchUuid string
    filters GetNetworkFilter[]
    id str
    The provider-assigned unique ID for this managed resource.
    name str
    type str
    The managed object type for the discovered network. This will be one of DistributedVirtualPortgroup for distributed port groups, Network for standard (host-based) port groups, or OpaqueNetwork for networks managed externally, such as those managed by NSX.
    datacenter_id str
    distributed_virtual_switch_uuid str
    filters Sequence[GetNetworkFilter]
    id String
    The provider-assigned unique ID for this managed resource.
    name String
    type String
    The managed object type for the discovered network. This will be one of DistributedVirtualPortgroup for distributed port groups, Network for standard (host-based) port groups, or OpaqueNetwork for networks managed externally, such as those managed by NSX.
    datacenterId String
    distributedVirtualSwitchUuid String
    filters List<Property Map>

    Supporting Types

    GetNetworkFilter

    NetworkType string
    This is required if you have multiple port groups with the same name. This will be one of DistributedVirtualPortgroup for distributed port groups, Network for standard (host-based) port groups, or OpaqueNetwork for networks managed externally, such as those managed by NSX.
    NetworkType string
    This is required if you have multiple port groups with the same name. This will be one of DistributedVirtualPortgroup for distributed port groups, Network for standard (host-based) port groups, or OpaqueNetwork for networks managed externally, such as those managed by NSX.
    networkType String
    This is required if you have multiple port groups with the same name. This will be one of DistributedVirtualPortgroup for distributed port groups, Network for standard (host-based) port groups, or OpaqueNetwork for networks managed externally, such as those managed by NSX.
    networkType string
    This is required if you have multiple port groups with the same name. This will be one of DistributedVirtualPortgroup for distributed port groups, Network for standard (host-based) port groups, or OpaqueNetwork for networks managed externally, such as those managed by NSX.
    network_type str
    This is required if you have multiple port groups with the same name. This will be one of DistributedVirtualPortgroup for distributed port groups, Network for standard (host-based) port groups, or OpaqueNetwork for networks managed externally, such as those managed by NSX.
    networkType String
    This is required if you have multiple port groups with the same name. This will be one of DistributedVirtualPortgroup for distributed port groups, Network for standard (host-based) port groups, or OpaqueNetwork for networks managed externally, such as those managed by NSX.

    Package Details

    Repository
    vSphere pulumi/pulumi-vsphere
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the vsphere Terraform Provider.
    vsphere logo
    vSphere v4.12.1 published on Tuesday, Oct 22, 2024 by Pulumi