Skip to content

Commit e8380fa

Browse files
authored
feat(aws-ec2): add VPC context provider (#1168)
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.
1 parent 020743b commit e8380fa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1757
-523
lines changed

docs/src/context.rst

+13
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,16 @@ The |cdk| currently supports the following context providers.
5656
const zone: HostedZoneRef = new HostedZoneProvider(this, {
5757
domainName: 'test.com'
5858
}).findAndImport(this, 'HostedZone');
59+
60+
:py:class:`VpcNetworkProvider <@aws-cdk/aws-ec2.VpcNetworkProvider>`
61+
Use this provider to look up and reference existing VPC in your accounts.
62+
For example, the follow code imports a VPC by tag name:
63+
64+
.. code:: js
65+
66+
const provider = new VpcNetworkProvider(this, {
67+
tags: {
68+
Purpose: 'WebServices'
69+
}
70+
});
71+
const vpc = VpcNetworkRef.import(this, 'VPC', provider.vpcProps);

packages/@aws-cdk/aws-autoscaling/test/integ.amazonlinux2.expected.json

+32
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@
2828
{
2929
"Key": "Name",
3030
"Value": "aws-cdk-autoscaling-integ/VPC/PublicSubnet1"
31+
},
32+
{
33+
"Key": "aws-cdk:subnet-name",
34+
"Value": "Public"
35+
},
36+
{
37+
"Key": "aws-cdk:subnet-type",
38+
"Value": "Public"
3139
}
3240
]
3341
}
@@ -111,6 +119,14 @@
111119
{
112120
"Key": "Name",
113121
"Value": "aws-cdk-autoscaling-integ/VPC/PublicSubnet2"
122+
},
123+
{
124+
"Key": "aws-cdk:subnet-name",
125+
"Value": "Public"
126+
},
127+
{
128+
"Key": "aws-cdk:subnet-type",
129+
"Value": "Public"
114130
}
115131
]
116132
}
@@ -194,6 +210,14 @@
194210
{
195211
"Key": "Name",
196212
"Value": "aws-cdk-autoscaling-integ/VPC/PrivateSubnet1"
213+
},
214+
{
215+
"Key": "aws-cdk:subnet-name",
216+
"Value": "Private"
217+
},
218+
{
219+
"Key": "aws-cdk:subnet-type",
220+
"Value": "Private"
197221
}
198222
]
199223
}
@@ -248,6 +272,14 @@
248272
{
249273
"Key": "Name",
250274
"Value": "aws-cdk-autoscaling-integ/VPC/PrivateSubnet2"
275+
},
276+
{
277+
"Key": "aws-cdk:subnet-name",
278+
"Value": "Private"
279+
},
280+
{
281+
"Key": "aws-cdk:subnet-type",
282+
"Value": "Private"
251283
}
252284
]
253285
}

packages/@aws-cdk/aws-autoscaling/test/integ.asg-w-classic-loadbalancer.expected.json

