Skip to content

Commit e882b7f

Browse files
authored
Adding AWS Budgets tag collection and updated IAM permissions (#163)
1 parent cc2c935 commit e882b7f

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

data-collection/deploy/deploy-in-linked-account.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ Resources:
164164
Action:
165165
- "budgets:ViewBudget"
166166
- "budgets:DescribeBudgets"
167+
- "budgets:ListTagsForResource"
167168
Resource: "arn:aws:budgets::*:budget/*"
168169
Roles:
169170
- Ref: LambdaRole

data-collection/deploy/module-budgets.yaml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,16 @@ Resources:
103103
Code:
104104
ZipFile: |
105105
#Author Stephanie Gooch 2021
106+
#Mohideen - Added Budgets tag collection module
106107
import os
107108
import json
108109
import logging
109110
import datetime
110111
from json import JSONEncoder
112+
import sys
113+
from pip._internal import main
114+
main(['install', '-I', '-q', 'boto3', '--target', '/tmp/', '--no-cache-dir', '--disable-pip-version-check'])
115+
sys.path.insert(0,'/tmp/')
111116
112117
import boto3
113118
@@ -164,7 +169,17 @@ Resources:
164169
count += 1
165170
budget['collection_time'] = collection_time
166171
logger.debug(budget)
167-
budget.update({'Account_ID': account_id, 'Account_Name': account_name})
172+
# Fetch tags for the budget using List tag for resource API
173+
budget_name = budget['BudgetName']
174+
resource_arn = f"arn:aws:budgets::{account_id}:budget/{budget_name}"
175+
budget_tag = budgets_client.list_tags_for_resource(
176+
ResourceARN=f"{resource_arn}"
177+
)
178+
if budget_tag['ResourceTags'] is not None:
179+
budget.update({'Account_ID': account_id, 'Account_Name': account_name, 'Tags': budget_tag['ResourceTags']})
180+
else:
181+
budget.update({'Account_ID': account_id, 'Account_Name': account_name})
182+
# Fetch CostFilters if available
168183
if 'CostFilters' not in budget or len(budget['CostFilters']) == 0 or 'PlannedBudgetLimits' not in budget:
169184
budget.update({'CostFilters': {'Filter': ['None']}})
170185
dataJSONData = json.dumps(budget, cls=DateTimeEncoder)

0 commit comments

Comments
 (0)