diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 00000000..522fa4a0 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1,2 @@ +# Comment line immediately above ownership line is reserved for related gus information. Please be careful while editing. +#ECCN:Open Source diff --git a/awslimitchecker/services/vpc.py b/awslimitchecker/services/vpc.py index 0080fe5b..1f7cdb25 100644 --- a/awslimitchecker/services/vpc.py +++ b/awslimitchecker/services/vpc.py @@ -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.") @@ -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( @@ -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( diff --git a/awslimitchecker/tests/services/result_fixtures.py b/awslimitchecker/tests/services/result_fixtures.py index 93c68929..032ff200 100644 --- a/awslimitchecker/tests/services/result_fixtures.py +++ b/awslimitchecker/tests/services/result_fixtures.py @@ -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': [ { diff --git a/awslimitchecker/tests/services/test_vpc.py b/awslimitchecker/tests/services/test_vpc.py index 60003ace..7e5967ee 100644 --- a/awslimitchecker/tests/services/test_vpc.py +++ b/awslimitchecker/tests/services/test_vpc.py @@ -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(): @@ -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 @@ -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()] @@ -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 @@ -393,5 +424,6 @@ def test_required_iam_permissions(self): 'ec2:DescribeSubnets', 'ec2:DescribeVpcs', 'ec2:DescribeVpnGateways', + 'ec2:DescribeCustomerGateways', 'ec2:DescribeNetworkInterfaces', ]