+94-46
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@
2828
{
2929
"Key": "Name",
3030
"Value": "aws-cdk-ec2-integ/VPC/PublicSubnet1"
31+
},
32+
{
33+
"Key": "aws-cdk:subnet-name",
34+
"Value": "Public"
35+
},
36+
{
37+
"Key": "aws-cdk:subnet-type",
38+
"Value": "Public"
3139
}
3240
]
3341
}
@@ -57,6 +65,21 @@
5765
}
5866
}
5967
},
68+
"VPCPublicSubnet1DefaultRoute91CEF279": {
69+
"Type": "AWS::EC2::Route",
70+
"DependsOn": [
71+
"VPCVPCGW99B986DC"
72+
],
73+
"Properties": {
74+
"RouteTableId": {
75+
"Ref": "VPCPublicSubnet1RouteTableFEE4B781"
76+
},
77+
"DestinationCidrBlock": "0.0.0.0/0",
78+
"GatewayId": {
79+
"Ref": "VPCIGWB7E252D3"
80+
}
81+
}
82+
},
6083
"VPCPublicSubnet1EIP6AD938E8": {
6184
"Type": "AWS::EC2::EIP",
6285
"Properties": {
@@ -83,21 +106,6 @@
83106
]
84107
}
85108
},
86-
"VPCPublicSubnet1DefaultRoute91CEF279": {
87-
"Type": "AWS::EC2::Route",
88-
"DependsOn": [
89-
"VPCVPCGW99B986DC"
90-
],
91-
"Properties": {
92-
"RouteTableId": {
93-
"Ref": "VPCPublicSubnet1RouteTableFEE4B781"
94-
},
95-
"DestinationCidrBlock": "0.0.0.0/0",
96-
"GatewayId": {
97-
"Ref": "VPCIGWB7E252D3"
98-
}
99-
}
100-
},
101109
"VPCPublicSubnet2Subnet74179F39": {
102110
"Type": "AWS::EC2::Subnet",
103111
"Properties": {
@@ -111,6 +119,14 @@
111119
{
112120
"Key": "Name",
113121
"Value": "aws-cdk-ec2-integ/VPC/PublicSubnet2"
122+
},
123+
{
124+
"Key": "aws-cdk:subnet-name",
125+
"Value": "Public"
126+
},
127+
{
128+
"Key": "aws-cdk:subnet-type",
129+
"Value": "Public"
114130
}
115131
]
116132
}
@@ -140,6 +156,21 @@
140156
}
141157
}
142158
},
159+
"VPCPublicSubnet2DefaultRouteB7481BBA": {
160+
"Type": "AWS::EC2::Route",
161+
"DependsOn": [
162+
"VPCVPCGW99B986DC"
163+
],
164+
"Properties": {
165+
"RouteTableId": {
166+
"Ref": "VPCPublicSubnet2RouteTable6F1A15F1"
167+
},
168+
"DestinationCidrBlock": "0.0.0.0/0",
169+
"GatewayId": {
170+
"Ref": "VPCIGWB7E252D3"
171+
}
172+
}
173+
},
143174
"VPCPublicSubnet2EIP4947BC00": {
144175
"Type": "AWS::EC2::EIP",
145176
"Properties": {
@@ -166,21 +197,6 @@
166197
]
167198
}
168199
},
169-
"VPCPublicSubnet2DefaultRouteB7481BBA": {
170-
"Type": "AWS::EC2::Route",
171-
"DependsOn": [
172-
"VPCVPCGW99B986DC"
173-
],
174-
"Properties": {
175-
"RouteTableId": {
176-
"Ref": "VPCPublicSubnet2RouteTable6F1A15F1"
177-
},
178-
"DestinationCidrBlock": "0.0.0.0/0",
179-
"GatewayId": {
180-
"Ref": "VPCIGWB7E252D3"
181-
}
182-
}
183-
},
184200
"VPCPublicSubnet3Subnet631C5E25": {
185201
"Type": "AWS::EC2::Subnet",
186202
"Properties": {
@@ -194,6 +210,14 @@
194210
{
195211
"Key": "Name",
196212
"Value": "aws-cdk-ec2-integ/VPC/PublicSubnet3"
213+
},
214+
{
215+
"Key": "aws-cdk:subnet-name",
216+
"Value": "Public"
217+
},
218+
{
219+
"Key": "aws-cdk:subnet-type",
220+
"Value": "Public"
197221
}
198222
]
199223
}
@@ -223,6 +247,21 @@
223247
}
224248
}
225249
},
250+
"VPCPublicSubnet3DefaultRouteA0D29D46": {
251+
"Type": "AWS::EC2::Route",
252+
"DependsOn": [
253+
"VPCVPCGW99B986DC"
254+
],
255+
"Properties": {
256+
"RouteTableId": {
257+
"Ref": "VPCPublicSubnet3RouteTable98AE0E14"
258+
},
259+
"DestinationCidrBlock": "0.0.0.0/0",
260+
"GatewayId": {
261+
"Ref": "VPCIGWB7E252D3"
262+
}
263+
}
264+
},
226265
"VPCPublicSubnet3EIPAD4BC883": {
227266
"Type": "AWS::EC2::EIP",
228267
"Properties": {
@@ -249,21 +288,6 @@
249288
]
250289
}
251290
},
252-
"VPCPublicSubnet3DefaultRouteA0D29D46": {
253-
"Type": "AWS::EC2::Route",
254-
"DependsOn": [
255-
"VPCVPCGW99B986DC"
256-
],
257-
"Properties": {
258-
"RouteTableId": {
259-
"Ref": "VPCPublicSubnet3RouteTable98AE0E14"
260-
},
261-
"DestinationCidrBlock": "0.0.0.0/0",
262-
"GatewayId": {
263-
"Ref": "VPCIGWB7E252D3"
264-
}
265-
}
266-
},
267291
"VPCPrivateSubnet1Subnet8BCA10E0": {
268292
"Type": "AWS::EC2::Subnet",
269293
"Properties": {
@@ -277,6 +301,14 @@
277301
{
278302
"Key": "Name",
279303
"Value": "aws-cdk-ec2-integ/VPC/PrivateSubnet1"
304+
},
305+
{
306+
"Key": "aws-cdk:subnet-name",
307+
"Value": "Private"
308+
},
309+
{
310+
"Key": "aws-cdk:subnet-type",
311+
"Value": "Private"
280312
}
281313
]
282314
}
@@ -331,6 +363,14 @@
331363
{
332364
"Key": "Name",
333365
"Value": "aws-cdk-ec2-integ/VPC/PrivateSubnet2"
366+
},
367+
{
368+
"Key": "aws-cdk:subnet-name",
369+
"Value": "Private"
370+
},
371+
{
372+
"Key": "aws-cdk:subnet-type",
373+
"Value": "Private"
334374
}
335375
]
336376
}
@@ -385,6 +425,14 @@
385425
{
386426
"Key": "Name",
387427
"Value": "aws-cdk-ec2-integ/VPC/PrivateSubnet3"
428+
},
429+
{
430+
"Key": "aws-cdk:subnet-name",
431+
"Value": "Private"
432+
},
433+
{
434+
"Key": "aws-cdk:subnet-type",
435+
"Value": "Private"
388436
}
389437
]
390438
}
@@ -663,4 +711,4 @@
663711
}
664712
}
665713
}
666-
}
714+
}

0 commit comments

Comments
 (0)