DigitalOcean

v4.16.0 published on Wednesday, Sep 28, 2022 by Pulumi

getVpc

Retrieve information about a VPC for use in other resources.

This data source provides all of the VPC’s properties as configured on your DigitalOcean account. This is useful if the VPC in question is not managed by the provider or you need to utilize any of the VPC’s data.

VPCs may be looked up by id or name. Specifying a region will return that that region’s default VPC.

Example Usage

VPC By Name

using System.Collections.Generic;
using Pulumi;
using DigitalOcean = Pulumi.DigitalOcean;

return await Deployment.RunAsync(() => 
{
    var example = DigitalOcean.GetVpc.Invoke(new()
    {
        Name = "example-network",
    });

});
package main

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

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := digitalocean.LookupVpc(ctx, &GetVpcArgs{
			Name: pulumi.StringRef("example-network"),
		}, nil)
		if err != nil {
			return err
		}
		return nil
	})
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.digitalocean.DigitaloceanFunctions;
import com.pulumi.digitalocean.inputs.GetVpcArgs;
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 example = DigitaloceanFunctions.getVpc(GetVpcArgs.builder()
            .name("example-network")
            .build());

    }
}
import pulumi
import pulumi_digitalocean as digitalocean

example = digitalocean.get_vpc(name="example-network")
import * as pulumi from "@pulumi/pulumi";
import * as digitalocean from "@pulumi/digitalocean";

const example = pulumi.output(digitalocean.getVpc({
    name: "example-network",
}));
variables:
  example:
    Fn::Invoke:
      Function: digitalocean:getVpc
      Arguments:
        name: example-network

Reuse the data about a VPC to assign a Droplet to it

using System.Collections.Generic;
using Pulumi;
using DigitalOcean = Pulumi.DigitalOcean;

return await Deployment.RunAsync(() => 
{
    var exampleVpc = DigitalOcean.GetVpc.Invoke(new()
    {
        Name = "example-network",
    });

    var exampleDroplet = new DigitalOcean.Droplet("exampleDroplet", new()
    {
        Size = "s-1vcpu-1gb",
        Image = "ubuntu-18-04-x64",
        Region = "nyc3",
        VpcUuid = exampleVpc.Apply(getVpcResult => getVpcResult.Id),
    });

});
package main

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

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		exampleVpc, err := digitalocean.LookupVpc(ctx, &GetVpcArgs{
			Name: pulumi.StringRef("example-network"),
		}, nil)
		if err != nil {
			return err
		}
		_, err = digitalocean.NewDroplet(ctx, "exampleDroplet", &digitalocean.DropletArgs{
			Size:    pulumi.String("s-1vcpu-1gb"),
			Image:   pulumi.String("ubuntu-18-04-x64"),
			Region:  pulumi.String("nyc3"),
			VpcUuid: pulumi.String(exampleVpc.Id),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.digitalocean.DigitaloceanFunctions;
import com.pulumi.digitalocean.inputs.GetVpcArgs;
import com.pulumi.digitalocean.Droplet;
import com.pulumi.digitalocean.DropletArgs;
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 exampleVpc = DigitaloceanFunctions.getVpc(GetVpcArgs.builder()
            .name("example-network")
            .build());

        var exampleDroplet = new Droplet("exampleDroplet", DropletArgs.builder()        
            .size("s-1vcpu-1gb")
            .image("ubuntu-18-04-x64")
            .region("nyc3")
            .vpcUuid(exampleVpc.applyValue(getVpcResult -> getVpcResult.id()))
            .build());

    }
}
import pulumi
import pulumi_digitalocean as digitalocean

example_vpc = digitalocean.get_vpc(name="example-network")
example_droplet = digitalocean.Droplet("exampleDroplet",
    size="s-1vcpu-1gb",
    image="ubuntu-18-04-x64",
    region="nyc3",
    vpc_uuid=example_vpc.id)
import * as pulumi from "@pulumi/pulumi";
import * as digitalocean from "@pulumi/digitalocean";

const exampleVpc = digitalocean.getVpc({
    name: "example-network",
});
const exampleDroplet = new digitalocean.Droplet("exampleDroplet", {
    size: "s-1vcpu-1gb",
    image: "ubuntu-18-04-x64",
    region: "nyc3",
    vpcUuid: exampleVpc.then(exampleVpc => exampleVpc.id),
});
resources:
  exampleDroplet:
    type: digitalocean:Droplet
    properties:
      size: s-1vcpu-1gb
      image: ubuntu-18-04-x64
      region: nyc3
      vpcUuid: ${exampleVpc.id}
variables:
  exampleVpc:
    Fn::Invoke:
      Function: digitalocean:getVpc
      Arguments:
        name: example-network

Using getVpc

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 getVpc(args: GetVpcArgs, opts?: InvokeOptions): Promise<GetVpcResult>
function getVpcOutput(args: GetVpcOutputArgs, opts?: InvokeOptions): Output<GetVpcResult>
def get_vpc(id: Optional[str] = None,
            name: Optional[str] = None,
            region: Optional[str] = None,
            opts: Optional[InvokeOptions] = None) -> GetVpcResult
