Skip to content

Commit

Permalink
test feature with roles
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Nov 22, 2024
1 parent 86da45d commit 9c3fdaa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tags/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ output "tag_hierarchy" {
"finops" = local.finops_tags
}
}

output "finops_roles" {
description = "Map of finops_project_role values based on finops_project_name and finops.roles in YAML"
value = { for r in local.finops_roles : r => format("%v_%v", local._finops_tags.name, r) }
}
12 changes: 12 additions & 0 deletions tags/tags.finops.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ locals {
project_role = local._finops.role != null ? replace(replace(local._finops.role, "+", format("%v_", local._finops.name)), "/[^a-z0-9_]/", "") : null
}
finops_tags = { for k, v in local._finops_tags : k => v if v != null && k != "prefix" }
finops_roles = [for r in lookup(local.tags_in.finops,"roles",[]): lower(r) ]
}

resource "terraform_data" "finops" {
Expand All @@ -21,3 +22,14 @@ resource "terraform_data" "finops" {
}
}

resource "terraform_data" "finops_roles" {
count = length(local.finops_roles) > 0 ? 1 : 0
input = local.finops_roles

lifecycle {
precondition {
condition = any([for r in local.finops_roles: length(regexall("[^0-9a-z_]",r)) > 0 ])
error_message = "finops.roles fields can contain only 0-9, a-z, and underscore."
}
}
}

0 comments on commit 9c3fdaa

Please sign in to comment.