Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Oct 18, 2024
1 parent 76b5c40 commit 1c5e1c8
Show file tree
Hide file tree
Showing 11 changed files with 211 additions and 4 deletions.
5 changes: 2 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion common/version.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
locals {
_module_version = "0.0.0"
_module_version = "0.0.1"
_module_name = "boc-nts"
}
32 changes: 32 additions & 0 deletions tags/.tf-control
Original file line number Diff line number Diff line change
@@ -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"
24 changes: 24 additions & 0 deletions tags/.tf-control.tfrc
Original file line number Diff line number Diff line change
@@ -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 = [ "*/*/*" ]
}
}

75 changes: 75 additions & 0 deletions tags/config.yml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions tags/locals.tf
Original file line number Diff line number Diff line change
@@ -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")
}
}
13 changes: 13 additions & 0 deletions tags/main.tf
Original file line number Diff line number Diff line change
@@ -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" }
}
15 changes: 15 additions & 0 deletions tags/outputs.tf
Original file line number Diff line number Diff line change
@@ -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
}
}
9 changes: 9 additions & 0 deletions tags/tags.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
finops:
number: 17
name: frank
role:
mon:
priority:
visibility:
ops:

31 changes: 31 additions & 0 deletions tags/variables.tf
Original file line number Diff line number Diff line change
@@ -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" {}
1 change: 1 addition & 0 deletions tags/version.tf

0 comments on commit 1c5e1c8

Please sign in to comment.