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

Vnic

Provides a VMware vSphere vnic resource.

Importing

An existing vNic can be imported into this resource via supplying the vNic’s ID. An example is below:

import * as pulumi from "@pulumi/pulumi";
import pulumi
using Pulumi;

class MyStack : Stack
{
    public MyStack()
    {
    }

}
package main

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

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		return nil
	})
}

The above would import the vnic vmk2 from host with ID host-123.

Example Usage

Create a vnic attached to a distributed virtual switch using the vmotion TCP/IP stack

using Pulumi;
using VSphere = Pulumi.VSphere;

class MyStack : Stack
{
    public MyStack()
    {
        var dc = Output.Create(VSphere.GetDatacenter.InvokeAsync(new VSphere.GetDatacenterArgs
        {
            Name = "mydc",
        }));
        var h1 = dc.Apply(dc => Output.Create(VSphere.GetHost.InvokeAsync(new VSphere.GetHostArgs
        {
            Name = "esxi1.host.test",
            DatacenterId = dc.Id,
        })));
        var d1 = new VSphere.DistributedVirtualSwitch("d1", new VSphere.DistributedVirtualSwitchArgs
        {
            DatacenterId = dc.Apply(dc => dc.Id),
            Hosts = 
            {
                new VSphere.Inputs.DistributedVirtualSwitchHostArgs
                {
                    HostSystemId = h1.Apply(h1 => h1.Id),
                    Devices = 
                    {
                        "vnic3",
                    },
                },
            },
        });
        var p1 = new VSphere.DistributedPortGroup("p1", new VSphere.DistributedPortGroupArgs
        {
            VlanId = 1234,
            DistributedVirtualSwitchUuid = d1.Id,
        });
        var v1 = new VSphere.Vnic("v1", new VSphere.VnicArgs
        {
            Host = h1.Apply(h1 => h1.Id),
            DistributedSwitchPort = d1.Id,
            DistributedPortGroup = p1.Id,
            Ipv4 = new VSphere.Inputs.VnicIpv4Args
            {
                Dhcp = true,
            },
            Netstack = "vmotion",
        });
    }

}
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 := "mydc"
        dc, err := vsphere.LookupDatacenter(ctx, &vsphere.LookupDatacenterArgs{
            Name: &opt0,
        }, nil)
        if err != nil {
            return err
        }
        opt1 := "esxi1.host.test"
        h1, err := vsphere.LookupHost(ctx, &vsphere.LookupHostArgs{
            Name:         &opt1,
            DatacenterId: dc.Id,
        }, nil)
        if err != nil {
            return err
        }
        d1, err := vsphere.NewDistributedVirtualSwitch(ctx, "d1", &vsphere.DistributedVirtualSwitchArgs{
            DatacenterId: pulumi.String(dc.Id),
            Hosts: vsphere.DistributedVirtualSwitchHostArray{
                &vsphere.DistributedVirtualSwitchHostArgs{
                    HostSystemId: pulumi.String(h1.Id),
                    Devices: pulumi.StringArray{
                        pulumi.String("vnic3"),
                    },
                },
            },
        })
        if err != nil {
            return err
        }
        p1, err := vsphere.NewDistributedPortGroup(ctx, "p1", &vsphere.DistributedPortGroupArgs{
            VlanId:                       pulumi.Int(1234),
            DistributedVirtualSwitchUuid: d1.ID(),
        })
        if err != nil {
            return err
        }
        _, err = vsphere.NewVnic(ctx, "v1", &vsphere.VnicArgs{
            Host:                  pulumi.String(h1.Id),
            DistributedSwitchPort: d1.ID(),
            DistributedPortGroup:  p1.ID(),
            Ipv4: &vsphere.VnicIpv4Args{
                Dhcp: pulumi.Bool(true),
            },
            Netstack: pulumi.String("vmotion"),
        })
        if err != nil {
            return err
        }
        return nil
    })
}
import pulumi
import pulumi_vsphere as vsphere

dc = vsphere.get_datacenter(name="mydc")
h1 = vsphere.get_host(name="esxi1.host.test",
    datacenter_id=dc.id)
d1 = vsphere.DistributedVirtualSwitch("d1",
    datacenter_id=dc.id,
    hosts=[vsphere.DistributedVirtualSwitchHostArgs(
        host_system_id=h1.id,
        devices=["vnic3"],
    )])
p1 = vsphere.DistributedPortGroup("p1",
    vlan_id=1234,
    distributed_virtual_switch_uuid=d1.id)
