-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
skip: Merge pull request #103 from epam/feature/ecc-aws-597-reserved_…
…redshift_node_recent_purchases new: added policy ecc-aws-597-reserved_redshift_node_recent_purchases
- Loading branch information
Showing
5 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
policies/ecc-aws-597-reserved_redshift_node_recent_purchases.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
12 changes: 12 additions & 0 deletions
12
terraform/ecc-aws-597-reserved_redshift_node_recent_purchases/iam/597-policy.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": "*" | ||
} | ||
] | ||
} |
28 changes: 28 additions & 0 deletions
28
...served_redshift_node_recent_purchases/placebo-green/redshift.DescribeReservedNodes_1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": {} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...reserved_redshift_node_recent_purchases/placebo-red/redshift.DescribeReservedNodes_1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": {} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
tests/ecc-aws-597-reserved_redshift_node_recent_purchases/red_policy_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |