From a95bd5ec9da5ec9e247f334b565526472d62ee2c Mon Sep 17 00:00:00 2001 From: badra001 Date: Fri, 18 Oct 2024 10:44:26 -0400 Subject: [PATCH] update --- tags/main.tf | 11 +---------- tags/outputs.tf | 2 +- tags/tags.finops.tf | 21 +++++++++++++++++++++ tags/variables.tf | 10 +++++----- 4 files changed, 28 insertions(+), 16 deletions(-) create mode 100644 tags/tags.finops.tf diff --git a/tags/main.tf b/tags/main.tf index 2d616fb..1c14966 100644 --- a/tags/main.tf +++ b/tags/main.tf @@ -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" } } diff --git a/tags/outputs.tf b/tags/outputs.tf index d3bb60e..55eb878 100644 --- a/tags/outputs.tf +++ b/tags/outputs.tf @@ -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 }, ) } diff --git a/tags/tags.finops.tf b/tags/tags.finops.tf new file mode 100644 index 0000000..6565450 --- /dev/null +++ b/tags/tags.finops.tf @@ -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." + } + } +} diff --git a/tags/variables.tf b/tags/variables.tf index 29b2205..a202667 100644 --- a/tags/variables.tf +++ b/tags/variables.tf @@ -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" {}