@@ -530,7 +530,8 @@ def assert_lifecycle_hook_properties(self, template, resource_name: str):
530530 assert resource ["Type" ] == "AWS::AutoScaling::LifecycleHook"
531531 properties = resource ["Properties" ]
532532 assert properties ["LifecycleTransition" ] == self .expected_lifecycle_transition
533- assert properties ["HeartbeatTimeout" ] == self .expected_heartbeat_timeout
533+ if "HeartbeatTimeout" in properties :
534+ assert properties ["HeartbeatTimeout" ] == self .expected_heartbeat_timeout
534535
535536
536537class IamRoleAssertion :
@@ -570,6 +571,10 @@ def assert_iam_policy_properties(self, template, resource_name: str):
570571 expected_lifecycle_transition = "autoscaling:EC2_INSTANCE_TERMINATING" ,
571572 expected_heartbeat_timeout = 7200 ,
572573 ),
574+ LifecycleHookAssertion (
575+ expected_lifecycle_transition = "autoscaling:EC2_INSTANCE_LAUNCHING" ,
576+ expected_heartbeat_timeout = 600 ,
577+ ),
573578 IamRoleAssertion (expected_managed_policy_arn = "arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy" ),
574579 IamPolicyAssertion (
575580 expected_statements = [
@@ -596,6 +601,25 @@ def assert_iam_policy_properties(self, template, resource_name: str):
596601 },
597602 "Sid" : "S3GetObj" ,
598603 },
604+ {
605+ "Action" : "autoscaling:CompleteLifecycleAction" ,
606+ "Effect" : "Allow" ,
607+ "Resource" : {
608+ "Fn::Join" : [
609+ "" ,
610+ [
611+ "arn:" ,
612+ {"Ref" : "AWS::Partition" },
613+ ":autoscaling:" ,
614+ {"Ref" : "AWS::Region" },
615+ ":" ,
616+ {"Ref" : "AWS::AccountId" },
617+ ":autoScalingGroupName/clustername-testloginnodespool1-AutoScalingGroup" ,
618+ ],
619+ ]
620+ },
621+ "Sid" : "Autoscaling" ,
622+ },
599623 ]
600624 ),
601625 ],
@@ -615,21 +639,25 @@ def test_login_nodes_traffic_management_resources_values_properties(
615639 )
616640
617641 asset_content_asg = get_asset_content_with_resource_name (
618- cdk_assets , "Pooltestloginnodespool1Pooltestloginnodespool1AutoScalingGroup41053D91 "
642+ cdk_assets , "clusternametestloginnodespool1clusternametestloginnodespool1AutoScalingGroup5EBA3937 "
619643 )
620644 asset_content_nlb = get_asset_content_with_resource_name (
621- cdk_assets , "Pooltestloginnodespool1testloginnodespool1LoadBalancer18C3DA82 "
645+ cdk_assets , "clusternametestloginnodespool1testloginnodespool1LoadBalancerE1D4FCC7 "
622646 )
623647 asset_content_target_group = get_asset_content_with_resource_name (
624- cdk_assets , "Pooltestloginnodespool1testloginnodespool1TargetGroupD150DBF2 "
648+ cdk_assets , "clusternametestloginnodespool1testloginnodespool1TargetGroup713F5EC5 "
625649 )
626650 asset_content_nlb_listener = get_asset_content_with_resource_name (
627651 cdk_assets ,
628- "Pooltestloginnodespool1testloginnodespool1LoadBalancerLoginNodesListenertestloginnodespool1727E619B" ,
652+ "clusternametestloginnodespool1testloginnodespool1LoadBalancerLoginNodesListenertestloginnodespool165B4D3DC" ,
653+ )
654+ asset_content_lifecycle_hook_terminating = get_asset_content_with_resource_name (
655+ cdk_assets ,
656+ "clusternametestloginnodespool1LoginNodesASGLifecycleHookTerminating51CA6203" ,
629657 )
630- asset_content_lifecycle_hook = get_asset_content_with_resource_name (
658+ asset_content_lifecycle_hook_launching = get_asset_content_with_resource_name (
631659 cdk_assets ,
632- "Pooltestloginnodespool1LoginNodesASGLifecycleHookE54B2467 " ,
660+ "clusternametestloginnodespool1LoginNodesASGLifecycleHookLaunching879DBA56 " ,
633661 )
634662 asset_content_iam_role = get_asset_content_with_resource_name (
635663 cdk_assets ,
@@ -639,29 +667,37 @@ def test_login_nodes_traffic_management_resources_values_properties(
639667 cdk_assets ,
640668 "ParallelClusterPoliciesA50bdea9651dc48c" ,
641669 )
642- print (cdk_assets )
643670 for lt_assertion in lt_assertions :
644671 if isinstance (lt_assertion , AutoScalingGroupAssertion ):
645672 lt_assertion .assert_asg_properties (
646- asset_content_asg , "Pooltestloginnodespool1Pooltestloginnodespool1AutoScalingGroup41053D91"
673+ asset_content_asg ,
674+ "clusternametestloginnodespool1clusternametestloginnodespool1AutoScalingGroup5EBA3937" ,
647675 )
648676 elif isinstance (lt_assertion , NetworkLoadBalancerAssertion ):
649677 lt_assertion .assert_nlb_properties (
650- asset_content_nlb , "Pooltestloginnodespool1testloginnodespool1LoadBalancer18C3DA82 "
678+ asset_content_nlb , "clusternametestloginnodespool1testloginnodespool1LoadBalancerE1D4FCC7 "
651679 )
652680 elif isinstance (lt_assertion , TargetGroupAssertion ):
653681 lt_assertion .assert_tg_properties (
654- asset_content_target_group , "Pooltestloginnodespool1testloginnodespool1TargetGroupD150DBF2 "
682+ asset_content_target_group , "clusternametestloginnodespool1testloginnodespool1TargetGroup713F5EC5 "
655683 )
656684 elif isinstance (lt_assertion , NetworkLoadBalancerListenerAssertion ):
657685 lt_assertion .assert_nlb_listener_properties (
658686 asset_content_nlb_listener ,
659- "Pooltestloginnodespool1testloginnodespool1LoadBalancerLoginNodesListenertestloginnodespool1727E619B" ,
687+ "clusternametestloginnodespool1testloginnodespool1"
688+ "LoadBalancerLoginNodesListenertestloginnodespool165B4D3DC" ,
660689 )
661690 elif isinstance (lt_assertion , LifecycleHookAssertion ):
662- lt_assertion .assert_lifecycle_hook_properties (
663- asset_content_lifecycle_hook , "Pooltestloginnodespool1LoginNodesASGLifecycleHookE54B2467"
664- )
691+ if lt_assertion .expected_lifecycle_transition == "autoscaling:EC2_INSTANCE_TERMINATING" :
692+ lt_assertion .assert_lifecycle_hook_properties (
693+ asset_content_lifecycle_hook_terminating ,
694+ "clusternametestloginnodespool1LoginNodesASGLifecycleHookTerminating51CA6203" ,
695+ )
696+ else :
697+ lt_assertion .assert_lifecycle_hook_properties (
698+ asset_content_lifecycle_hook_launching ,
699+ "clusternametestloginnodespool1LoginNodesASGLifecycleHookLaunching879DBA56" ,
700+ )
665701 elif isinstance (lt_assertion , IamRoleAssertion ):
666702 lt_assertion .assert_iam_role_properties (asset_content_iam_role , "RoleA50bdea9651dc48c" )
667703 elif isinstance (lt_assertion , IamPolicyAssertion ):
0 commit comments