Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Oct 18, 2024
1 parent 63c9b99 commit a95bd5e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
11 changes: 1 addition & 10 deletions tags/main.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
locals {
tags_in = var.filename != null && try(fileexists(var.filename), false) ? yamldecode(file(var.filename)) : yamldecode("")
tags_in = var.filename != null && try(fileexists(var.filename), false) ? yamldecode(file(var.filename)) : yamldecode("{}")
tags_filenames_in = length(var.filenames) > 0 ? { for f in var.filenames : f => yamldecode(file(f)) if fileexists(f) } : {}

_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 = format("fs%010d", local._finops.number)
project_name = replace(local._finops.name, "/[^a-z0-9_]/", "")
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" }
}
2 changes: 1 addition & 1 deletion tags/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
output "tags" {
description = "Map of processed tag key/value pairs"
value = merge(
# local.base_tags,
# local.base_tags,
{ for k, v in local.finops_tags : format("%v_%v", local._finops_tags.prefix, k) => v },
)
}
Expand Down
21 changes: 21 additions & 0 deletions tags/tags.finops.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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_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" }
}

resource "terraform_data" "finops" {
input = local.finops_tags

lifecycle {
precondition {
condition = local._finops.number > 0 && local._finops.number < 10000000000
error_message = "Invalid finops.number, must be between 0 and 10,000,000,000."
}
}
}
10 changes: 5 additions & 5 deletions tags/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ variable "finops" {
})
default = {
number = null
name = null
name = null
}

validation {
condition = length(var.finops)>0 && var.finops.number==null || (var.finops.number > 0 && var.finops.number < 10000000000)
error_message = "Invalid finops.number, must be between 0 and 10,000,000,000."
}
# validation {
# condition = length(var.finops)>0 && var.finops.number==null || (var.finops.number > 0 && var.finops.number < 10000000000)
# error_message = "Invalid finops.number, must be between 0 and 10,000,000,000."
# }
}

# variable "ops" {}
Expand Down

0 comments on commit a95bd5e

Please sign in to comment.