def get_vpc_output(id: Optional[pulumi.Input[str]] = None,
            name: Optional[pulumi.Input[str]] = None,
            region: Optional[pulumi.Input[str]] = None,
            opts: Optional[InvokeOptions] = None) -> Output[GetVpcResult]
func LookupVpc(ctx *Context, args *LookupVpcArgs, opts ...InvokeOption) (*LookupVpcResult, error)
func LookupVpcOutput(ctx *Context, args *LookupVpcOutputArgs, opts ...InvokeOption) LookupVpcResultOutput

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

public static class GetVpc 
{
    public static Task<GetVpcResult> InvokeAsync(GetVpcArgs args, InvokeOptions? opts = null)
    public static Output<GetVpcResult> Invoke(GetVpcInvokeArgs args, InvokeOptions? opts = null)
}
public static CompletableFuture<GetVpcResult> getVpc(GetVpcArgs args, InvokeOptions options)
// Output-based functions aren't available in Java yet
fn::invoke:
  function: digitalocean:index/getVpc:getVpc
  arguments:
    # arguments dictionary

The following arguments are supported:

Id string

The unique identifier of an existing VPC.

Name string

The name of an existing VPC.

Region string

The DigitalOcean region slug for the VPC's location.

Id string

The unique identifier of an existing VPC.

Name string

The name of an existing VPC.

Region string

The DigitalOcean region slug for the VPC's location.

id String

The unique identifier of an existing VPC.

name String

The name of an existing VPC.

region String

The DigitalOcean region slug for the VPC's location.

id string

The unique identifier of an existing VPC.

name string

The name of an existing VPC.

region string

The DigitalOcean region slug for the VPC's location.

id str

The unique identifier of an existing VPC.

name str

The name of an existing VPC.

region str

The DigitalOcean region slug for the VPC's location.

id String

The unique identifier of an existing VPC.

name String

The name of an existing VPC.

region String

The DigitalOcean region slug for the VPC's location.

getVpc Result

The following output properties are available:

CreatedAt string

The date and time of when the VPC was created.

Default bool

A boolean indicating whether or not the VPC is the default one for the region.

Description string

A free-form text field describing the VPC.

Id string

The unique identifier for the VPC.

IpRange string

The range of IP addresses for the VPC in CIDR notation.

Name string

The name of the VPC.

Region string

The DigitalOcean region slug for the VPC's location.

Urn string

The uniform resource name (URN) for the VPC.

CreatedAt string

The date and time of when the VPC was created.

Default bool

A boolean indicating whether or not the VPC is the default one for the region.

Description string

A free-form text field describing the VPC.

Id string

The unique identifier for the VPC.

IpRange string

The range of IP addresses for the VPC in CIDR notation.

Name string

The name of the VPC.

Region string

The DigitalOcean region slug for the VPC's location.

Urn string

The uniform resource name (URN) for the VPC.

createdAt String

The date and time of when the VPC was created.

default_ Boolean

A boolean indicating whether or not the VPC is the default one for the region.

description String

A free-form text field describing the VPC.

id String

The unique identifier for the VPC.

ipRange String

The range of IP addresses for the VPC in CIDR notation.

name String

The name of the VPC.

region String

The DigitalOcean region slug for the VPC's location.

urn String

The uniform resource name (URN) for the VPC.

createdAt string

The date and time of when the VPC was created.

default boolean

A boolean indicating whether or not the VPC is the default one for the region.

description string

A free-form text field describing the VPC.

id string

The unique identifier for the VPC.

ipRange string

The range of IP addresses for the VPC in CIDR notation.

name string

The name of the VPC.

region string

The DigitalOcean region slug for the VPC's location.

urn string

The uniform resource name (URN) for the VPC.

created_at str

The date and time of when the VPC was created.

default bool

A boolean indicating whether or not the VPC is the default one for the region.

description str

A free-form text field describing the VPC.

id str

The unique identifier for the VPC.

ip_range str

The range of IP addresses for the VPC in CIDR notation.

name str

The name of the VPC.

region str

The DigitalOcean region slug for the VPC's location.

urn str

The uniform resource name (URN) for the VPC.

createdAt String

The date and time of when the VPC was created.

default Boolean

A boolean indicating whether or not the VPC is the default one for the region.

description String

A free-form text field describing the VPC.

id String

The unique identifier for the VPC.

ipRange String

The range of IP addresses for the VPC in CIDR notation.

name String

The name of the VPC.

region String

The DigitalOcean region slug for the VPC's location.

urn String

The uniform resource name (URN) for the VPC.

Package Details

Repository
https://github.com/pulumi/pulumi-digitalocean
License
Apache-2.0
Notes

This Pulumi package is based on the digitalocean Terraform Provider.