From cf8785b681d2f35b2c51922bc78348469fadf4cb Mon Sep 17 00:00:00 2001 From: Anna Shcherbak Date: Tue, 26 Sep 2023 14:00:34 +0300 Subject: [PATCH] new: added policy ecc-aws-578-reserved_ec2_instance_payment_pending --- ...-reserved_ec2_instance_payment_pending.yml | 17 ++++++ .../iam/578-policy.json | 12 ++++ .../ec2.DescribeReservedInstances_1.json | 59 +++++++++++++++++++ .../ec2.DescribeReservedInstances_1.json | 59 +++++++++++++++++++ .../red_policy_test.py | 5 ++ 5 files changed, 152 insertions(+) create mode 100644 policies/ecc-aws-578-reserved_ec2_instance_payment_pending.yml create mode 100644 terraform/ecc-aws-578-reserved_ec2_instance_payment_pending/iam/578-policy.json create mode 100644 tests/ecc-aws-578-reserved_ec2_instance_payment_pending/placebo-green/ec2.DescribeReservedInstances_1.json create mode 100644 tests/ecc-aws-578-reserved_ec2_instance_payment_pending/placebo-red/ec2.DescribeReservedInstances_1.json create mode 100644 tests/ecc-aws-578-reserved_ec2_instance_payment_pending/red_policy_test.py diff --git a/policies/ecc-aws-578-reserved_ec2_instance_payment_pending.yml b/policies/ecc-aws-578-reserved_ec2_instance_payment_pending.yml new file mode 100644 index 000000000..b17dd20ba --- /dev/null +++ b/policies/ecc-aws-578-reserved_ec2_instance_payment_pending.yml @@ -0,0 +1,17 @@ +# Copyright (c) 2023 EPAM Systems, Inc. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + +policies: + - name: ecc-aws-578-reserved_ec2_instance_payment_pending + comment: '010008032000' + description: | + Amazon EC2 reserved instance payment pending + resource: aws.ec2-reserved + filters: + - type: value + key: State + value: payment-pending diff --git a/terraform/ecc-aws-578-reserved_ec2_instance_payment_pending/iam/578-policy.json b/terraform/ecc-aws-578-reserved_ec2_instance_payment_pending/iam/578-policy.json new file mode 100644 index 000000000..441e4dc4e --- /dev/null +++ b/terraform/ecc-aws-578-reserved_ec2_instance_payment_pending/iam/578-policy.json @@ -0,0 +1,12 @@ +{ + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "ec2:DescribeReservedInstances" + ], + "Resource": "*" + } + ] +} \ No newline at end of file diff --git a/tests/ecc-aws-578-reserved_ec2_instance_payment_pending/placebo-green/ec2.DescribeReservedInstances_1.json b/tests/ecc-aws-578-reserved_ec2_instance_payment_pending/placebo-green/ec2.DescribeReservedInstances_1.json new file mode 100644 index 000000000..cd78bd314 --- /dev/null +++ b/tests/ecc-aws-578-reserved_ec2_instance_payment_pending/placebo-green/ec2.DescribeReservedInstances_1.json @@ -0,0 +1,59 @@ +{ + "status_code": 200, + "data": { + "ReservedInstances": [ + { + "Duration": 31536000, + "End": { + "__class__": "datetime", + "year": 2020, + "month": 2, + "day": 23, + "hour": 11, + "minute": 25, + "second": 2, + "microsecond": 0 + }, + "FixedPrice": 30.0, + "InstanceCount": 1, + "InstanceType": "t2.micro", + "ProductDescription": "Linux/UNIX", + "ReservedInstancesId": "32881ecb-6734-4b79-94a0-26c759c2da38", + "Start": { + "__class__": "datetime", + "year": 2019, + "month": 2, + "day": 23, + "hour": 11, + "minute": 25, + "second": 3, + "microsecond": 340000 + }, + "State": "active", + "UsagePrice": 0.0, + "CurrencyCode": "USD", + "InstanceTenancy": "default", + "OfferingClass": "standard", + "OfferingType": "Partial Upfront", + "RecurringCharges": [ + { + "Amount": 0.0034, + "Frequency": "Hourly" + } + ], + "Scope": "Region" + } + ], + "ResponseMetadata": { + "RequestId": "cfd41aad-88c0-4975-9725-f2385aaa5852", + "HTTPStatusCode": 200, + "HTTPHeaders": { + "content-type": "text/xml;charset=UTF-8", + "content-length": "1267", + "date": "Sat, 23 Feb 2019 11:45:27 GMT", + "server": "AmazonEC2" + }, + "RetryAttempts": 0 + } + } +} diff --git a/tests/ecc-aws-578-reserved_ec2_instance_payment_pending/placebo-red/ec2.DescribeReservedInstances_1.json b/tests/ecc-aws-578-reserved_ec2_instance_payment_pending/placebo-red/ec2.DescribeReservedInstances_1.json new file mode 100644 index 000000000..9dce9a7c6 --- /dev/null +++ b/tests/ecc-aws-578-reserved_ec2_instance_payment_pending/placebo-red/ec2.DescribeReservedInstances_1.json @@ -0,0 +1,59 @@ +{ + "status_code": 200, + "data": { + "ReservedInstances": [ + { + "Duration": 31536000, + "End": { + "__class__": "datetime", + "year": 2020, + "month": 2, + "day": 23, + "hour": 11, + "minute": 25, + "second": 2, + "microsecond": 0 + }, + "FixedPrice": 30.0, + "InstanceCount": 1, + "InstanceType": "t2.micro", + "ProductDescription": "Linux/UNIX", + "ReservedInstancesId": "32881ecb-6734-4b79-94a0-26c759c2da38", + "Start": { + "__class__": "datetime", + "year": 2019, + "month": 2, + "day": 23, + "hour": 11, + "minute": 25, + "second": 3, + "microsecond": 340000 + }, + "State": "payment-pending", + "UsagePrice": 0.0, + "CurrencyCode": "USD", + "InstanceTenancy": "default", + "OfferingClass": "standard", + "OfferingType": "Partial Upfront", + "RecurringCharges": [ + { + "Amount": 0.0034, + "Frequency": "Hourly" + } + ], + "Scope": "Region" + } + ], + "ResponseMetadata": { + "RequestId": "cfd41aad-88c0-4975-9725-f2385aaa5852", + "HTTPStatusCode": 200, + "HTTPHeaders": { + "content-type": "text/xml;charset=UTF-8", + "content-length": "1267", + "date": "Sat, 23 Feb 2019 11:45:27 GMT", + "server": "AmazonEC2" + }, + "RetryAttempts": 0 + } + } +} diff --git a/tests/ecc-aws-578-reserved_ec2_instance_payment_pending/red_policy_test.py b/tests/ecc-aws-578-reserved_ec2_instance_payment_pending/red_policy_test.py new file mode 100644 index 000000000..1b59c33ca --- /dev/null +++ b/tests/ecc-aws-578-reserved_ec2_instance_payment_pending/red_policy_test.py @@ -0,0 +1,5 @@ +class PolicyTest(object): + + def test_resources_with_client(self, base_test, resources, local_session): + base_test.assertEqual(len(resources), 1) + base_test.assertEqual(resources[0]['State'], "payment-pending") \ No newline at end of file