From 3bb3cd14a06a539e84a647d1fb110568f6f795a6 Mon Sep 17 00:00:00 2001 From: skyuecx0630 <48788794+skyuecx0630@users.noreply.github.com> Date: Thu, 8 Aug 2024 20:19:41 +0900 Subject: [PATCH] Check ELB healthcheck only for ASGs attached to load balancers --- services/asg.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/asg.py b/services/asg.py index 7177c14..efe8f85 100644 --- a/services/asg.py +++ b/services/asg.py @@ -11,10 +11,10 @@ def autoscaling_group_elb_healthcheck_required(): asgs = client.describe_auto_scaling_groups()["AutoScalingGroups"] for asg in asgs: - if asg.get("HealthCheckType", {}) == "ELB": - compliant_resources.append(asg["AutoScalingGroupARN"]) - else: + if asg["LoadBalancerNames"] or asg["TargetGroupARNs"] and asg["HealthCheckType"] != "ELB": non_compliant_resources.append(asg["AutoScalingGroupARN"]) + else: + compliant_resources.append(asg["AutoScalingGroupARN"]) return RuleCheckResult( passed=not non_compliant_resources, @@ -29,7 +29,7 @@ def autoscaling_multiple_az(): asgs = client.describe_auto_scaling_groups()["AutoScalingGroups"] for asg in asgs: - if len(asg.get("AvailabilityZones", 0)) > 1: + if len(asg["AvailabilityZones"]) > 1: compliant_resources.append(asg["AutoScalingGroupARN"]) else: non_compliant_resources.append(asg["AutoScalingGroupARN"])