Skip to content

Commit 037b960

Browse files
committed
Ignore tag values in shared-tag-values
1 parent 08f2da1 commit 037b960

File tree

5 files changed

+23
-1
lines changed

5 files changed

+23
-1
lines changed

aws_project_costs/project-cost-schema.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
"minLength": 1
1313
}
1414
},
15+
"shared-tag-values": {
16+
"description": "Project tag values that should be ignored and considered as shared costs",
17+
"type": "array",
18+
"items": {
19+
"type": "string",
20+
"minLength": 1
21+
}
22+
},
1523
"project-groups": {
1624
"description": "Groups of projects which use common infrastructure, a mapping of group-name to list of projects in the group",
1725
"type": "object",

aws_project_costs/project_costs.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def _shared_account(
4141
start,
4242
description,
4343
proj_tag_names_map,
44+
shared_tag_values,
4445
project_tagname,
4546
projects_in_group,
4647
costs_dict,
@@ -53,7 +54,9 @@ def _shared_account(
5354
raise NotImplementedError(f"Project tag {costs_tag} not yet implemented")
5455

5556
project_tag = costs_tag[5:]
56-
if project_tagname and project_tag:
57+
if project_tagname and project_tag and (project_tag not in shared_tag_values):
58+
if project_tag not in proj_tag_names_map:
59+
raise ValueError(f"{project_tag} is not in proj-tag-names")
5760
project_name = proj_tag_names_map[project_tag]
5861
rows.append(
5962
(
@@ -65,6 +68,7 @@ def _shared_account(
6568
)
6669
)
6770
else:
71+
# Either untagged, or a tag that should be considered shared
6872
cost_per_project = item["COST"] / len(projects_in_group)
6973
for project_name in projects_in_group:
7074
rows.append(
@@ -111,6 +115,7 @@ def allocate_costs(*, accountname, config, start, df):
111115
start,
112116
description,
113117
config["proj-tag-names"],
118+
config["shared-tag-values"],
114119
project_tagname,
115120
projects_in_group,
116121
costs_dict,

example/2024-01-01_2024-02-01.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ START,END,accountname,Proj$,COST
1515
2024-01-01,2024-02-01,aws-training,Proj$project-004,66.66
1616
2024-01-01,2024-02-01,aws-production-1,Proj$project-001,888.22
1717
2024-01-01,2024-02-01,aws-production-1,Proj$project-002,55.668
18+
2024-01-01,2024-02-01,aws-production-1,Proj$shared,5
1819
2024-01-01,2024-02-01,aws-production-2,Proj$,25.5
1920
2024-01-01,2024-02-01,aws-production-2,Proj$project-003,0.111
2021
2024-01-01,2024-02-01,aws-production-2,Proj$project-004,545.3009

example/output.csv

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@ start,projectname,account,tag,cost
1717
2024-01-01,SPECIAL-OPS,aws-special-ops-dev [project-specific],Proj$project-001,0.02
1818
2024-01-01,Internal - training,aws-training [project-specific],Proj$project-001,45.2
1919
2024-01-01,Internal - training,aws-training [project-specific],Proj$project-004,66.66
20+
2024-01-01,Internal - development,aws-production-1 [shared],Proj$shared,1.0
21+
2024-01-01,Internal - training,aws-production-1 [shared],Proj$shared,1.0
2022
2024-01-01,Project A,aws-production-1 [shared],Proj$project-001,888.22
23+
2024-01-01,Project A,aws-production-1 [shared],Proj$shared,1.0
2124
2024-01-01,Project B,aws-production-1 [shared],Proj$project-002,55.668
25+
2024-01-01,Project B,aws-production-1 [shared],Proj$shared,1.0
26+
2024-01-01,SPECIAL-OPS,aws-production-1 [shared],Proj$shared,1.0
2227
2024-01-01,Internal - development,aws-production-2 [shared],Proj$,5.1
2328
2024-01-01,Internal - training,aws-production-2 [shared],Proj$,5.1
2429
2024-01-01,Project A,aws-production-2 [shared],Proj$,5.1

example/projects.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ proj-tag-names:
44
"project-003": "Project B"
55
"project-004": "SPECIAL-OPS"
66

7+
shared-tag-values:
8+
- "shared"
9+
710
project-groups:
811
tre:
912
- "Project A"

0 commit comments

Comments
 (0)