Skip to content

Commit a65dd19

Browse files
authored
fix(aws-elasticloadbalancingv2): fix load balancer deletion protection to properly update when set to false (#9986)
Fixes #9975 ## Notes - Changed load balancer deletion protection to also set the attribute to `false`, instead of omitting the attribute when `deletionProtection` is false. - Added unit test to verify the attribute is set with `false` in this case - Fixed other load balancer unit tests that were broken due to adding this attribute when `deletionProtection` is false - Updated `expected.json` files for integ tests to include this attribute when `deletionProtection` is false ### Main changes - packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts - packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/load-balancer.test.ts - packages/@aws-cdk/aws-elasticloadbalancingv2/test/nlb/load-balancer.test.ts ### Changes for `expected.json` files - Everything else ## Testing - Ran unit tests and ensured they succeeded - Deploy a load balancer with deletion protection on, set it to `false` in CDK code, then redeploy and ensure it gets turned off ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent b757d88 commit a65dd19

31 files changed

+240
-37
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,12 @@
579579
"LB8A12904C": {
580580
"Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
581581
"Properties": {
582+
"LoadBalancerAttributes": [
583+
{
584+
"Key": "deletion_protection.enabled",
585+
"Value": "false"
586+
}
587+
],
582588
"Scheme": "internet-facing",
583589
"SecurityGroups": [
584590
{

packages/@aws-cdk/aws-cloudfront-origins/test/integ.http-origin.expected.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@
2727
}
2828
}
2929
}
30-
}
30+
}

packages/@aws-cdk/aws-cloudfront-origins/test/integ.load-balancer-origin.expected.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,12 @@
358358
"LB8A12904C": {
359359
"Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
360360
"Properties": {
361+
"LoadBalancerAttributes": [
362+
{
363+
"Key": "deletion_protection.enabled",
364+
"Value": "false"
365+
}
366+
],
361367
"Scheme": "internet-facing",
362368
"SecurityGroups": [
363369
{
@@ -432,4 +438,4 @@
432438
}
433439
}
434440
}
435-
}
441+
}

packages/@aws-cdk/aws-cloudfront-origins/test/integ.origin-group.expected.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,6 @@
6868
"Type": "AWS::CloudFront::Distribution",
6969
"Properties": {
7070
"DistributionConfig": {
71-
"DefaultCacheBehavior": {
72-
"ForwardedValues": {
73-
"QueryString": false
74-
},
75-
"TargetOriginId": "cloudfrontorigingroupDistributionOriginGroup10B57F1D1",
76-
"ViewerProtocolPolicy": "allow-all"
77-
},
7871
"CacheBehaviors": [
7972
{
8073
"ForwardedValues": {
@@ -85,6 +78,13 @@
8578
"ViewerProtocolPolicy": "allow-all"
8679
}
8780
],
81+
"DefaultCacheBehavior": {
82+
"ForwardedValues": {
83+
"QueryString": false
84+
},
85+
"TargetOriginId": "cloudfrontorigingroupDistributionOriginGroup10B57F1D1",
86+
"ViewerProtocolPolicy": "allow-all"
87+
},
8888
"Enabled": true,
8989
"HttpVersion": "http2",
9090
"IPV6Enabled": true,
@@ -153,4 +153,4 @@
153153
}
154154
}
155155
}
156-
}
156+
}

packages/@aws-cdk/aws-cloudfront-origins/test/integ.s3-origin.expected.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,4 @@
106106
}
107107
}
108108
}
109-
}
109+
}

packages/@aws-cdk/aws-ecs-patterns/test/ec2/integ.multiple-application-load-balanced-ecs-service.expected.json