v1 = vsphere.Vnic("v1",
    host=h1.id,
    distributed_switch_port=d1.id,
    distributed_port_group=p1.id,
    ipv4=vsphere.VnicIpv4Args(
        dhcp=True,
    ),
    netstack="vmotion")
import * as pulumi from "@pulumi/pulumi";
import * as vsphere from "@pulumi/vsphere";

const dc = vsphere.getDatacenter({
    name: "mydc",
});
const h1 = dc.then(dc => vsphere.getHost({
    name: "esxi1.host.test",
    datacenterId: dc.id,
}));
const d1 = new vsphere.DistributedVirtualSwitch("d1", {
    datacenterId: dc.then(dc => dc.id),
    hosts: [{
        hostSystemId: h1.then(h1 => h1.id),
        devices: ["vnic3"],
    }],
});
const p1 = new vsphere.DistributedPortGroup("p1", {
    vlanId: 1234,
    distributedVirtualSwitchUuid: d1.id,
});
const v1 = new vsphere.Vnic("v1", {
    host: h1.then(h1 => h1.id),
    distributedSwitchPort: d1.id,
    distributedPortGroup: p1.id,
    ipv4: {
        dhcp: true,
    },
    netstack: "vmotion",
});

Create a vnic attached to a portgroup using the default TCP/IP stack

using Pulumi;
using VSphere = Pulumi.VSphere;

class MyStack : Stack
{
    public MyStack()
    {
        var dc = Output.Create(VSphere.GetDatacenter.InvokeAsync(new VSphere.GetDatacenterArgs
        {
            Name = "mydc",
        }));
        var h1 = dc.Apply(dc => Output.Create(VSphere.GetHost.InvokeAsync(new VSphere.GetHostArgs
        {
            Name = "esxi1.host.test",
            DatacenterId = dc.Id,
        })));
        var hvs1 = new VSphere.HostVirtualSwitch("hvs1", new VSphere.HostVirtualSwitchArgs
        {
            HostSystemId = h1.Apply(h1 => h1.Id),
            NetworkAdapters = 
            {
                "vmnic3",
                "vmnic4",
            },
            ActiveNics = 
            {
                "vmnic3",
            },
            StandbyNics = 
            {
                "vmnic4",
            },
        });
        var p1 = new VSphere.HostPortGroup("p1", new VSphere.HostPortGroupArgs
        {
            VirtualSwitchName = hvs1.Name,
            HostSystemId = h1.Apply(h1 => h1.Id),
        });
        var v1 = new VSphere.Vnic("v1", new VSphere.VnicArgs
        {
            Host = h1.Apply(h1 => h1.Id),
            Portgroup = p1.Name,
            Ipv4 = new VSphere.Inputs.VnicIpv4Args
            {
                Dhcp = true,
            },
        });
    }

}
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 := "mydc"
        dc, err := vsphere.LookupDatacenter(ctx, &vsphere.LookupDatacenterArgs{
            Name: &opt0,
        }, nil)
        if err != nil {
            return err
        }
        opt1 := "esxi1.host.test"
        h1, err := vsphere.LookupHost(ctx, &vsphere.LookupHostArgs{
            Name:         &opt1,
            DatacenterId: dc.Id,
        }, nil)
        if err != nil {
            return err
        }
        hvs1, err := vsphere.NewHostVirtualSwitch(ctx, "hvs1", &vsphere.HostVirtualSwitchArgs{
            HostSystemId: pulumi.String(h1.Id),
            NetworkAdapters: pulumi.StringArray{
                pulumi.String("vmnic3"),
                pulumi.String("vmnic4"),
            },
            ActiveNics: pulumi.StringArray{
                pulumi.String("vmnic3"),
            },
            StandbyNics: pulumi.StringArray{
                pulumi.String("vmnic4"),
            },
        })
        if err != nil {
            return err
        }
        p1, err := vsphere.NewHostPortGroup(ctx, "p1", &vsphere.HostPortGroupArgs{
            VirtualSwitchName: hvs1.Name,
            HostSystemId:      pulumi.String(h1.Id),
        })
        if err != nil {
            return err
        }
        _, err = vsphere.NewVnic(ctx, "v1", &vsphere.VnicArgs{
            Host:      pulumi.String(h1.Id),
            Portgroup: p1.Name,
            Ipv4: &vsphere.VnicIpv4Args{
                Dhcp: pulumi.Bool(true),
            },
        })
        if err != nil {
            return err
        }
        return nil
    })
}
import pulumi
import pulumi_vsphere as vsphere

