Skip to content

Commit 2d80813

Browse files
authored
chore(elbv2): fix broken integration tests (#19693)
Target group was being created before the subnet so the IP address had not been allocated. ---- ### All Submissions: * [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)? * [ ] Did you use `cdk-integ` to deploy the infrastructure and generate the snapshot (i.e. `cdk-integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent a298297 commit 2d80813

File tree

6 files changed

+151
-48
lines changed

6 files changed

+151
-48
lines changed

packages/@aws-cdk/aws-elasticloadbalancingv2/test/integ.alb.dualstack.expected.json

+39-7
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
"VPCPublicSubnet1SubnetB4246D30": {
1919
"Type": "AWS::EC2::Subnet",
2020
"Properties": {
21-
"CidrBlock": "10.0.0.0/18",
2221
"VpcId": {
2322
"Ref": "VPCB9E5F0B4"
2423
},
2524
"AvailabilityZone": "test-region-1a",
25+
"CidrBlock": "10.0.0.0/18",
2626
"Ipv6CidrBlock": {
2727
"Fn::Select": [
2828
0,
@@ -152,11 +152,11 @@
152152
"VPCPublicSubnet2Subnet74179F39": {
153153
"Type": "AWS::EC2::Subnet",
154154
"Properties": {
155-
"CidrBlock": "10.0.64.0/18",
156155
"VpcId": {
157156
"Ref": "VPCB9E5F0B4"
158157
},
159158
"AvailabilityZone": "test-region-1b",
159+
"CidrBlock": "10.0.64.0/18",
160160
"Ipv6CidrBlock": {
161161
"Fn::Select": [
162162
1,
@@ -286,11 +286,11 @@
286286
"VPCPrivateSubnet1Subnet8BCA10E0": {
287287
"Type": "AWS::EC2::Subnet",
288288
"Properties": {
289-
"CidrBlock": "10.0.128.0/18",
290289
"VpcId": {
291290
"Ref": "VPCB9E5F0B4"
292291
},
293292
"AvailabilityZone": "test-region-1a",
293+
"CidrBlock": "10.0.128.0/18",
294294
"MapPublicIpOnLaunch": false,
295295
"Tags": [
296296
{
@@ -348,11 +348,11 @@
348348
"VPCPrivateSubnet2SubnetCFCDAA7A": {
349349
"Type": "AWS::EC2::Subnet",
350350
"Properties": {
351-
"CidrBlock": "10.0.192.0/18",
352351
"VpcId": {
353352
"Ref": "VPCB9E5F0B4"
354353
},
355354
"AvailabilityZone": "test-region-1b",
355+
"CidrBlock": "10.0.192.0/18",
356356
"MapPublicIpOnLaunch": false,
357357
"Tags": [
358358
{
@@ -537,14 +537,30 @@
537537
],
538538
"Targets": [
539539
{
540-
"Id": "10.0.128.4"
540+
"Id": "10.0.128.6"
541541
}
542542
],
543543
"TargetType": "ip",
544544
"VpcId": {
545545
"Ref": "VPCB9E5F0B4"
546546
}
547-
}
547+
},
548+
"DependsOn": [
549+
"VPCPublicSubnet1DefaultRoute91CEF279",
550+
"VPCPublicSubnet1EIP6AD938E8",
551+
"VPCPublicSubnet1IPv6DefaultFD18367E",
552+
"VPCPublicSubnet1NATGatewayE0556630",
553+
"VPCPublicSubnet1RouteTableFEE4B781",
554+
"VPCPublicSubnet1RouteTableAssociation0B0896DC",
555+
"VPCPublicSubnet1SubnetB4246D30",
556+
"VPCPublicSubnet2DefaultRouteB7481BBA",
557+
"VPCPublicSubnet2EIP4947BC00",
558+
"VPCPublicSubnet2IPv6DefaultDD0476C2",
559+
"VPCPublicSubnet2NATGateway3C070193",
560+
"VPCPublicSubnet2RouteTable6F1A15F1",
561+
"VPCPublicSubnet2RouteTableAssociation5A808732",
562+
"VPCPublicSubnet2Subnet74179F39"
563+
]
548564
},
549565
"LBListenerConditionalTargetGroupA75CCCD9": {
550566
"Type": "AWS::ElasticLoadBalancingV2::TargetGroup",
@@ -566,7 +582,23 @@
566582
"VpcId": {
567583
"Ref": "VPCB9E5F0B4"
568584
}
569-
}
585+
},
586+
"DependsOn": [
587+
"VPCPublicSubnet1DefaultRoute91CEF279",
588+
"VPCPublicSubnet1EIP6AD938E8",
589+
"VPCPublicSubnet1IPv6DefaultFD18367E",
590+
"VPCPublicSubnet1NATGatewayE0556630",
591+
"VPCPublicSubnet1RouteTableFEE4B781",
592+
"VPCPublicSubnet1RouteTableAssociation0B0896DC",
593+
"VPCPublicSubnet1SubnetB4246D30",
594+
"VPCPublicSubnet2DefaultRouteB7481BBA",
595+
"VPCPublicSubnet2EIP4947BC00",
596+
"VPCPublicSubnet2IPv6DefaultDD0476C2",
597+
"VPCPublicSubnet2NATGateway3C070193",
598+
"VPCPublicSubnet2RouteTable6F1A15F1",
599+
"VPCPublicSubnet2RouteTableAssociation5A808732",
600+
"VPCPublicSubnet2Subnet74179F39"
601+
]
570602
},
571603
"LBListenerConditionalTargetRule91FA260F": {
572604
"Type": "AWS::ElasticLoadBalancingV2::ListenerRule",

packages/@aws-cdk/aws-elasticloadbalancingv2/test/integ.alb.dualstack.ts

+25-21
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,29 @@ const internetGateway = valueOrDie<cdk.IConstruct, ec2.CfnInternetGateway>(
4242
new Error('Couldnt find an internet gateway'),
4343
);
4444

45+
46+
const lb = new elbv2.ApplicationLoadBalancer(stack, 'LB', {
47+
vpc,
48+
ipAddressType: elbv2.IpAddressType.DUAL_STACK,
49+
internetFacing: true,
50+
});
51+
52+
const listener = lb.addListener('Listener', {
53+
port: 80,
54+
});
55+
56+
const group1 = listener.addTargets('Target', {
57+
port: 80,
58+
targets: [new elbv2.IpTarget('10.0.128.6')],
59+
});
60+
61+
const group2 = listener.addTargets('ConditionalTarget', {
62+
priority: 10,
63+
hostHeader: 'example.com',
64+
port: 80,
65+
targets: [new elbv2.IpTarget('10.0.128.5')],
66+
});
67+
4568
vpc.publicSubnets.forEach((subnet, idx) => {
4669
// Add a default ipv6 route to the subnet's route table.
4770
const unboxedSubnet = subnet as ec2.Subnet;
@@ -71,28 +94,9 @@ vpc.publicSubnets.forEach((subnet, idx) => {
7194

7295
// The subnet depends on the ipv6 cidr being allocated.
7396
cfnSubnet.addDependsOn(ipv6Block);
74-
});
7597

76-
const lb = new elbv2.ApplicationLoadBalancer(stack, 'LB', {
77-
vpc,
78-
ipAddressType: elbv2.IpAddressType.DUAL_STACK,
79-
internetFacing: true,
80-
});
81-
82-
const listener = lb.addListener('Listener', {
83-
port: 80,
84-
});
85-
86-
const group1 = listener.addTargets('Target', {
87-
port: 80,
88-
targets: [new elbv2.IpTarget('10.0.128.4')],
89-
});
90-
91-
const group2 = listener.addTargets('ConditionalTarget', {
92-
priority: 10,
93-
hostHeader: 'example.com',
94-
port: 80,
95-
targets: [new elbv2.IpTarget('10.0.128.5')],
98+
group1.node.addDependency(subnet);
99+
group2.node.addDependency(subnet);
96100
});
97101

98102
listener.addAction('action1', {

packages/@aws-cdk/aws-elasticloadbalancingv2/test/integ.alb.expected.json

+41-13
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
"VPCPublicSubnet1SubnetB4246D30": {
1919
"Type": "AWS::EC2::Subnet",
2020
"Properties": {
21-
"CidrBlock": "10.0.0.0/18",
2221
"VpcId": {
2322
"Ref": "VPCB9E5F0B4"
2423
},
2524
"AvailabilityZone": "test-region-1a",
25+
"CidrBlock": "10.0.0.0/18",
2626
"MapPublicIpOnLaunch": true,
2727
"Tags": [
2828
{
@@ -95,15 +95,15 @@
9595
"VPCPublicSubnet1NATGatewayE0556630": {
9696
"Type": "AWS::EC2::NatGateway",
9797
"Properties": {
98+
"SubnetId": {
99+
"Ref": "VPCPublicSubnet1SubnetB4246D30"
100+
},
98101
"AllocationId": {
99102
"Fn::GetAtt": [
100103
"VPCPublicSubnet1EIP6AD938E8",
101104
"AllocationId"
102105
]
103106
},
104-
"SubnetId": {
105-
"Ref": "VPCPublicSubnet1SubnetB4246D30"
106-
},
107107
"Tags": [
108108
{
109109
"Key": "Name",
@@ -115,11 +115,11 @@
115115
"VPCPublicSubnet2Subnet74179F39": {
116116
"Type": "AWS::EC2::Subnet",
117117
"Properties": {
118-
"CidrBlock": "10.0.64.0/18",
119118
"VpcId": {
120119
"Ref": "VPCB9E5F0B4"
121120
},
122121
"AvailabilityZone": "test-region-1b",
122+
"CidrBlock": "10.0.64.0/18",
123123
"MapPublicIpOnLaunch": true,
124124
"Tags": [
125125
{
@@ -192,15 +192,15 @@
192192
"VPCPublicSubnet2NATGateway3C070193": {
193193
"Type": "AWS::EC2::NatGateway",
194194
"Properties": {
195+
"SubnetId": {
196+
"Ref": "VPCPublicSubnet2Subnet74179F39"
197+
},
195198
"AllocationId": {
196199
"Fn::GetAtt": [
197200
"VPCPublicSubnet2EIP4947BC00",
198201
"AllocationId"
199202
]
200203
},
201-
"SubnetId": {
202-
"Ref": "VPCPublicSubnet2Subnet74179F39"
203-
},
204204
"Tags": [
205205
{
206206
"Key": "Name",
@@ -212,11 +212,11 @@
212212
"VPCPrivateSubnet1Subnet8BCA10E0": {
213213
"Type": "AWS::EC2::Subnet",
214214
"Properties": {
215-
"CidrBlock": "10.0.128.0/18",
216215
"VpcId": {
217216
"Ref": "VPCB9E5F0B4"
218217
},
219218
"AvailabilityZone": "test-region-1a",
219+
"CidrBlock": "10.0.128.0/18",
220220
"MapPublicIpOnLaunch": false,
221221
"Tags": [
222222
{
@@ -274,11 +274,11 @@
274274
"VPCPrivateSubnet2SubnetCFCDAA7A": {
275275
"Type": "AWS::EC2::Subnet",
276276
"Properties": {
277-
"CidrBlock": "10.0.192.0/18",
278277
"VpcId": {
279278
"Ref": "VPCB9E5F0B4"
280279
},
281280
"AvailabilityZone": "test-region-1b",
281+
"CidrBlock": "10.0.192.0/18",
282282
"MapPublicIpOnLaunch": false,
283283
"Tags": [
284284
{
@@ -454,14 +454,28 @@
454454
],
455455
"Targets": [
456456
{
457-
"Id": "10.0.128.4"
457+
"Id": "10.0.128.6"
458458
}
459459
],
460460
"TargetType": "ip",
461461
"VpcId": {
462462
"Ref": "VPCB9E5F0B4"
463463
}
464-
}
464+
},
465+
"DependsOn": [
466+
"VPCPublicSubnet1DefaultRoute91CEF279",
467+
"VPCPublicSubnet1EIP6AD938E8",
468+
"VPCPublicSubnet1NATGatewayE0556630",
469+
"VPCPublicSubnet1RouteTableFEE4B781",
470+
"VPCPublicSubnet1RouteTableAssociation0B0896DC",
471+
"VPCPublicSubnet1SubnetB4246D30",
472+
"VPCPublicSubnet2DefaultRouteB7481BBA",
473+
"VPCPublicSubnet2EIP4947BC00",
474+
"VPCPublicSubnet2NATGateway3C070193",
475+
"VPCPublicSubnet2RouteTable6F1A15F1",
476+
"VPCPublicSubnet2RouteTableAssociation5A808732",
477+
"VPCPublicSubnet2Subnet74179F39"
478+
]
465479
},
466480
"LBListenerConditionalTargetGroupA75CCCD9": {
467481
"Type": "AWS::ElasticLoadBalancingV2::TargetGroup",
@@ -499,7 +513,21 @@
499513
"VpcId": {
500514
"Ref": "VPCB9E5F0B4"
501515
}
502-
}
516+
},
517+
"DependsOn": [
518+
"VPCPublicSubnet1DefaultRoute91CEF279",
519+
"VPCPublicSubnet1EIP6AD938E8",
520+
"VPCPublicSubnet1NATGatewayE0556630",
521+
"VPCPublicSubnet1RouteTableFEE4B781",
522+
"VPCPublicSubnet1RouteTableAssociation0B0896DC",
523+
"VPCPublicSubnet1SubnetB4246D30",
524+
"VPCPublicSubnet2DefaultRouteB7481BBA",
525+
"VPCPublicSubnet2EIP4947BC00",
526+
"VPCPublicSubnet2NATGateway3C070193",
527+
"VPCPublicSubnet2RouteTable6F1A15F1",
528+
"VPCPublicSubnet2RouteTableAssociation5A808732",
529+
"VPCPublicSubnet2Subnet74179F39"
530+
]
503531
},
504532
"LBListenerConditionalTargetRule91FA260F": {
505533
"Type": "AWS::ElasticLoadBalancingV2::ListenerRule",

packages/@aws-cdk/aws-elasticloadbalancingv2/test/integ.alb.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const listener = lb.addListener('Listener', {
2121

2222
const group1 = listener.addTargets('Target', {
2323
port: 80,
24-
targets: [new elbv2.IpTarget('10.0.128.4')],
24+
targets: [new elbv2.IpTarget('10.0.128.6')],
2525
stickinessCookieDuration: cdk.Duration.minutes(5),
2626
});
2727

@@ -35,6 +35,7 @@ const group2 = listener.addTargets('ConditionalTarget', {
3535
slowStart: cdk.Duration.minutes(1),
3636
});
3737

38+
3839
group1.metricTargetResponseTime().createAlarm(stack, 'ResponseTimeHigh1', {
3940
threshold: 5,
4041
evaluationPeriods: 2,
@@ -45,4 +46,9 @@ group2.metricTargetResponseTime().createAlarm(stack, 'ResponseTimeHigh2', {
4546
evaluationPeriods: 2,
4647
});
4748

49+
vpc.publicSubnets.forEach(subnet => {
50+
group2.node.addDependency(subnet);
51+
group1.node.addDependency(subnet);
52+
});
53+
4854
app.synth();

0 commit comments

Comments
 (0)