Skip to content

Commit bd35344

Browse files
authored
add check for target groups per alb (#18)
* add check for target groups per alb and format
1 parent 2599886 commit bd35344

File tree

2 files changed

+71
-16
lines changed

2 files changed

+71
-16
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
### Added
11+
12+
- new check: elb_target_groups_per_alb
13+
1014
### Fixed
1115

1216
- fix wrong number of EBS snapshots

aws_quota/check/elb.py

Lines changed: 67 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,21 @@
55

66

77
def get_albs(session: boto3.Session):
8-
return list(filter(lambda lb: lb['Type'] == 'application', session.client('elbv2').describe_load_balancers()['LoadBalancers']))
8+
return list(
9+
filter(
10+
lambda lb: lb['Type'] == 'application',
11+
session.client('elbv2').describe_load_balancers()['LoadBalancers'],
12+
)
13+
)
914

1015

1116
def get_nlbs(session: boto3.Session):
12-
return list(filter(lambda lb: lb['Type'] == 'network', session.client('elbv2').describe_load_balancers()['LoadBalancers']))
17+
return list(
18+
filter(
19+
lambda lb: lb['Type'] == 'network',
20+
session.client('elbv2').describe_load_balancers()['LoadBalancers'],
21+
)
22+
)
1323

1424

1525
class ClassicLoadBalancerCountCheck(QuotaCheck):
@@ -21,7 +31,9 @@ class ClassicLoadBalancerCountCheck(QuotaCheck):
2131

2232
@property
2333
def current(self):
24-
return len(self.boto_session.client('elb').describe_load_balancers()['LoadBalancerDescriptions'])
34+
return len(
35+
self.boto_session.client('elb').describe_load_balancers()['LoadBalancerDescriptions']
36+
)
2537

2638

2739
class ListenerPerClassicLoadBalancerCountCheck(InstanceQuotaCheck):
@@ -33,14 +45,19 @@ class ListenerPerClassicLoadBalancerCountCheck(InstanceQuotaCheck):
3345

3446
@staticmethod
3547
def get_all_identifiers(session: boto3.Session) -> typing.List[str]:
36-
return [lb['LoadBalancerName'] for lb in session.client('elb').describe_load_balancers()['LoadBalancerDescriptions']]
48+
return [
49+
lb['LoadBalancerName']
50+
for lb in session.client('elb').describe_load_balancers()['LoadBalancerDescriptions']
51+
]
3752

3853
@property
3954
def current(self):
4055
try:
41-
return len(self.boto_session.client('elb').describe_load_balancers(
42-
LoadBalancerNames=[self.instance_id]
43-
)['LoadBalancerDescriptions'][0]['ListenerDescriptions'])
56+
return len(
57+
self.boto_session.client('elb').describe_load_balancers(
58+
LoadBalancerNames=[self.instance_id]
59+
)['LoadBalancerDescriptions'][0]['ListenerDescriptions']
60+
)
4461
except self.boto_session.client('elb').exceptions.AccessPointNotFoundException as e:
4562
raise InstanceWithIdentifierNotFound(self) from e
4663

@@ -54,7 +71,14 @@ class NetworkLoadBalancerCountCheck(QuotaCheck):
5471

5572
@property
5673
def current(self):
57-
return len(list(filter(lambda lb: lb['Type'] == 'network', self.boto_session.client('elbv2').describe_load_balancers()['LoadBalancers'])))
74+
return len(
75+
list(
76+
filter(
77+
lambda lb: lb['Type'] == 'network',
78+
self.boto_session.client('elbv2').describe_load_balancers()['LoadBalancers'],
79+
)
80+
)
81+
)
5882

5983

6084
class ListenerPerNetworkLoadBalancerCountCheck(InstanceQuotaCheck):
@@ -66,14 +90,16 @@ class ListenerPerNetworkLoadBalancerCountCheck(InstanceQuotaCheck):
6690

6791
@staticmethod
6892
def get_all_identifiers(session: boto3.Session) -> typing.List[str]:
69-
return [alb['LoadBalancerArn']
70-
for alb in get_nlbs(session)]
93+
return [alb['LoadBalancerArn'] for alb in get_nlbs(session)]
7194

7295
@property
7396
def current(self):
7497
try:
75-
return len(self.boto_session.client('elbv2').describe_listeners(
76-
LoadBalancerArn=self.instance_id)['Listeners'])
98+
return len(
99+
self.boto_session.client('elbv2').describe_listeners(
100+
LoadBalancerArn=self.instance_id
101+
)['Listeners']
102+
)
77103
except self.boto_session.client('elbv2').exceptions.LoadBalancerNotFoundException as e:
78104
raise InstanceWithIdentifierNotFound(self) from e
79105

@@ -99,14 +125,16 @@ class ListenerPerApplicationLoadBalancerCountCheck(InstanceQuotaCheck):
99125

100126
@staticmethod
101127
def get_all_identifiers(session: boto3.Session) -> typing.List[str]:
102-
return [alb['LoadBalancerArn']
103-
for alb in get_albs(session)]
128+
return [alb['LoadBalancerArn'] for alb in get_albs(session)]
104129

105130
@property
106131
def current(self) -> int:
107132
try:
108-
return len(self.boto_session.client('elbv2').describe_listeners(
109-
LoadBalancerArn=self.instance_id)['Listeners'])
133+
return len(
134+
self.boto_session.client('elbv2').describe_listeners(
135+
LoadBalancerArn=self.instance_id
136+
)['Listeners']
137+
)
110138
except self.boto_session.client('elbv2').exceptions.LoadBalancerNotFoundException as e:
111139
raise InstanceWithIdentifierNotFound(self) from e
112140

@@ -121,3 +149,26 @@ class TargetGroupCountCheck(QuotaCheck):
121149
@property
122150
def current(self):
123151
return len(self.boto_session.client('elbv2').describe_target_groups()['TargetGroups'])
152+
153+
154+
class TargetGroupsPerApplicationLoadBalancerCountCheck(InstanceQuotaCheck):
155+
key = "elb_target_groups_per_alb"
156+
description = "Target groups per Application Load Balancer"
157+
service_code = 'elasticloadbalancing'
158+
quota_code = 'L-822D1B1B'
159+
instance_id = 'Load Balancer ARN'
160+
161+
@staticmethod
162+
def get_all_identifiers(session: boto3.Session) -> typing.List[str]:
163+
return [alb['LoadBalancerArn'] for alb in get_albs(session)]
164+
165+
@property
166+
def current(self) -> int:
167+
try:
168+
return len(
169+
self.boto_session.client('elbv2').describe_target_groups(
170+
LoadBalancerArn=self.instance_id
171+
)['TargetGroups']
172+
)
173+
except self.boto_session.client('elbv2').exceptions.LoadBalancerNotFoundException as e:
174+
raise InstanceWithIdentifierNotFound(self) from e

0 commit comments

Comments
 (0)