Skip to content

Commit

Permalink
Ignore tag values in shared-tag-values
Browse files Browse the repository at this point in the history
  • Loading branch information
manics committed May 22, 2024
1 parent 08f2da1 commit 037b960
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
8 changes: 8 additions & 0 deletions aws_project_costs/project-cost-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
"minLength": 1
}
},
"shared-tag-values": {
"description": "Project tag values that should be ignored and considered as shared costs",
"type": "array",
"items": {
"type": "string",
"minLength": 1
}
},
"project-groups": {
"description": "Groups of projects which use common infrastructure, a mapping of group-name to list of projects in the group",
"type": "object",
Expand Down
7 changes: 6 additions & 1 deletion aws_project_costs/project_costs.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def _shared_account(
start,
description,
proj_tag_names_map,
shared_tag_values,
project_tagname,
projects_in_group,
costs_dict,
Expand All @@ -53,7 +54,9 @@ def _shared_account(
raise NotImplementedError(f"Project tag {costs_tag} not yet implemented")

project_tag = costs_tag[5:]
if project_tagname and project_tag:
if project_tagname and project_tag and (project_tag not in shared_tag_values):
if project_tag not in proj_tag_names_map:
raise ValueError(f"{project_tag} is not in proj-tag-names")
project_name = proj_tag_names_map[project_tag]
rows.append(
(
Expand All @@ -65,6 +68,7 @@ def _shared_account(
)
)
else:
# Either untagged, or a tag that should be considered shared
cost_per_project = item["COST"] / len(projects_in_group)
for project_name in projects_in_group:
rows.append(
Expand Down Expand Up @@ -111,6 +115,7 @@ def allocate_costs(*, accountname, config, start, df):
start,
description,
config["proj-tag-names"],
config["shared-tag-values"],
project_tagname,
projects_in_group,
costs_dict,
Expand Down
1 change: 1 addition & 0 deletions example/2024-01-01_2024-02-01.csv
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ START,END,accountname,Proj$,COST
2024-01-01,2024-02-01,aws-training,Proj$project-004,66.66
2024-01-01,2024-02-01,aws-production-1,Proj$project-001,888.22
2024-01-01,2024-02-01,aws-production-1,Proj$project-002,55.668
2024-01-01,2024-02-01,aws-production-1,Proj$shared,5
2024-01-01,2024-02-01,aws-production-2,Proj$,25.5
2024-01-01,2024-02-01,aws-production-2,Proj$project-003,0.111
2024-01-01,2024-02-01,aws-production-2,Proj$project-004,545.3009
Expand Down
5 changes: 5 additions & 0 deletions example/output.csv
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ start,projectname,account,tag,cost
2024-01-01,SPECIAL-OPS,aws-special-ops-dev [project-specific],Proj$project-001,0.02
2024-01-01,Internal - training,aws-training [project-specific],Proj$project-001,45.2
2024-01-01,Internal - training,aws-training [project-specific],Proj$project-004,66.66
2024-01-01,Internal - development,aws-production-1 [shared],Proj$shared,1.0
2024-01-01,Internal - training,aws-production-1 [shared],Proj$shared,1.0
2024-01-01,Project A,aws-production-1 [shared],Proj$project-001,888.22
2024-01-01,Project A,aws-production-1 [shared],Proj$shared,1.0
2024-01-01,Project B,aws-production-1 [shared],Proj$project-002,55.668
2024-01-01,Project B,aws-production-1 [shared],Proj$shared,1.0
2024-01-01,SPECIAL-OPS,aws-production-1 [shared],Proj$shared,1.0
2024-01-01,Internal - development,aws-production-2 [shared],Proj$,5.1
2024-01-01,Internal - training,aws-production-2 [shared],Proj$,5.1
2024-01-01,Project A,aws-production-2 [shared],Proj$,5.1
Expand Down
3 changes: 3 additions & 0 deletions example/projects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ proj-tag-names:
"project-003": "Project B"
"project-004": "SPECIAL-OPS"

shared-tag-values:
- "shared"

project-groups:
tre:
- "Project A"
Expand Down

0 comments on commit 037b960

Please sign in to comment.