Skip to content

Commit

Permalink
add conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Nov 8, 2024
1 parent 8afd264 commit 1d73fcb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
7 changes: 4 additions & 3 deletions tags/tags.finops.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ locals {
_finops = { for k in ["number", "name", "role"] : k => try(local.tags_in.finops[k], try(var.finops[k], null)) }
_finops_tags = {
prefix = "finops"
project_number = try(format("fs%010d", local._finops.number),null)
project_name = try(replace(local._finops.name, "/[^a-z0-9_]/", ""),null)
project_number = try(format("fs%010d", local._finops.number), null)
project_name = try(replace(local._finops.name, "/[^a-z0-9_]/", ""), null)
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_tags2 = { for k, v in local._finops_tags : k => v if v != null && k != "prefix" }
finops_tags = merge(local.legacy_finops_converted, local._finops_tags2)
}

resource "terraform_data" "finops" {
Expand Down
11 changes: 11 additions & 0 deletions tags/tags.legacy.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
locals {
legacy_finops_tags = {
project_number = ["Project Number", "ProjectNumber"]
project_name = ["Project Name", "ProjectName"]
project_role = ["Project Role", "ProjectRole"]
}
legacy_finops_tags_map = { for k, v in transpose(local.legacy_finops_tags) : k => v[0] }

_legacy_finops1 = [for k, v in var.legacy_tags : { legacy_key = k, value = v, key = lookup(local.legacy_finops_tags_map, k, null) }]
legacy_finops_converted = merge([for t in local._legacy_finops1 : { (t.key) = lower(t.value) } if t.key != null]...)
}
6 changes: 6 additions & 0 deletions tags/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@ variable "finops" {

# variable "ops" {}
# variable "mon" {}

variable "legacy_tags" {
description = "Legacy tags (primarily the older finops tags) for which we will output a conversion"
type = map(string)
default = {}
}

0 comments on commit 1d73fcb

Please sign in to comment.