Skip to content

Commit 1e69cc6

Browse files
authored
feat(elbv2): Implement IConnectable to NLB (#28494)
# Summary Implement an `IConnectable` interface to a NetworkLoadBalancer. # Why need this change? AWS CDK has great features for abstraction. `IConnectable` interface is one of this. `IConnectable` simplifies the management of security groups. AWS CDK add support security group to NLB at #27978. However, Currently NLB not implement `IConnectable`, so customers can't use useful interface in AWS CDK. # Example use case ```ts declare const lb: elbv2.NetworkLoadBalancer; declare const asg: autoscaling.AutoScalingGroup; asg.connections.allowFrom(lb, ec2.Port.tcp(8088)); // currently can not ``` Closes #26735 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent c0085d5 commit 1e69cc6

25 files changed

+35541
-292
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-elasticloadbalancingv2/test/integ.nlb-lookup.js.snapshot/aws-cdk-elbv2-StackWithLb.assets.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-elasticloadbalancingv2/test/integ.nlb-lookup.js.snapshot/aws-cdk-elbv2-StackWithLb.template.json

+100-54
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
"VPCPublicSubnet1SubnetB4246D30": {
1919
"Type": "AWS::EC2::Subnet",
2020
"Properties": {
21-
"VpcId": {
22-
"Ref": "VPCB9E5F0B4"
23-
},
2421
"AvailabilityZone": "test-region-1a",
2522
"CidrBlock": "10.0.0.0/18",
2623
"MapPublicIpOnLaunch": true,
@@ -37,21 +34,24 @@
3734
"Key": "Name",
3835
"Value": "aws-cdk-elbv2-StackWithLb/VPC/PublicSubnet1"
3936
}
40-
]
37+
],
38+
"VpcId": {
39+
"Ref": "VPCB9E5F0B4"
40+
}
4141
}
4242
},
4343
"VPCPublicSubnet1RouteTableFEE4B781": {
4444
"Type": "AWS::EC2::RouteTable",
4545
"Properties": {
46-
"VpcId": {
47-
"Ref": "VPCB9E5F0B4"
48-
},
4946
"Tags": [
5047
{
5148
"Key": "Name",
5249
"Value": "aws-cdk-elbv2-StackWithLb/VPC/PublicSubnet1"
5350
}
54-
]
51+
],
52+
"VpcId": {
53+
"Ref": "VPCB9E5F0B4"
54+
}
5555
}
5656
},
5757
"VPCPublicSubnet1RouteTableAssociation0B0896DC": {
@@ -68,12 +68,12 @@
6868
"VPCPublicSubnet1DefaultRoute91CEF279": {
6969
"Type": "AWS::EC2::Route",
7070
"Properties": {
71-
"RouteTableId": {
72-
"Ref": "VPCPublicSubnet1RouteTableFEE4B781"
73-
},
7471
"DestinationCidrBlock": "0.0.0.0/0",
7572
"GatewayId": {
7673
"Ref": "VPCIGWB7E252D3"
74+
},
75+
"RouteTableId": {
76+
"Ref": "VPCPublicSubnet1RouteTableFEE4B781"
7777
}
7878
},
7979
"DependsOn": [
@@ -95,15 +95,15 @@
9595
"VPCPublicSubnet1NATGatewayE0556630": {
9696
"Type": "AWS::EC2::NatGateway",
9797
"Properties": {
98-
"SubnetId": {
99-
"Ref": "VPCPublicSubnet1SubnetB4246D30"
100-
},
10198
"AllocationId": {
10299
"Fn::GetAtt": [
103100
"VPCPublicSubnet1EIP6AD938E8",
104101
"AllocationId"
105102
]
106103
},
104+
"SubnetId": {
105+
"Ref": "VPCPublicSubnet1SubnetB4246D30"
106+
},
107107
"Tags": [
108108
{
109109
"Key": "Name",
@@ -119,9 +119,6 @@
119119
"VPCPublicSubnet2Subnet74179F39": {
120120
"Type": "AWS::EC2::Subnet",
121121
"Properties": {
122-
"VpcId": {
123-
"Ref": "VPCB9E5F0B4"
124-
},
125122
"AvailabilityZone": "test-region-1b",
126123
"CidrBlock": "10.0.64.0/18",
127124
"MapPublicIpOnLaunch": true,
@@ -138,21 +135,24 @@
138135
"Key": "Name",
139136
"Value": "aws-cdk-elbv2-StackWithLb/VPC/PublicSubnet2"
140137
}
141-
]
138+
],
139+
"VpcId": {
140+
"Ref": "VPCB9E5F0B4"
141+
}
142142
}
143143
},
144144
"VPCPublicSubnet2RouteTable6F1A15F1": {
145145
"Type": "AWS::EC2::RouteTable",
146146
"Properties": {
147-
"VpcId": {
148-
"Ref": "VPCB9E5F0B4"
149-
},
150147
"Tags": [
151148
{
152149
"Key": "Name",
153150
"Value": "aws-cdk-elbv2-StackWithLb/VPC/PublicSubnet2"
154151
}
155-
]
152+
],
153+
"VpcId": {
154+
"Ref": "VPCB9E5F0B4"
155+
}
156156
}
157157
},
158158
"VPCPublicSubnet2RouteTableAssociation5A808732": {
@@ -169,12 +169,12 @@
169169
"VPCPublicSubnet2DefaultRouteB7481BBA": {
170170
"Type": "AWS::EC2::Route",
171171
"Properties": {
172-
"RouteTableId": {
173-
"Ref": "VPCPublicSubnet2RouteTable6F1A15F1"
174-
},
175172
"DestinationCidrBlock": "0.0.0.0/0",
176173
"GatewayId": {
177174
"Ref": "VPCIGWB7E252D3"
175+
},
176+
"RouteTableId": {
177+
"Ref": "VPCPublicSubnet2RouteTable6F1A15F1"
178178
}
179179
},
180180
"DependsOn": [
@@ -196,15 +196,15 @@
196196
"VPCPublicSubnet2NATGateway3C070193": {
197197
"Type": "AWS::EC2::NatGateway",
198198
"Properties": {
199-
"SubnetId": {
200-
"Ref": "VPCPublicSubnet2Subnet74179F39"
201-
},
202199
"AllocationId": {
203200
"Fn::GetAtt": [
204201
"VPCPublicSubnet2EIP4947BC00",
205202
"AllocationId"
206203
]
207204
},
205+
"SubnetId": {
206+
"Ref": "VPCPublicSubnet2Subnet74179F39"
207+
},
208208
"Tags": [
209209
{
210210
"Key": "Name",
@@ -220,9 +220,6 @@
220220
"VPCPrivateSubnet1Subnet8BCA10E0": {
221221
"Type": "AWS::EC2::Subnet",
222222
"Properties": {
223-
"VpcId": {
224-
"Ref": "VPCB9E5F0B4"
225-
},
226223
"AvailabilityZone": "test-region-1a",
227224
"CidrBlock": "10.0.128.0/18",
228225
"MapPublicIpOnLaunch": false,
@@ -239,21 +236,24 @@
239236
"Key": "Name",
240237
"Value": "aws-cdk-elbv2-StackWithLb/VPC/PrivateSubnet1"
241238
}
242-
]
239+
],
240+
"VpcId": {
241+
"Ref": "VPCB9E5F0B4"
242+
}
243243
}
244244
},
245245
"VPCPrivateSubnet1RouteTableBE8A6027": {
246246
"Type": "AWS::EC2::RouteTable",
247247
"Properties": {
248-
"VpcId": {
249-
"Ref": "VPCB9E5F0B4"
250-
},
251248
"Tags": [
252249
{
253250
"Key": "Name",
254251
"Value": "aws-cdk-elbv2-StackWithLb/VPC/PrivateSubnet1"
255252
}
256-
]
253+
],
254+
"VpcId": {
255+
"Ref": "VPCB9E5F0B4"
256+
}
257257
}
258258
},
259259
"VPCPrivateSubnet1RouteTableAssociation347902D1": {
@@ -270,21 +270,18 @@
270270
"VPCPrivateSubnet1DefaultRouteAE1D6490": {
271271
"Type": "AWS::EC2::Route",
272272
"Properties": {
273-
"RouteTableId": {
274-
"Ref": "VPCPrivateSubnet1RouteTableBE8A6027"
275-
},
276273
"DestinationCidrBlock": "0.0.0.0/0",
277274
"NatGatewayId": {
278275
"Ref": "VPCPublicSubnet1NATGatewayE0556630"
276+
},
277+
"RouteTableId": {
278+
"Ref": "VPCPrivateSubnet1RouteTableBE8A6027"
279279
}
280280
}
281281
},
282282
"VPCPrivateSubnet2SubnetCFCDAA7A": {
283283
"Type": "AWS::EC2::Subnet",
284284
"Properties": {
285-
"VpcId": {
286-
"Ref": "VPCB9E5F0B4"
287-
},
288285
"AvailabilityZone": "test-region-1b",
289286
"CidrBlock": "10.0.192.0/18",
290287
"MapPublicIpOnLaunch": false,
@@ -301,21 +298,24 @@
301298
"Key": "Name",
302299
"Value": "aws-cdk-elbv2-StackWithLb/VPC/PrivateSubnet2"
303300
}
304-
]
301+
],
302+
"VpcId": {
303+
"Ref": "VPCB9E5F0B4"
304+
}
305305
}
306306
},
307307
"VPCPrivateSubnet2RouteTable0A19E10E": {
308308
"Type": "AWS::EC2::RouteTable",
309309
"Properties": {
310-
"VpcId": {
311-
"Ref": "VPCB9E5F0B4"
312-
},
313310
"Tags": [
314311
{
315312
"Key": "Name",
316313
"Value": "aws-cdk-elbv2-StackWithLb/VPC/PrivateSubnet2"
317314
}
318-
]
315+
],
316+
"VpcId": {
317+
"Ref": "VPCB9E5F0B4"
318+
}
319319
}
320320
},
321321
"VPCPrivateSubnet2RouteTableAssociation0C73D413": {
@@ -332,12 +332,12 @@
332332
"VPCPrivateSubnet2DefaultRouteF4F5CFD2": {
333333
"Type": "AWS::EC2::Route",
334334
"Properties": {
335-
"RouteTableId": {
336-
"Ref": "VPCPrivateSubnet2RouteTable0A19E10E"
337-
},
338335
"DestinationCidrBlock": "0.0.0.0/0",
339336
"NatGatewayId": {
340337
"Ref": "VPCPublicSubnet2NATGateway3C070193"
338+
},
339+
"RouteTableId": {
340+
"Ref": "VPCPrivateSubnet2RouteTable0A19E10E"
341341
}
342342
}
343343
},
@@ -355,11 +355,27 @@
355355
"VPCVPCGW99B986DC": {
356356
"Type": "AWS::EC2::VPCGatewayAttachment",
357357
"Properties": {
358-
"VpcId": {
359-
"Ref": "VPCB9E5F0B4"
360-
},
361358
"InternetGatewayId": {
362359
"Ref": "VPCIGWB7E252D3"
360+
},
361+
"VpcId": {
362+
"Ref": "VPCB9E5F0B4"
363+
}
364+
}
365+
},
366+
"SGADB53937": {
367+
"Type": "AWS::EC2::SecurityGroup",
368+
"Properties": {
369+
"GroupDescription": "aws-cdk-elbv2-StackWithLb/SG",
370+
"SecurityGroupEgress": [
371+
{
372+
"CidrIp": "0.0.0.0/0",
373+
"Description": "Allow all outbound traffic by default",
374+
"IpProtocol": "-1"
375+
}
376+
],
377+
"VpcId": {
378+
"Ref": "VPCB9E5F0B4"
363379
}
364380
}
365381
},
@@ -374,6 +390,14 @@
374390
],
375391
"Name": "my-load-balancer",
376392
"Scheme": "internet-facing",
393+
"SecurityGroups": [
394+
{
395+
"Fn::GetAtt": [
396+
"SGADB53937",
397+
"GroupId"
398+
]
399+
}
400+
],
377401
"Subnets": [
378402
{
379403
"Ref": "VPCPublicSubnet1SubnetB4246D30"
@@ -414,12 +438,12 @@
414438
"Properties": {
415439
"Port": 443,
416440
"Protocol": "TCP",
441+
"TargetType": "ip",
417442
"Targets": [
418443
{
419444
"Id": "10.0.1.1"
420445
}
421446
],
422-
"TargetType": "ip",
423447
"VpcId": {
424448
"Ref": "VPCB9E5F0B4"
425449
}
@@ -443,6 +467,28 @@
443467
"Name": "TgArn"
444468
}
445469
},
470+
"SgId": {
471+
"Value": {
472+
"Fn::GetAtt": [
473+
"SGADB53937",
474+
"GroupId"
475+
]
476+
},
477+
"Export": {
478+
"Name": "SgId"
479+
}
480+
},
481+
"ExportsOutputFnGetAttSGADB53937GroupId97E49F2D": {
482+
"Value": {
483+
"Fn::GetAtt": [
484+
"SGADB53937",
485+
"GroupId"
486+
]
487+
},
488+
"Export": {
489+
"Name": "aws-cdk-elbv2-StackWithLb:ExportsOutputFnGetAttSGADB53937GroupId97E49F2D"
490+
}
491+
},
446492
"ExportsOutputRefLB8A12904C1150D6A6": {
447493
"Value": {
448494
"Ref": "LB8A12904C"

packages/@aws-cdk-testing/framework-integ/test/aws-elasticloadbalancingv2/test/integ.nlb-lookup.js.snapshot/aws-cdk-elbv2-integ-StackUnderTest.assets.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)