Skip to content

Commit

Permalink
add base-label prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Jul 30, 2025
1 parent 3c9736b commit 852dd32
Show file tree
Hide file tree
Showing 17 changed files with 252 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@

- 0.1.0 -- 2025-04-14
- add map for (AWS Migration Accleration Program) tag section (automatic, but need to select them from output)

- 0.2.0 -- 2025-07-29
- add base-label
- add prefixes
32 changes: 32 additions & 0 deletions base-label/.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 base-label/.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 = [ "*/*/*" ]
}
}

7 changes: 7 additions & 0 deletions base-label/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, "base-label")
}
}
4 changes: 4 additions & 0 deletions base-label/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output "version" {
description = "Module version information. Cannot be passed back in tags because it will overwrite other module tags"
value = local.base_tags
}
11 changes: 11 additions & 0 deletions base-label/prefixes.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
locals {
_prefixes = yamldecode(file(format("%v/prefixes.yml", path.module)))["prefixes"]
prefixes = { for k, v in local._prefixes : k => v!=null ? format("%v-", v) : "" }
}

output "prefixes" {
description = "Pre-defined prefixes map. If missing, there is no prefix for the component."
value = local.prefixes
}

# get prefix with: try(module.x.prefixes.s3,"")
41 changes: 41 additions & 0 deletions base-label/prefixes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
prefixes:
customer-gateway: cgw
dhcp-options:
ebs: v-ebs
ecs: ecs
ecs-policy: p-ecs
ecs-role: r-ecs
ecs-security-group: ecs
ecs-user: s-ecs
efs: v-efs
eks-policy: p-eks
eks-role: r-eks
eks-security-group: eks
eks-user: s-eks
elastic-ip: eip
group: g
iam-admin-user: a
iam-service-user: s
iam-user: u
internet-gateway: igw
kms: k-kms
log-group: lg
log-stream: lgs
nat-gateway: nat
network-acl: nacl
policy: p
role: r
route-table: route
s3: v-s3
security-group:
subnet:
transit-gateway-attachment: tgwa
transit-gateway-peer: tgwp
transit-gateway-route-table: tgwr
transit-gateway: tgw
transit-gateway-vpn: tgwv
vpc:
vpc-endpoint: vpce
vpc-peer: vpcp
vpn-connection: vpn_
vpn-gateway: vpcg
27 changes: 27 additions & 0 deletions base-label/tf-run.data
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
VERSION 2.1.1
TAG setup
REMOTE-STATE
COMMAND tf-directory-setup.py -l none -f
COMMAND setup-new-directory.sh

TAG links
LINKTOP includes.d/variables.account_tags.tf
LINKTOP includes.d/variables.account_tags.auto.tfvars
LINKTOP includes.d/variables.infrastructure_tags.tf
LINKTOP includes.d/variables.infrastructure_tags.auto.tfvars
LINKTOP includes.d/variables.application_tags.tf
LINKTOP includes.d/variables.application_tags.auto.tfvars
# LINKTOP provider_configs.d/provider.ldap_new.auto.tfvars
# LINKTOP provider_configs.d/provider.ldap_new.tf
# LINKTOP provider_configs.d/provider.ldap_new.variables.tf
COMMAND rm -f provider.ldap.*

TAG init
COMMAND tf-init

TAG start
#POLICY
ALL

TAG state-link
COMMAND tf-directory-setup.py -l s3
14 changes: 7 additions & 7 deletions base-label/variables.tf
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
variable "business" {
description = "Business label (organization, program, etc)"
type = string
type = string
}

variable "application" {
description = "Application label"
type = string
type = string
}

variable "environment" {
description = "Environment label"
type = string
type = string

validation {
condition = contains(["dev","test","qa","uat","ite","stage","prod","cre","sa","services","common"],var.environment)
error_message = "var.environment value invalid. See https://github.e.it.census.gov/terraform/cloud-information/tree/master/aws/documentation/naming-tagging-standard for valid list."
condition = contains(["dev", "test", "qa", "uat", "ite", "stage", "prod", "cre", "sa", "services", "common"], var.environment)
error_message = "The var.environment value invalid. See https://github.e.it.census.gov/terraform/cloud-information/tree/master/aws/documentation/naming-tagging-standard for valid list."
}
}

variable "custom" {
description = "Custom label"
type = string
default = null
type = string
default = null
}
1 change: 1 addition & 0 deletions base-label/version.tf
33 changes: 33 additions & 0 deletions base-label/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
terraform {
required_version = ">= 1.0.0"
required_providers {
# aws = {
# source = "hashicorp/aws"
# version = ">= 5.0"
# }
# ldap = {
# source = "trevex/ldap"
# version = ">= 0.5.4"
# }
# external = {
# source = "hashicorp/external"
# version = ">= 1.0"
# }
# null = {
# source = "hashicorp/null"
# version = ">= 1.0"
# }
# random = {
# source = "hashicorp/random"
# version = ">= 1.0"
# }
# template = {
# source = "hashicorp/template"
# version = ">= 1.0"
# }
# infoblox = {
# source = "infobloxopen/infoblox"
# version = ">= 2.1.0"
# }
}
}
3 changes: 2 additions & 1 deletion common/locals.tf.initial
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ locals {
account_environment = data.aws_arn.current.partition == "aws-us-gov" ? "gov" : "ew"

base_tags = {
"boc:tf_module_version" = local._module_version
"boc:created_by" = "terraform"
"boc:tf_module_version" = local._module_version
"boc:tf_module_version" = local._module_name
}
}
2 changes: 1 addition & 1 deletion common/version.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
locals {
_module_version = "0.1.0"
_module_version = "0.2.0"
_module_name = "boc-nts"
}
11 changes: 11 additions & 0 deletions examples/tags/tags.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module "tags" {
# source = "git@github.e.it.census.gov:terraform-modules/boc-nts//tags"
source = "../../tags"
filename = format("%v/%v", path.root, "tags.yml")

legacy_tags = merge(
var.account_tags,
var.infrastructure_tags,
var.application_tags,
)
}
4 changes: 4 additions & 0 deletions examples/tags/variable.application_tags.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "application_tags" {
description = "Map of application tags"
type = map(string)
}
33 changes: 33 additions & 0 deletions examples/tags/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 4.0"
}
# ldap = {
# source = "trevex/ldap"
# version = ">= 0.5.4"
# }
# external = {
# source = "hashicorp/external"
# version = ">= 1.0"
# }
# null = {
# source = "hashicorp/null"
# version = ">= 1.0"
# }
# random = {
# source = "hashicorp/random"
# version = ">= 1.0"
# }
# template = {
# source = "hashicorp/template"
# version = ">= 1.0"
# }
# infoblox = {
# source = "infobloxopen/infoblox"
# version = ">= 2.1.0"
# }
}
required_version = ">= 1.0.0"
}
10 changes: 10 additions & 0 deletions tags/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,13 @@ output "finops_roles" {
description = "Map of finops_project_role values based on finops_project_name and finops.roles in YAML"
value = { for r in local.finops_roles : r => { (format("%v_%v_role", local._finops_tags.prefix, "project")) = format("%v_%v", local.finops_tags.project_name, r) } }
}

output "finops_tags" {
description = "Map of finops tags by short name for individual selection"
value = { for k,v in local.finops_tags : replace(k,"${local._finops_tags_prefix}_","") => { k = v }}
}

output "version" {
description = "Module version information. Cannot be passed back in tags because it will overwrite other module tags"
value = local.base_tags
}

0 comments on commit 852dd32

Please sign in to comment.