VpcPeeringConnection class
Provides a resource to manage a VPC peering connection.
> Note: Modifying the VPC Peering Connection options requires peering to be active. An automatic activation
can be done using the autoAccept attribute. Alternatively, the VPC Peering
Connection has to be made active manually using other means. See notes below for
more information.
> NOTE on VPC Peering Connections and VPC Peering Connection Options: This provider provides
both a standalone VPC Peering Connection Options and a VPC Peering Connection
resource with accepter and requester attributes. Do not manage options for the same VPC peering
connection in both a VPC Peering Connection resource and a VPC Peering Connection Options resource.
Doing so will cause a conflict of options and will overwrite the options.
Using a VPC Peering Connection Options resource decouples management of the connection options from
management of the VPC Peering Connection and allows options to be set correctly in cross-account scenarios.
> Note: For cross-account (requester's AWS account differs from the accepter's AWS account) or inter-region
VPC Peering Connections use the aws.ec2.VpcPeeringConnection resource to manage the requester's side of the
connection and use the aws.ec2.VpcPeeringConnectionAccepter resource to manage the accepter's side of the connection.
> Note: Creating multiple aws.ec2.VpcPeeringConnection resources with the same peerVpcId and vpcId will not produce an error. Instead, AWS will return the connection id that already exists, resulting in multiple aws.ec2.VpcPeeringConnection resources with the same id.
Example Usage
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const foo = new aws.ec2.VpcPeeringConnection("foo", {
peerOwnerId: peerOwnerId,
peerVpcId: bar.id,
vpcId: fooAwsVpc.id,
});
import pulumi
import pulumi_aws as aws
foo = aws.ec2.VpcPeeringConnection("foo",
peer_owner_id=peer_owner_id,
peer_vpc_id=bar["id"],
vpc_id=foo_aws_vpc["id"])
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var foo = new Aws.Ec2.VpcPeeringConnection("foo", new()
{
PeerOwnerId = peerOwnerId,
PeerVpcId = bar.Id,
VpcId = fooAwsVpc.Id,
});
});
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/ec2"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := ec2.NewVpcPeeringConnection(ctx, "foo", &ec2.VpcPeeringConnectionArgs{
PeerOwnerId: pulumi.Any(peerOwnerId),
PeerVpcId: pulumi.Any(bar.Id),
VpcId: pulumi.Any(fooAwsVpc.Id),
})
if err != nil {
return err
}
return nil
})
}
pulumi {
required_providers {
aws = {
source = "pulumi/aws"
}
}
}
resource "aws_ec2_vpcpeeringconnection" "foo" {
peer_owner_id = peerOwnerId
peer_vpc_id = bar.id
vpc_id = fooAwsVpc.id
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.ec2.VpcPeeringConnection;
import com.pulumi.aws.ec2.VpcPeeringConnectionArgs;
import java.util.ArrayList;
import java.util.Arrays;
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) {
var foo = new VpcPeeringConnection("foo", VpcPeeringConnectionArgs.builder()
.peerOwnerId(peerOwnerId)
.peerVpcId(bar.id())
.vpcId(fooAwsVpc.id())
.build());
}
}
resources:
foo:
type: aws:ec2:VpcPeeringConnection
properties:
peerOwnerId: ${peerOwnerId}
peerVpcId: ${bar.id}
vpcId: ${fooAwsVpc.id}
Basic usage with connection options:
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const foo = new aws.ec2.VpcPeeringConnection("foo", {
accepter: {
allowRemoteVpcDnsResolution: true,
},
requester: {
allowRemoteVpcDnsResolution: true,
},
peerOwnerId: peerOwnerId,
peerVpcId: bar.id,
vpcId: fooAwsVpc.id,
});
import pulumi
import pulumi_aws as aws
foo = aws.ec2.VpcPeeringConnection("foo",
accepter={
"allow_remote_vpc_dns_resolution": True,
},
requester={
"allow_remote_vpc_dns_resolution": True,
},
peer_owner_id=peer_owner_id,
peer_vpc_id=bar["id"],
vpc_id=foo_aws_vpc["id"])
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var foo = new Aws.Ec2.VpcPeeringConnection("foo", new()
{
Accepter = new Aws.Ec2.Inputs.VpcPeeringConnectionAccepterArgs
{
AllowRemoteVpcDnsResolution = true,
},
Requester = new Aws.Ec2.Inputs.VpcPeeringConnectionRequesterArgs
{
AllowRemoteVpcDnsResolution = true,
},
PeerOwnerId = peerOwnerId,
PeerVpcId = bar.Id,
VpcId = fooAwsVpc.Id,
});
});
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/ec2"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := ec2.NewVpcPeeringConnection(ctx, "foo", &ec2.VpcPeeringConnectionArgs{
Accepter: &ec2.VpcPeeringConnectionAccepterTypeArgs{
AllowRemoteVpcDnsResolution: pulumi.Bool(true),
},
Requester: &ec2.VpcPeeringConnectionRequesterArgs{
AllowRemoteVpcDnsResolution: pulumi.Bool(true),
},
PeerOwnerId: pulumi.Any(peerOwnerId),
PeerVpcId: pulumi.Any(bar.Id),
VpcId: pulumi.Any(fooAwsVpc.Id),
})
if err != nil {
return err
}
return nil
})
}
pulumi {
required_providers {
aws = {
source = "pulumi/aws"
}
}
}
resource "aws_ec2_vpcpeeringconnection" "foo" {
accepter = {
allow_remote_vpc_dns_resolution = true
}
requester = {
allow_remote_vpc_dns_resolution = true
}
peer_owner_id = peerOwnerId
peer_vpc_id = bar.id
vpc_id = fooAwsVpc.id
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.ec2.VpcPeeringConnection;
import com.pulumi.aws.ec2.VpcPeeringConnectionArgs;
import com.pulumi.aws.ec2.inputs.VpcPeeringConnectionAccepterArgs;
import com.pulumi.aws.ec2.inputs.VpcPeeringConnectionRequesterArgs;
import java.util.ArrayList;
import java.util.Arrays;
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) {
var foo = new VpcPeeringConnection("foo", VpcPeeringConnectionArgs.builder()
.accepter(VpcPeeringConnectionAccepterArgs.builder()
.allowRemoteVpcDnsResolution(true)
.build())
.requester(VpcPeeringConnectionRequesterArgs.builder()
.allowRemoteVpcDnsResolution(true)
.build())
.peerOwnerId(peerOwnerId)
.peerVpcId(bar.id())
.vpcId(fooAwsVpc.id())
.build());
}
}
resources:
foo:
type: aws:ec2:VpcPeeringConnection
properties:
accepter:
allowRemoteVpcDnsResolution: true
requester:
allowRemoteVpcDnsResolution: true
peerOwnerId: ${peerOwnerId}
peerVpcId: ${bar.id}
vpcId: ${fooAwsVpc.id}
Basic usage with tags:
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const fooVpc = new aws.ec2.Vpc("foo", {cidrBlock: "10.1.0.0/16"});
const bar = new aws.ec2.Vpc("bar", {cidrBlock: "10.2.0.0/16"});
const foo = new aws.ec2.VpcPeeringConnection("foo", {
peerOwnerId: peerOwnerId,
peerVpcId: bar.id,
vpcId: fooVpc.id,
autoAccept: true,
tags: {
Name: "VPC Peering between foo and bar",
},
});
import pulumi
import pulumi_aws as aws
foo_vpc = aws.ec2.Vpc("foo", cidr_block="10.1.0.0/16")
bar = aws.ec2.Vpc("bar", cidr_block="10.2.0.0/16")
foo = aws.ec2.VpcPeeringConnection("foo",
peer_owner_id=peer_owner_id,
peer_vpc_id=bar.id,
vpc_id=foo_vpc.id,
auto_accept=True,
tags={
"Name": "VPC Peering between foo and bar",
})
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var fooVpc = new Aws.Ec2.Vpc("foo", new()
{
CidrBlock = "10.1.0.0/16",
});
var bar = new Aws.Ec2.Vpc("bar", new()
{
CidrBlock = "10.2.0.0/16",
});
var foo = new Aws.Ec2.VpcPeeringConnection("foo", new()
{
PeerOwnerId = peerOwnerId,
PeerVpcId = bar.Id,
VpcId = fooVpc.Id,
AutoAccept = true,
Tags =
{
{ "Name", "VPC Peering between foo and bar" },
},
});
});
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/ec2"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
fooVpc, err := ec2.NewVpc(ctx, "foo", &ec2.VpcArgs{
CidrBlock: pulumi.String("10.1.0.0/16"),
})
if err != nil {
return err
}
bar, err := ec2.NewVpc(ctx, "bar", &ec2.VpcArgs{
CidrBlock: pulumi.String("10.2.0.0/16"),
})
if err != nil {
return err
}
_, err = ec2.NewVpcPeeringConnection(ctx, "foo", &ec2.VpcPeeringConnectionArgs{
PeerOwnerId: pulumi.Any(peerOwnerId),
PeerVpcId: bar.ID().ToIDOutput().ToStringOutput(),
VpcId: fooVpc.ID().ToIDOutput().ToStringOutput(),
AutoAccept: pulumi.Bool(true),
Tags: pulumi.StringMap{
"Name": pulumi.String("VPC Peering between foo and bar"),
},
})
if err != nil {
return err
}
return nil
})
}
pulumi {
required_providers {
aws = {
source = "pulumi/aws"
}
}
}
resource "aws_ec2_vpcpeeringconnection" "foo" {
peer_owner_id = peerOwnerId
peer_vpc_id = aws_ec2_vpc.bar.id
vpc_id = aws_ec2_vpc.foo.id
auto_accept = true
tags = {
"Name" = "VPC Peering between foo and bar"
}
}
resource "aws_ec2_vpc" "foo" {
cidr_block = "10.1.0.0/16"
}
resource "aws_ec2_vpc" "bar" {
cidr_block = "10.2.0.0/16"
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.ec2.Vpc;
import com.pulumi.aws.ec2.VpcArgs;
import com.pulumi.aws.ec2.VpcPeeringConnection;
import com.pulumi.aws.ec2.VpcPeeringConnectionArgs;
import java.util.ArrayList;
import java.util.Arrays;
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) {
var fooVpc = new Vpc("fooVpc", VpcArgs.builder()
.cidrBlock("10.1.0.0/16")
.build());
var bar = new Vpc("bar", VpcArgs.builder()
.cidrBlock("10.2.0.0/16")
.build());
var foo = new VpcPeeringConnection("foo", VpcPeeringConnectionArgs.builder()
.peerOwnerId(peerOwnerId)
.peerVpcId(bar.id())
.vpcId(fooVpc.id())
.autoAccept(true)
.tags(Map.of("Name", "VPC Peering between foo and bar"))
.build());
}
}
resources:
foo:
type: aws:ec2:VpcPeeringConnection
properties:
peerOwnerId: ${peerOwnerId}
peerVpcId: ${bar.id}
vpcId: ${fooVpc.id}
autoAccept: true
tags:
Name: VPC Peering between foo and bar
fooVpc:
type: aws:ec2:Vpc
name: foo
properties:
cidrBlock: 10.1.0.0/16
bar:
type: aws:ec2:Vpc
properties:
cidrBlock: 10.2.0.0/16
Basic usage with region:
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const fooVpc = new aws.ec2.Vpc("foo", {cidrBlock: "10.1.0.0/16"});
const bar = new aws.ec2.Vpc("bar", {cidrBlock: "10.2.0.0/16"});
const foo = new aws.ec2.VpcPeeringConnection("foo", {
peerOwnerId: peerOwnerId,
peerVpcId: bar.id,
vpcId: fooVpc.id,
peerRegion: "us-east-1",
});
import pulumi
import pulumi_aws as aws
foo_vpc = aws.ec2.Vpc("foo", cidr_block="10.1.0.0/16")
bar = aws.ec2.Vpc("bar", cidr_block="10.2.0.0/16")
foo = aws.ec2.VpcPeeringConnection("foo",
peer_owner_id=peer_owner_id,
peer_vpc_id=bar.id,
vpc_id=foo_vpc.id,
peer_region="us-east-1")
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var fooVpc = new Aws.Ec2.Vpc("foo", new()
{
CidrBlock = "10.1.0.0/16",
});
var bar = new Aws.Ec2.Vpc("bar", new()
{
CidrBlock = "10.2.0.0/16",
});
var foo = new Aws.Ec2.VpcPeeringConnection("foo", new()
{
PeerOwnerId = peerOwnerId,
PeerVpcId = bar.Id,
VpcId = fooVpc.Id,
PeerRegion = "us-east-1",
});
});
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/ec2"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
fooVpc, err := ec2.NewVpc(ctx, "foo", &ec2.VpcArgs{
CidrBlock: pulumi.String("10.1.0.0/16"),
})
if err != nil {
return err
}
bar, err := ec2.NewVpc(ctx, "bar", &ec2.VpcArgs{
CidrBlock: pulumi.String("10.2.0.0/16"),
})
if err != nil {
return err
}
_, err = ec2.NewVpcPeeringConnection(ctx, "foo", &ec2.VpcPeeringConnectionArgs{
PeerOwnerId: pulumi.Any(peerOwnerId),
PeerVpcId: bar.ID().ToIDOutput().ToStringOutput(),
VpcId: fooVpc.ID().ToIDOutput().ToStringOutput(),
PeerRegion: pulumi.String("us-east-1"),
})
if err != nil {
return err
}
return nil
})
}
pulumi {
required_providers {
aws = {
source = "pulumi/aws"
}
}
}
resource "aws_ec2_vpcpeeringconnection" "foo" {
peer_owner_id = peerOwnerId
peer_vpc_id = aws_ec2_vpc.bar.id
vpc_id = aws_ec2_vpc.foo.id
peer_region = "us-east-1"
}
resource "aws_ec2_vpc" "foo" {
cidr_block = "10.1.0.0/16"
}
resource "aws_ec2_vpc" "bar" {
cidr_block = "10.2.0.0/16"
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.ec2.Vpc;
import com.pulumi.aws.ec2.VpcArgs;
import com.pulumi.aws.ec2.VpcPeeringConnection;
import com.pulumi.aws.ec2.VpcPeeringConnectionArgs;
import java.util.ArrayList;
import java.util.Arrays;
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) {
var fooVpc = new Vpc("fooVpc", VpcArgs.builder()
.cidrBlock("10.1.0.0/16")
.build());
var bar = new Vpc("bar", VpcArgs.builder()
.cidrBlock("10.2.0.0/16")
.build());
var foo = new VpcPeeringConnection("foo", VpcPeeringConnectionArgs.builder()
.peerOwnerId(peerOwnerId)
.peerVpcId(bar.id())
.vpcId(fooVpc.id())
.peerRegion("us-east-1")
.build());
}
}
resources:
foo:
type: aws:ec2:VpcPeeringConnection
properties:
peerOwnerId: ${peerOwnerId}
peerVpcId: ${bar.id}
vpcId: ${fooVpc.id}
peerRegion: us-east-1
fooVpc:
type: aws:ec2:Vpc
name: foo
properties:
cidrBlock: 10.1.0.0/16
bar:
type: aws:ec2:Vpc
properties:
cidrBlock: 10.2.0.0/16
Import
Using pulumi import, import VPC Peering resources using the VPC peering id. For example:
$ pulumi import aws:ec2/vpcPeeringConnection:VpcPeeringConnection test_connection pcx-111aaa111
Constructors
- VpcPeeringConnection(String name, {VpcPeeringConnectionArgs? args, CustomResourceOptions? options})
-
Creates a new VpcPeeringConnection.
nameThe Pulumi resource name.argsArguments used to configure this VpcPeeringConnection. The set of arguments for VpcPeeringConnection.optionsResource options controlling this resource's behavior. - VpcPeeringConnection.reference(String urn)
- Creates a typed reference to an existing VpcPeeringConnection resource.
Properties
-
accepter
↔ Output<
VpcPeeringConnectionAccepter> -
An optional configuration block that allows for VPC Peering Connection options to be set for the VPC that accepts
the peering connection (a maximum of one).
latefinal
-
acceptStatus
↔ Output<
String> -
The status of the VPC Peering Connection request.
latefinal
-
autoAccept
↔ Output<
bool?> -
Accept the peering (both VPCs need to be in the same AWS account and region).
latefinal
-
childResources
→ Set<
Resource> -
finalinherited
-
completionSources
↔ Map<
String, IOutputCompletionSource> -
latefinalinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
-
id
↔ Output<
String> -
getter/setter pairinherited
- isCustom → bool
-
Returns whether this resource is provider-managed.
no setterinherited
- isProtected → bool
-
Returns whether this resource is protected from deletion.
no setterinherited
- isRemote → bool
-
Whether this resource is registered as remote.
no setterinherited
- isResourceReference → bool
-
Whether this instance represents a resource value returned over RPC.
finalinherited
-
peerOwnerId
↔ Output<
String> -
The AWS account ID of the target peer VPC.
Defaults to the account ID the AWS provider is currently connected to, so must be managed if connecting cross-account.
latefinal
-
peerRegion
↔ Output<
String> -
The region of the accepter VPC of the VPC Peering Connection.
autoAcceptmust befalse, and use theaws.ec2.VpcPeeringConnectionAccepterto manage the accepter side.latefinal -
peerVpcId
↔ Output<
String> -
The ID of the target VPC with which you are creating the VPC Peering Connection.
latefinal
-
region
↔ Output<
String> -
Region where this resource will be managed. Defaults to the Region set in the provider configuration.
latefinal
-
requester
↔ Output<
VpcPeeringConnectionRequester> -
A optional configuration block that allows for VPC Peering Connection options to be set for the VPC that requests
the peering connection (a maximum of one).
latefinal
-
resourceTransforms
→ List<
ResourceTransform> -
Inherited/explicit async transforms.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
A map of tags to assign to the resource. .If configured with a provider
defaultTagsconfiguration block present, tags with matching keys will overwrite those defined at the provider-level.latefinal -
A map of tags assigned to the resource, including those inherited from the provider
defaultTagsconfiguration block.latefinal -
transformations
→ List<
ResourceTransformation> -
Inherited/explicit legacy transformations.
no setterinherited
-
urn
↔ Output<
String> -
latefinalinherited
-
vpcId
↔ Output<
String> -
The ID of the requester VPC.
latefinal
Methods
-
failId(
Object error) → void -
Completes this resource ID with an error when registration fails.
inherited
-
failOutputs(
Object error) → void -
Completes all output properties with
error.inherited -
failUrn(
Object error) → void -
Completes this resource URN with an error when registration fails.
inherited
-
getProvider(
String moduleMember) → ProviderResource? -
Returns provider for
moduleMember's package, if configured.inherited -
getResourceName(
) → String -
Returns this resource's logical name.
inherited
-
getResourceType(
) → String -
Returns this resource's Pulumi type token.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
registerOutput<
T> (String propertyName, {Object? decoder(Object?)?, bool isSecret = false}) → Output< T> -
Registers a dynamic output property for this resource.
inherited
-
resolveId(
String? value, {required bool isKnown}) → void -
Resolves the provider-assigned ID for this resource.
inherited
-
resolveOutputs(
Struct outputs) → void -
Resolves all output properties from a monitor response payload.
inherited
-
resolveUrn(
String value) → void -
Resolves this resource's URN once assigned by the engine.
inherited
-
serializeProperties(
Map< String, dynamic> properties) → Future<Struct> -
Serializes resource properties for RPC transmission.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
get(
String name, Input< String> id, {VpcPeeringConnectionState? state, CustomResourceOptions? options}) → VpcPeeringConnection -
Gets an existing VpcPeeringConnection resource's state with the given
nameandid.