1. Packages
  2. Digitalocean Provider
  3. API Docs
  4. getVpc
DigitalOcean v4.35.0 published on Tuesday, Nov 19, 2024 by Pulumi

digitalocean.getVpc

Explore with Pulumi AI

digitalocean logo
DigitalOcean v4.35.0 published on Tuesday, Nov 19, 2024 by Pulumi

    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

    import * as pulumi from "@pulumi/pulumi";
    import * as digitalocean from "@pulumi/digitalocean";
    
    const example = digitalocean.getVpc({
        name: "example-network",
    });
    
    import pulumi
    import pulumi_digitalocean as digitalocean
    
    example = digitalocean.get_vpc(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, &digitalocean.LookupVpcArgs{
    			Name: pulumi.StringRef("example-network"),
    		}, nil)
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using DigitalOcean = Pulumi.DigitalOcean;
    
    return await Deployment.RunAsync(() => 
    {
        var example = DigitalOcean.GetVpc.Invoke(new()
        {
            Name = "example-network",
        });
    
    });
    
    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());
    
        }
    }
    
    variables:
      example:
        fn::invoke:
          Function: digitalocean:getVpc
          Arguments:
            name: example-network
    

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

    import * as pulumi from "@pulumi/pulumi";
    import * as digitalocean from "@pulumi/digitalocean";
    
    const example = digitalocean.getVpc({
        name: "example-network",
    });
    const exampleDroplet = new digitalocean.Droplet("example", {
        name: "example-01",
        size: digitalocean.DropletSlug.DropletS1VCPU1GB,
        image: "ubuntu-18-04-x64",
        region: digitalocean.Region.NYC3,
        vpcUuid: example.then(example => example.id),
    });
    
    import pulumi
    import pulumi_digitalocean as digitalocean
    
    example = digitalocean.get_vpc(name="example-network")
    example_droplet = digitalocean.Droplet("example",
        name="example-01",
        size=digitalocean.DropletSlug.DROPLET_S1_VCPU1_GB,
        image="ubuntu-18-04-x64",
        region=digitalocean.Region.NYC3,
        vpc_uuid=example.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 {
    		example, err := digitalocean.LookupVpc(ctx, &digitalocean.LookupVpcArgs{
    			Name: pulumi.StringRef("example-network"),
    		}, nil)
    		if err != nil {
    			return err
    		}
    		_, err = digitalocean.NewDroplet(ctx, "example", &digitalocean.DropletArgs{
    			Name:    pulumi.String("example-01"),
    			Size:    pulumi.String(digitalocean.DropletSlugDropletS1VCPU1GB),
    			Image:   pulumi.String("ubuntu-18-04-x64"),
    			Region:  pulumi.String(digitalocean.RegionNYC3),
    			VpcUuid: pulumi.String(example.Id),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using DigitalOcean = Pulumi.DigitalOcean;
    
    return await Deployment.RunAsync(() => 
    {
        var example = DigitalOcean.GetVpc.Invoke(new()
        {
            Name = "example-network",
        });
    
        var exampleDroplet = new DigitalOcean.Droplet("example", new()
        {
            Name = "example-01",
            Size = DigitalOcean.DropletSlug.DropletS1VCPU1GB,
            Image = "ubuntu-18-04-x64",
            Region = DigitalOcean.Region.NYC3,
            VpcUuid = example.Apply(getVpcResult => getVpcResult.Id),
        });
    
    });
    
    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 example = DigitaloceanFunctions.getVpc(GetVpcArgs.builder()
                .name("example-network")
                .build());
    
            var exampleDroplet = new Droplet("exampleDroplet", DropletArgs.builder()
                .name("example-01")
                .size("s-1vcpu-1gb")
                .image("ubuntu-18-04-x64")
                .region("nyc3")
                .vpcUuid(example.applyValue(getVpcResult -> getVpcResult.id()))
                .build());
    
        }
    }
    
    resources:
      exampleDroplet:
        type: digitalocean:Droplet
        name: example
        properties:
          name: example-01
          size: s-1vcpu-1gb
          image: ubuntu-18-04-x64
          region: nyc3
          vpcUuid: ${example.id}
    variables:
      example:
        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
    DigitalOcean pulumi/pulumi-digitalocean
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the digitalocean Terraform Provider.
    digitalocean logo
    DigitalOcean v4.35.0 published on Tuesday, Nov 19, 2024 by Pulumi