Skip to content

Commit

Permalink
Added the policy name to cost-savings
Browse files Browse the repository at this point in the history
  • Loading branch information
athiruma committed Nov 20, 2024
1 parent 02fb275 commit 7a88b57
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion cloud_governance/policy/helpers/aws/aws_policy_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class AWSPolicyOperations(AbstractPolicyOperations):
def __init__(self):
super().__init__()
self._region = self._environment_variables_dict.get('AWS_DEFAULT_REGION', 'us-east-2')
self.policy_name = self._environment_variables_dict.get('policy')
self._cloud_name = 'AWS'
self._ec2_client = get_boto3_client(client='ec2', region_name=self._region)
self._s3_client = get_boto3_client('s3', region_name=self._region)
Expand All @@ -27,7 +28,7 @@ def __init__(self):
self._ec2_operations = EC2Operations(region=self._region)
self._cloudwatch = CloudWatchOperations(region=self._region)
self._resource_pricing = ResourcesPricing()
self.cost_savings_tag = [{'Key': 'cost-savings', 'Value': 'true'}]
self.cost_savings_tag = [{'Key': 'cost-savings', 'Value': self.policy_name}]

def get_tag_name_from_tags(self, tags: list, tag_name: str) -> str:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_database_idle():
assert get_tag_value_from_tags(tags=rds_client.describe_db_instances()['DBInstances'][0]['TagList'],
tag_name='DaysCount') == f"{current_date.date()}@1"
assert get_tag_value_from_tags(tags=rds_client.describe_db_instances()['DBInstances'][0]['TagList'],
tag_name='cost-savings') == "true"
tag_name='cost-savings') == "database_idle"


@mock_cloudwatch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_unattached_volume_dry_run_yes():
assert response.get('ResourceAction') == 'False'
assert response.get('SkipPolicy') == 'NA'
assert get_tag_value_from_tags(tags=volume_run._get_all_volumes()[0]['Tags'],
tag_name='cost-savings') == 'true'
tag_name='cost-savings') == 'unattached_volume'


@mock_ec2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_unused_nat_gateway_dry_run_yes():
assert len(response) == 1
assert response[0]['CleanUpDays'] == 0
assert get_tag_value_from_tags(tags=unused_nat_gateway._ec2_operations.get_nat_gateways()[0]['Tags'],
tag_name='cost-savings') == 'true'
tag_name='cost-savings') == 'unused_nat_gateway'


@mock_cloudwatch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_zombie_snapshots():
'Tags'],
tag_name='DaysCount')
assert get_tag_value_from_tags(tags=zombie_snapshots._ec2_operations.get_snapshots()[0]['Tags'],
tag_name='cost-savings') == 'true'
tag_name='cost-savings') == 'zombie_snapshots'


@mock_ec2
Expand Down

0 comments on commit 7a88b57

Please sign in to comment.