getVpc

suspend fun getVpc(argument: GetVpcPlainArgs): GetVpcResult

aws.ec2.Vpc provides details about a specific VPC. This resource can prove useful when a module accepts a vpc id as an input variable and needs to, for example, determine the CIDR block of that VPC.

Example Usage

The following example shows how one might accept a VPC id as a variable and use this data source to obtain the data necessary to create a subnet within it.

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as std from "@pulumi/std";
const config = new pulumi.Config();
const vpcId = config.requireObject<any>("vpcId");
const selected = aws.ec2.getVpc({
id: vpcId,
});
const example = new aws.ec2.Subnet("example", {
vpcId: selected.then(selected => selected.id),
availabilityZone: "us-west-2a",
cidrBlock: selected.then(selected => std.cidrsubnet({
input: selected.cidrBlock,
newbits: 4,
netnum: 1,
})).then(invoke => invoke.result),
});
import pulumi
import pulumi_aws as aws
import pulumi_std as std
config = pulumi.Config()
vpc_id = config.require_object("vpcId")
selected = aws.ec2.get_vpc(id=vpc_id)
example = aws.ec2.Subnet("example",
vpc_id=selected.id,
availability_zone="us-west-2a",
cidr_block=std.cidrsubnet(input=selected.cidr_block,
newbits=4,
netnum=1).result)
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
using Std = Pulumi.Std;
return await Deployment.RunAsync(() =>
{
var config = new Config();
var vpcId = config.RequireObject<dynamic>("vpcId");
var selected = Aws.Ec2.GetVpc.Invoke(new()
{
Id = vpcId,
});
var example = new Aws.Ec2.Subnet("example", new()
{
VpcId = selected.Apply(getVpcResult => getVpcResult.Id),
AvailabilityZone = "us-west-2a",
CidrBlock = Std.Cidrsubnet.Invoke(new()
{
Input = selected.Apply(getVpcResult => getVpcResult.CidrBlock),
Newbits = 4,
Netnum = 1,
}).Apply(invoke => invoke.Result),
});
});
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2"
"github.com/pulumi/pulumi-std/sdk/go/std"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
cfg := config.New(ctx, "")
vpcId := cfg.RequireObject("vpcId")
selected, err := ec2.LookupVpc(ctx, &ec2.LookupVpcArgs{
Id: pulumi.StringRef(vpcId),
}, nil)
if err != nil {
return err
}
invokeCidrsubnet, err := std.Cidrsubnet(ctx, &std.CidrsubnetArgs{
Input: selected.CidrBlock,
Newbits: 4,
Netnum: 1,
}, nil)
if err != nil {
return err
}
_, err = ec2.NewSubnet(ctx, "example", &ec2.SubnetArgs{
VpcId: pulumi.String(selected.Id),
AvailabilityZone: pulumi.String("us-west-2a"),
CidrBlock: pulumi.String(invokeCidrsubnet.Result),
})
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.aws.ec2.Ec2Functions;
import com.pulumi.aws.ec2.inputs.GetVpcArgs;
import com.pulumi.aws.ec2.Subnet;
import com.pulumi.aws.ec2.SubnetArgs;
import com.pulumi.std.StdFunctions;
import com.pulumi.std.inputs.CidrsubnetArgs;
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 config = ctx.config();
final var vpcId = config.get("vpcId");
final var selected = Ec2Functions.getVpc(GetVpcArgs.builder()
.id(vpcId)
.build());
var example = new Subnet("example", SubnetArgs.builder()
.vpcId(selected.id())
.availabilityZone("us-west-2a")
.cidrBlock(StdFunctions.cidrsubnet(CidrsubnetArgs.builder()
.input(selected.cidrBlock())
.newbits(4)
.netnum(1)
.build()).result())
.build());
}
}
configuration:
vpcId:
type: dynamic
resources:
example:
type: aws:ec2:Subnet
properties:
vpcId: ${selected.id}
availabilityZone: us-west-2a
cidrBlock:
fn::invoke:
function: std:cidrsubnet
arguments:
input: ${selected.cidrBlock}
newbits: 4
netnum: 1
return: result
variables:
selected:
fn::invoke:
function: aws:ec2:getVpc
arguments:
id: ${vpcId}

Return

A collection of values returned by getVpc.

Parameters

argument

A collection of arguments for invoking getVpc.


suspend fun getVpc(cidrBlock: String? = null, default: Boolean? = null, dhcpOptionsId: String? = null, filters: List<GetVpcFilter>? = null, id: String? = null, state: String? = null, tags: Map<String, String>? = null): GetVpcResult

Return

A collection of values returned by getVpc.

Parameters

cidrBlock

Cidr block of the desired VPC.

default

Boolean constraint on whether the desired VPC is the default VPC for the region.

dhcpOptionsId

DHCP options id of the desired VPC.

filters

Custom filter block as described below.

id

ID of the specific VPC to retrieve.

state

Current state of the desired VPC. Can be either "pending" or "available".

tags

Map of tags, each pair of which must exactly match a pair on the desired VPC. More complex filters can be expressed using one or more filter sub-blocks, which take the following arguments:

See also


suspend fun getVpc(argument: suspend GetVpcPlainArgsBuilder.() -> Unit): GetVpcResult

Return

A collection of values returned by getVpc.

Parameters

argument

Builder for com.pulumi.aws.ec2.kotlin.inputs.GetVpcPlainArgs.

See also