Skip to content
2 changes: 2 additions & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Comment line immediately above ownership line is reserved for related gus information. Please be careful while editing.
#ECCN:Open Source
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ awslimitchecker
Master:

.. image:: https://api.travis-ci.com/jantman/awslimitchecker.svg?branch=master
:target: http://travis-ci.com/jantman/awslimitchecker
:target: https://app.travis-ci.com/github/jantman/awslimitchecker
:alt: travis-ci for master branch

.. image:: https://codecov.io/github/jantman/awslimitchecker/coverage.svg?branch=master
Expand All @@ -46,7 +46,7 @@ Master:
Develop:

.. image:: https://api.travis-ci.com/jantman/awslimitchecker.svg?branch=develop
:target: http://travis-ci.com/jantman/awslimitchecker
:target: https://app.travis-ci.com/github/jantman/awslimitchecker
:alt: travis-ci for develop branch

.. image:: https://codecov.io/github/jantman/awslimitchecker/coverage.svg?branch=develop
Expand Down
35 changes: 34 additions & 1 deletion awslimitchecker/services/vpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def find_usage(self):
self._find_usage_gateways()
self._find_usage_nat_gateways(subnet_to_az)
self._find_usages_vpn_gateways()
self._find_usages_customer_gateways()
self._find_usage_network_interfaces()
self._have_usage = True
logger.debug("Done checking usage.")
Expand Down Expand Up @@ -235,6 +236,25 @@ def _find_usages_vpn_gateways(self):
aws_type='AWS::EC2::VPNGateway'
)

def _find_usages_customer_gateways(self):
"""find usage of customer gateways"""

# do not include deleting and deleted in the results
vpngws = self.conn.describe_customer_gateways(Filters=[
{
'Name': 'state',
'Values': [
'available',
'pending'
]
}
])['CustomerGateways']

self.limits['Customer gateways']._add_current_usage(
len(vpngws),
aws_type='AWS::EC2::CustomerGateway'
)

def _find_usage_network_interfaces(self):
"""find usage of network interfaces"""
enis = paginate_dict(
Expand Down Expand Up @@ -349,7 +369,20 @@ def get_limits(self):
5,
self.warning_threshold,
self.critical_threshold,
limit_type='AWS::EC2::VPNGateway'
limit_type='AWS::EC2::VPNGateway',
quotas_service_code='ec2',
quotas_name='Virtual private gateways per region'
)

limits['Customer gateways'] = AwsLimit(
'Customer gateways',
self,
50,
self.warning_threshold,
self.critical_threshold,
limit_type='AWS::EC2::CustomerGateway',
quotas_service_code='ec2',
quotas_name='Customer gateways per region'
)

limits['Network interfaces per Region'] = AwsLimit(
Expand Down
19 changes: 19 additions & 0 deletions awslimitchecker/tests/services/result_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,25 @@ class VPC(object):
]
}

test_find_usages_customer_gateways = {
'CustomerGateways': [
{
"BgpAsn": "11111",
'State': 'pending',
'Type': 'ipsec.1',
"IpAddress": "123.55.44.11",
'CustomerGatewayId': 'string',
'Tags': [
{
'Key': 'string',
'Value': 'string'
},
]
},
{'CustomerGatewayId': 'string1'}
]
}

test_find_usage_network_interfaces = {
'NetworkInterfaces': [
{
Expand Down
32 changes: 32 additions & 0 deletions awslimitchecker/tests/services/test_vpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def test_get_limits(self):
'Rules per network ACL',
'Route tables per VPC',
'Virtual private gateways',
'Customer gateways',
'Network interfaces per Region',
])
for name, limit in res.items():
Expand Down Expand Up @@ -113,6 +114,7 @@ def test_find_usage(self):
_find_usage_gateways=DEFAULT,
_find_usage_nat_gateways=DEFAULT,
_find_usages_vpn_gateways=DEFAULT,
_find_usages_customer_gateways=DEFAULT,
_find_usage_network_interfaces=DEFAULT,
) as mocks:
mocks['_find_usage_subnets'].return_value = sn
Expand All @@ -130,6 +132,7 @@ def test_find_usage(self):
'_find_usage_route_tables',
'_find_usage_gateways',
'_find_usages_vpn_gateways',
'_find_usages_customer_gateways',
'_find_usage_network_interfaces',
]:
assert mocks[x].mock_calls == [call()]
Expand Down Expand Up @@ -362,6 +365,34 @@ def test_find_usages_vpn_gateways(self):
]),
]

def test_find_usages_customer_gateways(self):
response = result_fixtures.VPC.test_find_usages_customer_gateways

mock_conn = Mock()
mock_conn.describe_customer_gateways.return_value = response

cls = _VpcService(21, 43, {}, None)
cls._current_account_id = '0123456789'
cls.conn = mock_conn

cls._find_usages_customer_gateways()

assert len(cls.limits['Customer gateways']
.get_current_usage()) == 1
assert cls.limits['Customer gateways'].get_current_usage()[
0].get_value() == 2
assert mock_conn.mock_calls == [
call.describe_customer_gateways(Filters=[
{
'Name': 'state',
'Values': [
'available',
'pending'
]
}
]),
]

def test_find_usage_network_interfaces(self):
response = result_fixtures.VPC.test_find_usage_network_interfaces

Expand Down Expand Up @@ -393,5 +424,6 @@ def test_required_iam_permissions(self):
'ec2:DescribeSubnets',
'ec2:DescribeVpcs',
'ec2:DescribeVpnGateways',
'ec2:DescribeCustomerGateways',
'ec2:DescribeNetworkInterfaces',
]