diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ce3418..65491d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,4 @@ # Versions -* v1.0.0 -- {{ yyyy-mm-dd }} - - initial creation - +- 0.0.1 -- 2024-10-18 + - initial creation with tags for finops diff --git a/common/version.tf b/common/version.tf index a0cd862..8eeb428 100644 --- a/common/version.tf +++ b/common/version.tf @@ -1,3 +1,4 @@ locals { - _module_version = "0.0.0" + _module_version = "0.0.1" + _module_name = "boc-nts" } diff --git a/tags/.tf-control b/tags/.tf-control new file mode 100644 index 0000000..340816b --- /dev/null +++ b/tags/.tf-control @@ -0,0 +1,32 @@ +# .tf-control +# allows for setting a specific command to be used for tf-* commands under this git repo +# see tf-control.sh help for more info + +TFCONTROL_VERSION="1.0.7" +#TFCOMMAND="terraform_latest" +TFCOMMAND="terraform_current" + +# TF_CLI_CONFIG_FILE=PATH-TO-FILE/.tf-control.tfrc +# TFARGS="" +# TFNOLOG="" +# TFNOCOLOR="" + +# from issue: https://github.com/hashicorp/terraform/issues/32901 +# to get to TF 1.4 and beyond in a shared cache environment +# this is currently in the tf-control.sh script explicitly +#TF_PLUGIN_CACHE_MAY_BREAK_DEPENDENCY_LOCK_FILE=1 + +# use the following to force a specific version. An upgrade of an existing 0.12.31 to 1.x +# needs you to cycle through 0.13.17, 0.14.11, and then latest (0.15.5 not needed). Other +# steps in between. See https://github.e.it.census.gov/terraform/support/tree/master/docs/how-to/terraform-upgrade for details +# +#TFCOMMAND="terraform_0.12.31" +#TFCOMMAND="terraform_0.13.7" +#TFCOMMAND="terraform_0.14.11" +#TFCOMMAND="terraform_0.15.5" +#TFCOMMAND="terraform_1.3.10" +#TFCOMMAND="terraform_1.4.7" +#TFCOMMAND="terraform_1.5.7" +#TFCOMMAND="terraform_1.6.6" +#TFCOMMAND="terraform_1.7.5" +#TFCOMMAND="terraform_1.8.2" diff --git a/tags/.tf-control.tfrc b/tags/.tf-control.tfrc new file mode 100644 index 0000000..7425488 --- /dev/null +++ b/tags/.tf-control.tfrc @@ -0,0 +1,24 @@ +TFCONTROL_VERSION="1.0.5" + +# https://www.terraform.io/docs/cli/config/config-file.html +plugin_cache_dir = "/data/terraform/terraform.d/plugin-cache" +#disable_checkpoint = true + +provider_installation { +# filesystem_mirror { +# path = "/apps/terraform/terraform.d/providers" +# include = [ "*/*/*" ] +# } + filesystem_mirror { + path = "/data/terraform/terraform.d/providers" + include = [ "*/*/*" ] + } +# filesystem_mirror { +# path = "/apps/terraform/terraform.d/providers" +# include = [ "external.terraform.census.gov/*/*" ] +# } + direct { + include = [ "*/*/*" ] + } +} + diff --git a/tags/config.yml b/tags/config.yml new file mode 100644 index 0000000..7ea44a4 --- /dev/null +++ b/tags/config.yml @@ -0,0 +1,75 @@ +finops_project_number: + valid_values: + - fs0000000000 + - fs0000000000 + - fs0000000001 + - fs0000000002 + - fs0000000003 + - fs0000000004 + - fs0000000004 + - fs0000000005 + - fs0000000006 + - fs0000000007 + - fs0000000008 + - fs0000000009 + - fs0000000010 + - fs0000000011 + - fs0000000012 + - fs0000000013 + - fs0000000014 + - fs0000000015 + - fs0000000015 + - fs0000000016 + - fs0000000017 + - fs0000000018 + - fs0000000019 + - fs0000000020 + - fs0000000021 + - fs0000000022 + - fs0000000023 + - fs0000000023 + - fs0000000023 + - fs0000000024 + - fs0000000024 + - fs0000000025 + - fs0000000026 + - fs0000000027 + - fs0000000028 + - fs0000000029 + - fs0000000030 + - fs0000000031 + - fs0000000032 + - fs0000000033 + - fs0000000034 + - fs0000000034 + - fs0000000035 + - fs0000000036 + - fs0000000037 + - fs0000000038 + - fs0000000039 + - fs0000000039 + - fs0000000040 + - fs0000000041 + - fs0000000042 + - fs0000000042 + - fs0000000042 + - fs0000000042 + - fs0000000043 + - fs0000000044 + - fs0000000045 + - fs0000000046 + - fs0000000047 + - fs0000000048 + - fs0000000049 + - fs0000000050 + - fs0000000051 + - fs0000000052 + - fs0000000053 + - fs0000000054 + - fs0000000055 + - fs0000000056 + - fs0000000057 + - fs0000000058 + - fs0000000059 + - fs0000000060 + - fs0000000063 diff --git a/tags/locals.tf b/tags/locals.tf new file mode 100644 index 0000000..efc0208 --- /dev/null +++ b/tags/locals.tf @@ -0,0 +1,7 @@ +locals { + base_tags = { + "boc:created_by" = "terraform" + "boc:tf_module_version" = local._module_version + "boc:tf_module_name" = format("%v/%v", local._module_name, "tags") + } +} diff --git a/tags/main.tf b/tags/main.tf new file mode 100644 index 0000000..2d616fb --- /dev/null +++ b/tags/main.tf @@ -0,0 +1,13 @@ +locals { + 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 new file mode 100644 index 0000000..d8b92d1 --- /dev/null +++ b/tags/outputs.tf @@ -0,0 +1,15 @@ +output "tags" { + description = "Map of processed tag key/value pairs" + value = merge( + local.base_tags, + { for k, v in local.finops_tags : format("%v_%v", local._finops_tags.prefix, k) => v }, + ) +} + +output "tag_hierarchy" { + description = "Map of processed tag key/value pairs grouped by category" + value = { + "base" = local.base_tags + "finops" = local.finops_tags + } +} diff --git a/tags/tags.yml b/tags/tags.yml new file mode 100644 index 0000000..5285bfb --- /dev/null +++ b/tags/tags.yml @@ -0,0 +1,9 @@ +finops: + number: 17 + name: frank + role: +mon: + priority: + visibility: +ops: + diff --git a/tags/variables.tf b/tags/variables.tf new file mode 100644 index 0000000..b379b90 --- /dev/null +++ b/tags/variables.tf @@ -0,0 +1,31 @@ +variable "filename" { + description = "Filename of YAML file with tags (see documentation for structure)" + type = string + default = null +} + +variable "filenames" { + description = "Filenames of YAML file with tags (see documentation for structure). Each will be processed and the resultant tags merged" + type = list(string) + default = [] +} + +#--- +# finops +#--- +variable "finops" { + description = "FinOps Related tags (required: number, name; not-required: role)" + type = object({ + number = number + name = string + role = optional(string) + }) + + validation { + condition = var.finops.number > 0 && var.finops.number < 10000000000 + error_message = "Invalid finops.number, must be between 0 and 10,000,000,000." + } +} + +# variable "ops" {} +# variable "mon" {} diff --git a/tags/version.tf b/tags/version.tf new file mode 120000 index 0000000..b83c5b7 --- /dev/null +++ b/tags/version.tf @@ -0,0 +1 @@ +../common/version.tf \ No newline at end of file