Skip to content

Commit

Permalink
skip: Merge pull request #103 from epam/feature/ecc-aws-597-reserved_…
Browse files Browse the repository at this point in the history
…redshift_node_recent_purchases

new: added policy ecc-aws-597-reserved_redshift_node_recent_purchases
  • Loading branch information
anna-shcherbak authored Jan 12, 2024
2 parents ca6d52a + ce87620 commit 50a6dd3
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 0 deletions.
22 changes: 22 additions & 0 deletions policies/ecc-aws-597-reserved_redshift_node_recent_purchases.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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-597-reserved_redshift_node_recent_purchases
comment: '010008062000'
description: |
Amazon Redshift reserved instance recent purchases
resource: aws.redshift-reserved
filters:
- type: value
key: State
value: active
- type: value
key: StartTime
value_type: age
op: lte
value: 7
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ec2:DescribeReservedNodes"
],
"Resource": "*"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"status_code": 200,
"data": {
"ReservedNodes": [
{
"ReservedNodeId": "1ba8e2e3-bc01-4d65-b35d-a4a3e931547e",
"ReservedNodeOfferingId": "ceb6a579-cf4c-4343-be8b-d832c45ab51c",
"NodeType": "dc2.xlarge",
"StartTime": "2020-06-07T11:08:39.051Z",
"Duration": 31536000,
"FixedPrice": 1380.0,
"UsagePrice": 0.0,
"CurrencyCode": "USD",
"NodeCount": 1,
"State": "active",
"OfferingType": "All Upfront",
"RecurringCharges": [
{
"RecurringChargeAmount": 0.0,
"RecurringChargeFrequency": "Hourly"
}
],
"ReservedNodeOfferingType": "Regular"
}
],
"ResponseMetadata": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"status_code": 200,
"data": {
"ReservedNodes": [
{
"ReservedNodeId": "1ba8e2e3-bc01-4d65-b35d-a4a3e931547e",
"ReservedNodeOfferingId": "ceb6a579-cf4c-4343-be8b-d832c45ab51c",
"NodeType": "dc2.xlarge",
"StartTime": "2024-01-12T11:08:39.051Z",
"Duration": 31536000,
"FixedPrice": 1380.0,
"UsagePrice": 0.0,
"CurrencyCode": "USD",
"NodeCount": 1,
"State": "active",
"OfferingType": "All Upfront",
"RecurringCharges": [
{
"RecurringChargeAmount": 0.0,
"RecurringChargeFrequency": "Hourly"
}
],
"ReservedNodeOfferingType": "Regular"
}
],
"ResponseMetadata": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import datetime
from dateutil import tz as tzutil

class PolicyTest(object):

def mock_time(self):
return 2024, 1, 12

def test_resources(self, base_test, resources):
base_test.assertEqual(len(resources), 1)
base_test.assertEqual(resources[0]['State'], "active")

start_time_str = resources[0]["StartTime"]
start_time = datetime.datetime.strptime(start_time_str, "%Y-%m-%dT%H:%M:%S.%fZ").replace(tzinfo=datetime.timezone.utc)

time_now = datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc)
delta = start_time - time_now
base_test.assertTrue(delta.days <= 7)

0 comments on commit 50a6dd3

Please sign in to comment.