dc = vsphere.get_datacenter(name="mydc")
h1 = vsphere.get_host(name="esxi1.host.test",
    datacenter_id=dc.id)
hvs1 = vsphere.HostVirtualSwitch("hvs1",
    host_system_id=h1.id,
    network_adapters=[
        "vmnic3",
        "vmnic4",
    ],
    active_nics=["vmnic3"],
    standby_nics=["vmnic4"])
p1 = vsphere.HostPortGroup("p1",
    virtual_switch_name=hvs1.name,
    host_system_id=h1.id)
v1 = vsphere.Vnic("v1",
    host=h1.id,
    portgroup=p1.name,
    ipv4=vsphere.VnicIpv4Args(
        dhcp=True,
    ))
import * as pulumi from "@pulumi/pulumi";
import * as vsphere from "@pulumi/vsphere";

const dc = vsphere.getDatacenter({
    name: "mydc",
});
const h1 = dc.then(dc => vsphere.getHost({
    name: "esxi1.host.test",
    datacenterId: dc.id,
}));
const hvs1 = new vsphere.HostVirtualSwitch("hvs1", {
    hostSystemId: h1.then(h1 => h1.id),
    networkAdapters: [
        "vmnic3",
        "vmnic4",
    ],
    activeNics: ["vmnic3"],
    standbyNics: ["vmnic4"],
});
const p1 = new vsphere.HostPortGroup("p1", {
    virtualSwitchName: hvs1.name,
    hostSystemId: h1.then(h1 => h1.id),
});
const v1 = new vsphere.Vnic("v1", {
    host: h1.then(h1 => h1.id),
    portgroup: p1.name,
    ipv4: {
        dhcp: true,
    },
});

Create a Vnic Resource

new Vnic(name: string, args: VnicArgs, opts?: CustomResourceOptions);
def Vnic(resource_name: str, opts: Optional[ResourceOptions] = None, distributed_port_group: Optional[str] = None, distributed_switch_port: Optional[str] = None, host: Optional[str] = None, ipv4: Optional[VnicIpv4Args] = None, ipv6: Optional[VnicIpv6Args] = None, mac: Optional[str] = None, mtu: Optional[int] = None, netstack: Optional[str] = None, portgroup: Optional[str] = None)
func NewVnic(ctx *Context, name string, args VnicArgs, opts ...ResourceOption) (*Vnic, error)
public Vnic(string name, VnicArgs args, CustomResourceOptions? opts = null)
name string
The unique name of the resource.
args VnicArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name str
The unique name of the resource.
opts ResourceOptions
A bag of options that control this resource's behavior.
ctx Context
Context object for the current deployment.
name string
The unique name of the resource.
args VnicArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args VnicArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.

Vnic Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Programming Model docs.

Inputs

The Vnic resource accepts the following input properties:

Host string

ESX host the interface belongs to

DistributedPortGroup string

Key of the distributed portgroup the nic will connect to.

DistributedSwitchPort string

UUID of the DVSwitch the nic will be attached to. Do not set if you set portgroup.

Ipv4 Pulumi.VSphere.Inputs.VnicIpv4Args

IPv4 settings. Either this or ipv6 needs to be set. See ipv4 options below.

Ipv6 Pulumi.VSphere.Inputs.VnicIpv6Args

IPv6 settings. Either this or ipv6 needs to be set. See ipv6 options below.

Mac string

MAC address of the interface.

Mtu int

MTU of the interface.

Netstack string

TCP/IP stack setting for this interface. Possible values are ‘defaultTcpipStack’, ‘vmotion’, ‘vSphereProvisioning’. Changing this will force the creation of a new interface since it’s not possible to change the stack once it gets created. (Default: defaultTcpipStack)

Portgroup string

Portgroup to attach the nic to. Do not set if you set distributed_switch_port.

Host string

ESX host the interface belongs to

DistributedPortGroup string

Key of the distributed portgroup the nic will connect to.

DistributedSwitchPort string

UUID of the DVSwitch the nic will be attached to. Do not set if you set portgroup.

Ipv4 VnicIpv4

IPv4 settings. Either this or ipv6 needs to be set. See ipv4 options below.

Ipv6 VnicIpv6

IPv6 settings. Either this or ipv6 needs to be set. See ipv6 options below.

Mac string

MAC address of the interface.

Mtu int

MTU of the interface.

Netstack string

TCP/IP stack setting for this interface. Possible values are ‘defaultTcpipStack’, ‘vmotion’, ‘vSphereProvisioning’. Changing this will force the creation of a new interface since it’s not possible to change the stack once it gets created. (Default: defaultTcpipStack)