+12-6
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,6 @@
458458
"ecs:Poll",
459459
"ecs:StartTelemetrySession"
460460
],
461-
"Effect": "Allow",
462-
"Resource": "*",
463461
"Condition": {
464462
"ArnEquals": {
465463
"ecs:cluster": {
@@ -469,7 +467,9 @@
469467
]
470468
}
471469
}
472-
}
470+
},
471+
"Effect": "Allow",
472+
"Resource": "*"
473473
},
474474
{
475475
"Action": [
@@ -657,8 +657,6 @@
657657
"ecs:DescribeContainerInstances",
658658
"ecs:DescribeTasks"
659659
],
660-
"Effect": "Allow",
661-
"Resource": "*",
662660
"Condition": {
663661
"ArnEquals": {
664662
"ecs:cluster": {
@@ -668,7 +666,9 @@
668666
]
669667
}
670668
}
671-
}
669+
},
670+
"Effect": "Allow",
671+
"Resource": "*"
672672
},
673673
{
674674
"Action": [
@@ -862,6 +862,12 @@
862862
"myServiceLB168895E1": {
863863
"Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
864864
"Properties": {
865+
"LoadBalancerAttributes": [
866+
{
867+
"Key": "deletion_protection.enabled",
868+
"Value": "false"
869+
}
870+
],
865871
"Scheme": "internet-facing",
866872
"SecurityGroups": [
867873
{

packages/@aws-cdk/aws-ecs-patterns/test/ec2/integ.scheduled-ecs-task.lit.expected.json

+8-7
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,6 @@
278278
"ecs:Poll",
279279
"ecs:StartTelemetrySession"
280280
],
281-
"Effect": "Allow",
282-
"Resource": "*",
283281
"Condition": {
284282
"ArnEquals": {
285283
"ecs:cluster": {
@@ -289,7 +287,9 @@
289287
]
290288
}
291289
}
292-
}
290+
},
291+
"Effect": "Allow",
292+
"Resource": "*"
293293
},
294294
{
295295
"Action": [
@@ -300,7 +300,8 @@
300300
],
301301
"Effect": "Allow",
302302
"Resource": "*"
303-
} ],
303+
}
304+
],
304305
"Version": "2012-10-17"
305306
},
306307
"PolicyName": "EcsClusterDefaultAutoScalingGroupInstanceRoleDefaultPolicy04DC6C80",
@@ -473,8 +474,6 @@
473474
"ecs:DescribeContainerInstances",
474475
"ecs:DescribeTasks"
475476
],
476-
"Effect": "Allow",
477-
"Resource": "*",
478477
"Condition": {
479478
"ArnEquals": {
480479
"ecs:cluster": {
@@ -484,7 +483,9 @@
484483
]
485484
}
486485
}
487-
}
486+
},
487+
"Effect": "Allow",
488+
"Resource": "*"
488489
},
489490
{
490491
"Action": [

packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.asset-image.expected.json

+6
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,12 @@
361361
"FargateServiceLBB353E155": {
362362
"Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
363363
"Properties": {
364+
"LoadBalancerAttributes": [
365+
{
366+
"Key": "deletion_protection.enabled",
367+
"Value": "false"
368+
}
369+
],
364370
"Scheme": "internet-facing",
365371
"SecurityGroups": [
366372
{

packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.executionrole.expected.json

+6
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,12 @@
410410
"L3LB212FC0E0": {
411411
"Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
412412
"Properties": {
413+
"LoadBalancerAttributes": [
414+
{
415+
"Key": "deletion_protection.enabled",
416+
"Value": "false"
417+
}
418+
],
413419
"Scheme": "internet-facing",
414420
"SecurityGroups": [
415421
{

packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.l3-autocreate.expected.json

+12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
"L3LB212FC0E0": {
44
"Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
55
"Properties": {
6+
"LoadBalancerAttributes": [
7+
{
8+
"Key": "deletion_protection.enabled",
9+
"Value": "false"
10+
}
11+
],
612
"Scheme": "internet-facing",
713
"SecurityGroups": [
814
{
@@ -663,6 +669,12 @@
663669
"L3bLBB8FADA4E": {
664670
"Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
665671
"Properties": {
672+
"LoadBalancerAttributes": [
673+
{
674+
"Key": "deletion_protection.enabled",
675+
"Value": "false"
676+
}
677+
],
666678
"Scheme": "internet-facing",
667679
"SecurityGroups": [
668680
{

packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.l3-vpconly.expected.json

+18
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,12 @@
358358
"L3LB212FC0E0": {
359359
"Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
360360
"Properties": {
361+
"LoadBalancerAttributes": [
362+
{
363+
"Key": "deletion_protection.enabled",
364+
"Value": "false"
365+
}
366+
],
361367
"Scheme": "internet-facing",
362368
"SecurityGroups": [
363369
{
@@ -1018,6 +1024,12 @@
10181024
"L3bLBB8FADA4E": {
10191025
"Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
10201026
"Properties": {
1027+
"LoadBalancerAttributes": [
1028+
{
1029+
"Key": "deletion_protection.enabled",
1030+
"Value": "false"
1031+
}
1032+
],
10211033
"Scheme": "internet-facing",
10221034
"SecurityGroups": [
10231035
{
@@ -1323,6 +1335,12 @@
13231335
"L3cLB041B1E8C": {
13241336
"Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
13251337
"Properties": {
1338+
"LoadBalancerAttributes": [
1339+
{
1340+
"Key": "deletion_protection.enabled",
1341+
"Value": "false"
1342+
}
1343+
],
13261344
"Scheme": "internet-facing",
13271345
"SecurityGroups": [
13281346
{

packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.l3.expected.json

+6
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,12 @@
361361
"L3LB212FC0E0": {
362362
"Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
363363
"Properties": {
364+
"LoadBalancerAttributes": [
365+
{
366+
"Key": "deletion_protection.enabled",
367+
"Value": "false"
368+
}
369+
],
364370
"Scheme": "internet-facing",
365371
"SecurityGroups": [
366372
{

packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.load-balanced-fargate-service.expected.json

+6
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,12 @@
361361
"myServiceLB168895E1": {
362362
"Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
363363
"Properties": {
364+
"LoadBalancerAttributes": [
365+
{
366+
"Key": "deletion_protection.enabled",
367+
"Value": "false"
368+
}
369+
],
364370
"Scheme": "internet-facing",
365371
"SecurityGroups": [
366372
{

packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.multiple-network-load-balanced-fargate-service.expected.json

+12
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,12 @@
361361
"myServicelb1FA8CBE12": {
362362
"Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
363363
"Properties": {
364+
"LoadBalancerAttributes": [
365+
{
366+
"Key": "deletion_protection.enabled",
367+
"Value": "false"
368+
}
369+
],
364370
"Scheme": "internet-facing",
365371
"Subnets": [
366372
{
@@ -409,6 +415,12 @@
409415
"myServicelb2C84C7BCB": {
410416
"Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
411417
"Properties": {
418+
"LoadBalancerAttributes": [
419+
{
420+
"Key": "deletion_protection.enabled",
421+
"Value": "false"
422+
}
423+
],
412424
"Scheme": "internet-facing",
413425
"Subnets": [
414426
{

packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.special-listener.expected.json

+12
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,12 @@
361361
"FargateNlbServiceLBC7004B25": {
362362
"Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
363363
"Properties": {
364+
"LoadBalancerAttributes": [
365+
{
366+
"Key": "deletion_protection.enabled",
367+
"Value": "false"
368+
}
369+
],
364370
"Scheme": "internet-facing",
365371
"Subnets": [
366372
{
@@ -595,6 +601,12 @@
595601
"FargateAlbServiceLBA7128551": {
596602
"Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
597603
"Properties": {
604+
"LoadBalancerAttributes": [
605+
{
606+
"Key": "deletion_protection.enabled",
607+
"Value": "false"
608+
}
609+
],
598610
"Scheme": "internet-facing",
599611
"SecurityGroups": [
600612
{

packages/@aws-cdk/aws-ecs/test/ec2/integ.lb-awsvpc-nw.expected.json

+6
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,12 @@
979979
"LB8A12904C": {
980980
"Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
981981
"Properties": {
982+
"LoadBalancerAttributes": [
983+
{
984+
"Key": "deletion_protection.enabled",
985+
"Value": "false"
986+
}
987+
],
982988
"Scheme": "internet-facing",
983989
"SecurityGroups": [
984990
{

packages/@aws-cdk/aws-ecs/test/ec2/integ.lb-bridge-nw.expected.json

+6
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,12 @@
943943
"LB8A12904C": {
944944
"Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
945945
"Properties": {
946+
"LoadBalancerAttributes": [
947+
{
948+
"Key": "deletion_protection.enabled",
949+
"Value": "false"
950+
}
951+
],
946952
"Scheme": "internet-facing",
947953
"SecurityGroups": [
948954
{

packages/@aws-cdk/aws-ecs/test/fargate/integ.lb-awsvpc-nw.expected.json

+6
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,12 @@
558558
"LB8A12904C": {
559559
"Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
560560
"Properties": {
561+
"LoadBalancerAttributes": [
562+
{
563+
"Key": "deletion_protection.enabled",
564+
"Value": "false"
565+
}
566+
],
561567
"Scheme": "internet-facing",
562568
"SecurityGroups": [
563569
{

0 commit comments

Comments
 (0)