Skip to content

Commit

Permalink
feat(aws-ec2): add VPC context provider (#1168)
Browse files Browse the repository at this point in the history
Add a context provider for looking up existing VPCs in an account. This
is useful if the VPC is defined outside of your CDK app, such as in a
different CDK app, by hand or in a CloudFormation template.

Addresses some of the needs in #1095.
  • Loading branch information
rix0rrr authored Nov 15, 2018
1 parent 020743b commit e8380fa
Show file tree
Hide file tree
Showing 45 changed files with 1,757 additions and 523 deletions.
13 changes: 13 additions & 0 deletions docs/src/context.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,16 @@ The |cdk| currently supports the following context providers.
const zone: HostedZoneRef = new HostedZoneProvider(this, {
domainName: 'test.com'
}).findAndImport(this, 'HostedZone');
:py:class:`VpcNetworkProvider <@aws-cdk/aws-ec2.VpcNetworkProvider>`
Use this provider to look up and reference existing VPC in your accounts.
For example, the follow code imports a VPC by tag name:

.. code:: js
const provider = new VpcNetworkProvider(this, {
tags: {
Purpose: 'WebServices'
}
});
const vpc = VpcNetworkRef.import(this, 'VPC', provider.vpcProps);
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
{
"Key": "Name",
"Value": "aws-cdk-autoscaling-integ/VPC/PublicSubnet1"
},
{
"Key": "aws-cdk:subnet-name",
"Value": "Public"
},
{
"Key": "aws-cdk:subnet-type",
"Value": "Public"
}
]
}
Expand Down Expand Up @@ -111,6 +119,14 @@
{
"Key": "Name",
"Value": "aws-cdk-autoscaling-integ/VPC/PublicSubnet2"
},
{
"Key": "aws-cdk:subnet-name",
"Value": "Public"
},
{
"Key": "aws-cdk:subnet-type",
"Value": "Public"
}
]
}
Expand Down Expand Up @@ -194,6 +210,14 @@
{
"Key": "Name",
"Value": "aws-cdk-autoscaling-integ/VPC/PrivateSubnet1"
},
{
"Key": "aws-cdk:subnet-name",
"Value": "Private"
},
{
"Key": "aws-cdk:subnet-type",
"Value": "Private"
}
]
}
Expand Down Expand Up @@ -248,6 +272,14 @@
{
"Key": "Name",
"Value": "aws-cdk-autoscaling-integ/VPC/PrivateSubnet2"
},
{
"Key": "aws-cdk:subnet-name",
"Value": "Private"
},
{
"Key": "aws-cdk:subnet-type",
"Value": "Private"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
{
"Key": "Name",
"Value": "aws-cdk-ec2-integ/VPC/PublicSubnet1"
},
{
"Key": "aws-cdk:subnet-name",
"Value": "Public"
},
{
"Key": "aws-cdk:subnet-type",
"Value": "Public"
}
]
}
Expand Down Expand Up @@ -57,6 +65,21 @@
}
}
},
"VPCPublicSubnet1DefaultRoute91CEF279": {
"Type": "AWS::EC2::Route",
"DependsOn": [
"VPCVPCGW99B986DC"
],
"Properties": {
"RouteTableId": {
"Ref": "VPCPublicSubnet1RouteTableFEE4B781"
},
"DestinationCidrBlock": "0.0.0.0/0",
"GatewayId": {
"Ref": "VPCIGWB7E252D3"
}
}
},
"VPCPublicSubnet1EIP6AD938E8": {
"Type": "AWS::EC2::EIP",
"Properties": {
Expand All @@ -83,21 +106,6 @@
]
}
},
"VPCPublicSubnet1DefaultRoute91CEF279": {
"Type": "AWS::EC2::Route",
"DependsOn": [
"VPCVPCGW99B986DC"
],
"Properties": {
"RouteTableId": {
"Ref": "VPCPublicSubnet1RouteTableFEE4B781"
},
"DestinationCidrBlock": "0.0.0.0/0",
"GatewayId": {
"Ref": "VPCIGWB7E252D3"
}
}
},
"VPCPublicSubnet2Subnet74179F39": {
"Type": "AWS::EC2::Subnet",
"Properties": {
Expand All @@ -111,6 +119,14 @@
{
"Key": "Name",
"Value": "aws-cdk-ec2-integ/VPC/PublicSubnet2"
},
{
"Key": "aws-cdk:subnet-name",
"Value": "Public"
},
{
"Key": "aws-cdk:subnet-type",
"Value": "Public"
}
]
}
Expand Down Expand Up @@ -140,6 +156,21 @@
}
}
},
"VPCPublicSubnet2DefaultRouteB7481BBA": {
"Type": "AWS::EC2::Route",
"DependsOn": [
"VPCVPCGW99B986DC"
],
"Properties": {
"RouteTableId": {
"Ref": "VPCPublicSubnet2RouteTable6F1A15F1"
},
"DestinationCidrBlock": "0.0.0.0/0",
"GatewayId": {
"Ref": "VPCIGWB7E252D3"
}
}
},
"VPCPublicSubnet2EIP4947BC00": {
"Type": "AWS::EC2::EIP",
"Properties": {
Expand All @@ -166,21 +197,6 @@
]
}
},
"VPCPublicSubnet2DefaultRouteB7481BBA": {
"Type": "AWS::EC2::Route",
"DependsOn": [
"VPCVPCGW99B986DC"
],
"Properties": {
"RouteTableId": {
"Ref": "VPCPublicSubnet2RouteTable6F1A15F1"
},
"DestinationCidrBlock": "0.0.0.0/0",
"GatewayId": {
"Ref": "VPCIGWB7E252D3"
}
}
},
"VPCPublicSubnet3Subnet631C5E25": {
"Type": "AWS::EC2::Subnet",
"Properties": {
Expand All @@ -194,6 +210,14 @@
{
"Key": "Name",
"Value": "aws-cdk-ec2-integ/VPC/PublicSubnet3"
},
{
"Key": "aws-cdk:subnet-name",
"Value": "Public"
},
{
"Key": "aws-cdk:subnet-type",
"Value": "Public"
}
]
}
Expand Down Expand Up @@ -223,6 +247,21 @@
}
}
},
"VPCPublicSubnet3DefaultRouteA0D29D46": {
"Type": "AWS::EC2::Route",
"DependsOn": [
"VPCVPCGW99B986DC"
],
"Properties": {
"RouteTableId": {
"Ref": "VPCPublicSubnet3RouteTable98AE0E14"
},
"DestinationCidrBlock": "0.0.0.0/0",
"GatewayId": {
"Ref": "VPCIGWB7E252D3"
}
}
},
"VPCPublicSubnet3EIPAD4BC883": {
"Type": "AWS::EC2::EIP",
"Properties": {
Expand All @@ -249,21 +288,6 @@
]
}
},
"VPCPublicSubnet3DefaultRouteA0D29D46": {
"Type": "AWS::EC2::Route",
"DependsOn": [
"VPCVPCGW99B986DC"
],
"Properties": {
"RouteTableId": {
"Ref": "VPCPublicSubnet3RouteTable98AE0E14"
},
"DestinationCidrBlock": "0.0.0.0/0",
"GatewayId": {
"Ref": "VPCIGWB7E252D3"
}
}
},
"VPCPrivateSubnet1Subnet8BCA10E0": {
"Type": "AWS::EC2::Subnet",
"Properties": {
Expand All @@ -277,6 +301,14 @@
{
"Key": "Name",
"Value": "aws-cdk-ec2-integ/VPC/PrivateSubnet1"
},
{
"Key": "aws-cdk:subnet-name",
"Value": "Private"
},
{
"Key": "aws-cdk:subnet-type",
"Value": "Private"
}
]
}
Expand Down Expand Up @@ -331,6 +363,14 @@
{
"Key": "Name",
"Value": "aws-cdk-ec2-integ/VPC/PrivateSubnet2"
},
{
"Key": "aws-cdk:subnet-name",
"Value": "Private"
},
{
"Key": "aws-cdk:subnet-type",
"Value": "Private"
}
]
}
Expand Down Expand Up @@ -385,6 +425,14 @@
{
"Key": "Name",
"Value": "aws-cdk-ec2-integ/VPC/PrivateSubnet3"
},
{
"Key": "aws-cdk:subnet-name",
"Value": "Private"
},
{
"Key": "aws-cdk:subnet-type",
"Value": "Private"
}
]
}
Expand Down Expand Up @@ -663,4 +711,4 @@
}
}
}
}
}
Loading

0 comments on commit e8380fa

Please sign in to comment.