Portgroup string

Portgroup to attach the nic to. Do not set if you set distributed_switch_port.

host string

ESX host the interface belongs to

distributedPortGroup string

Key of the distributed portgroup the nic will connect to.

distributedSwitchPort string

UUID of the DVSwitch the nic will be attached to. Do not set if you set portgroup.

ipv4 VnicIpv4

IPv4 settings. Either this or ipv6 needs to be set. See ipv4 options below.

ipv6 VnicIpv6

IPv6 settings. Either this or ipv6 needs to be set. See ipv6 options below.

mac string

MAC address of the interface.

mtu number

MTU of the interface.

netstack string

TCP/IP stack setting for this interface. Possible values are ‘defaultTcpipStack’, ‘vmotion’, ‘vSphereProvisioning’. Changing this will force the creation of a new interface since it’s not possible to change the stack once it gets created. (Default: defaultTcpipStack)

portgroup string

Portgroup to attach the nic to. Do not set if you set distributed_switch_port.

host str

ESX host the interface belongs to

distributed_port_group str

Key of the distributed portgroup the nic will connect to.

distributed_switch_port str

UUID of the DVSwitch the nic will be attached to. Do not set if you set portgroup.

ipv4 VnicIpv4Args

IPv4 settings. Either this or ipv6 needs to be set. See ipv4 options below.

ipv6 VnicIpv6Args

IPv6 settings. Either this or ipv6 needs to be set. See ipv6 options below.

mac str

MAC address of the interface.

mtu int

MTU of the interface.

netstack str

TCP/IP stack setting for this interface. Possible values are ‘defaultTcpipStack’, ‘vmotion’, ‘vSphereProvisioning’. Changing this will force the creation of a new interface since it’s not possible to change the stack once it gets created. (Default: defaultTcpipStack)

portgroup str

Portgroup to attach the nic to. Do not set if you set distributed_switch_port.

Outputs

All input properties are implicitly available as output properties. Additionally, the Vnic resource produces the following output properties:

Id string
The provider-assigned unique ID for this managed resource.
Id string
The provider-assigned unique ID for this managed resource.
id string
The provider-assigned unique ID for this managed resource.
id str
The provider-assigned unique ID for this managed resource.

Look up an Existing Vnic Resource

Get an existing Vnic resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: VnicState, opts?: CustomResourceOptions): Vnic
@staticmethod
def get(resource_name: str, id: str, opts: Optional[ResourceOptions] = None, distributed_port_group: Optional[str] = None, distributed_switch_port: Optional[str] = None, host: Optional[str] = None, ipv4: Optional[VnicIpv4Args] = None, ipv6: Optional[VnicIpv6Args] = None, mac: Optional[str] = None, mtu: Optional[int] = None, netstack: Optional[str] = None, portgroup: Optional[str] = None) -> Vnic
func GetVnic(ctx *Context, name string, id IDInput, state *VnicState, opts ...ResourceOption) (*Vnic, error)
public static Vnic Get(string name, Input<string> id, VnicState? state, CustomResourceOptions? opts = null)
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.

The following state arguments are supported:

DistributedPortGroup string

Key of the distributed portgroup the nic will connect to.

DistributedSwitchPort string

UUID of the DVSwitch the nic will be attached to. Do not set if you set portgroup.

Host string

ESX host the interface belongs to

Ipv4 Pulumi.VSphere.Inputs.VnicIpv4Args

IPv4 settings. Either this or ipv6 needs to be set. See ipv4 options below.

Ipv6 Pulumi.VSphere.Inputs.VnicIpv6Args

IPv6 settings. Either this or ipv6 needs to be set. See ipv6 options below.

Mac string

MAC address of the interface.

Mtu int

MTU of the interface.

Netstack string

TCP/IP stack setting for this interface. Possible values are ‘defaultTcpipStack’, ‘vmotion’, ‘vSphereProvisioning’. Changing this will force the creation of a new interface since it’s not possible to change the stack once it gets created. (Default: defaultTcpipStack)

Portgroup string

Portgroup to attach the nic to. Do not set if you set distributed_switch_port.

DistributedPortGroup string

Key of the distributed portgroup the nic will connect to.

DistributedSwitchPort string

UUID of the DVSwitch the nic will be attached to. Do not set if you set portgroup.

Host string

ESX host the interface belongs to

Ipv4 VnicIpv4

IPv4 settings. Either this or ipv6 needs to be set. See ipv4 options below.

Ipv6 VnicIpv6

IPv6 settings. Either this or ipv6 needs to be set. See ipv6 options below.

