Check ELB healthcheck only for ASGs attached to load balancers

This commit is contained in:
skyuecx0630 2024-08-08 20:19:41 +09:00
parent 885115d91d
commit 3bb3cd14a0

View File

@ -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"])