Mac string

MAC address of the interface.

Mtu int

MTU of the interface.

Netstack string

TCP/IP stack setting for this interface. Possible values are ‘defaultTcpipStack’, ‘vmotion’, ‘vSphereProvisioning’. Changing this will force the creation of a new interface since it’s not possible to change the stack once it gets created. (Default: defaultTcpipStack)

Portgroup string

Portgroup to attach the nic to. Do not set if you set distributed_switch_port.

distributedPortGroup string

Key of the distributed portgroup the nic will connect to.

distributedSwitchPort string

UUID of the DVSwitch the nic will be attached to. Do not set if you set portgroup.

host string

ESX host the interface belongs to

ipv4 VnicIpv4

IPv4 settings. Either this or ipv6 needs to be set. See ipv4 options below.

ipv6 VnicIpv6

IPv6 settings. Either this or ipv6 needs to be set. See ipv6 options below.

mac string

MAC address of the interface.

mtu number

MTU of the interface.

netstack string

TCP/IP stack setting for this interface. Possible values are ‘defaultTcpipStack’, ‘vmotion’, ‘vSphereProvisioning’. Changing this will force the creation of a new interface since it’s not possible to change the stack once it gets created. (Default: defaultTcpipStack)

portgroup string

Portgroup to attach the nic to. Do not set if you set distributed_switch_port.

distributed_port_group str

Key of the distributed portgroup the nic will connect to.

distributed_switch_port str

UUID of the DVSwitch the nic will be attached to. Do not set if you set portgroup.

host str

ESX host the interface belongs to

ipv4 VnicIpv4Args

IPv4 settings. Either this or ipv6 needs to be set. See ipv4 options below.

ipv6 VnicIpv6Args

IPv6 settings. Either this or ipv6 needs to be set. See ipv6 options below.

mac str

MAC address of the interface.

mtu int

MTU of the interface.

netstack str

TCP/IP stack setting for this interface. Possible values are ‘defaultTcpipStack’, ‘vmotion’, ‘vSphereProvisioning’. Changing this will force the creation of a new interface since it’s not possible to change the stack once it gets created. (Default: defaultTcpipStack)

portgroup str

Portgroup to attach the nic to. Do not set if you set distributed_switch_port.

Supporting Types

VnicIpv4

Dhcp bool

Use DHCP to configure the interface’s IPv4 stack.

Gw string

IP address of the default gateway, if DHCP or autoconfig is not set.

Ip string

Address of the interface, if DHCP is not set.

Netmask string

Netmask of the interface, if DHCP is not set.

Dhcp bool

Use DHCP to configure the interface’s IPv4 stack.

Gw string

IP address of the default gateway, if DHCP or autoconfig is not set.

Ip string

Address of the interface, if DHCP is not set.

Netmask string

Netmask of the interface, if DHCP is not set.

dhcp boolean

Use DHCP to configure the interface’s IPv4 stack.

gw string

IP address of the default gateway, if DHCP or autoconfig is not set.

ip string

Address of the interface, if DHCP is not set.

netmask string

Netmask of the interface, if DHCP is not set.

dhcp bool

Use DHCP to configure the interface’s IPv4 stack.

gw str

IP address of the default gateway, if DHCP or autoconfig is not set.

ip str

Address of the interface, if DHCP is not set.

netmask str

Netmask of the interface, if DHCP is not set.

VnicIpv6

Addresses List<string>

List of IPv6 addresses

Autoconfig bool

Use IPv6 Autoconfiguration (RFC2462).

Dhcp bool

Use DHCP to configure the interface’s IPv4 stack.

Gw string

IP address of the default gateway, if DHCP or autoconfig is not set.

Addresses []string

List of IPv6 addresses

Autoconfig bool

Use IPv6 Autoconfiguration (RFC2462).

Dhcp bool

Use DHCP to configure the interface’s IPv4 stack.

Gw string

IP address of the default gateway, if DHCP or autoconfig is not set.

addresses string[]

List of IPv6 addresses

autoconfig boolean

Use IPv6 Autoconfiguration (RFC2462).

dhcp boolean

Use DHCP to configure the interface’s IPv4 stack.

gw string

IP address of the default gateway, if DHCP or autoconfig is not set.

addresses Sequence[str]

List of IPv6 addresses

autoconfig bool

Use IPv6 Autoconfiguration (RFC2462).

dhcp bool

Use DHCP to configure the interface’s IPv4 stack.

gw str

IP address of the default gateway, if DHCP or autoconfig is not set.

Package Details

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