cloud-foundation-fabric/modules/naming-convention
Ludovico Magnocavallo f6775aca1b
Use the same versions file everywhere, pin to tf 1.0+ provider 4.0+ (#355)
* add default versions file, remove old providers and versions

* use default versions file everywhere

* fix kms module

* re-add provider configuration for data platform step 2

* update kms module outputs sorting

* update kms documentation

* fix data solutions tests

* fix GKE workload identity attribute name

* work around firewall provider issue in datafusion example
2021-11-03 15:05:43 +01:00
..
README.md Add more validations to linter 2021-10-08 18:26:04 +02:00
main.tf Naming convention module (#318) 2021-10-05 12:21:12 +02:00
outputs.tf Naming convention module (#318) 2021-10-05 12:21:12 +02:00
variables.tf Add more validations to linter 2021-10-08 18:26:04 +02:00
versions.tf Use the same versions file everywhere, pin to tf 1.0+ provider 4.0+ (#355) 2021-11-03 15:05:43 +01:00

README.md

Naming Convention Module

This module allows defining a naming convention in a single place, and enforcing it by pre-creating resource names based on a set of tokens (environment, team name, etc.).

It implements a fairly common naming convention with optional prefix or suffix, but is really meant to be forked, and modified to adapt to individual use cases: just replace the environment and team variables with whatever makes sense for you, and edit the few lines in main.tf marked by comments.

The module also supports labels, generating sets of per-resource labels that combine the passed in tokens with optional resource-level labels.

It's completely static, using no provider resources, so its outputs are safe to use where dynamic values are not supported, like in for_each statements.

Example

In its default configuration, the module supports an option prefix and suffix, and two tokens: one for the environment, and one for the team name.

module "names-org" {
  source     = "./modules/naming-convention"
  prefix      = "myco"
  environment = "dev"
  team        = "cloud"
  resources = {
    bucket = ["tf-org", "tf-sec", "tf-log"]
    project = ["tf", "sec", "log"]
  }
  labels = {
    project = {
      tf = {scope = "global"}
    }
  }
}

module "project-tf" {
  source = "./modules/project"
  # myco-cloud-dev-tf
  name   = module.names-org.names.project.tf
  # { environment = "dev", scope = "global", team = "cloud" }
  labels = module.names-org.labels.project.tf
}

You can also enable resource type naming, useful with some legacy CMDB setups. When doing this, resource type names become part of the final resource names and are usually shorted (e.g. prj instead of project):

module "names-org" {
  source     = "./modules/naming-convention"
  prefix      = "myco"
  environment = "dev"
  team        = "cloud"
  resources = {
    bkt = ["tf-org", "tf-sec", "tf-log"]
    prj = ["tf", "sec", "log"]
  }
  labels = {
    prj = {
      tf = {scope = "global"}
    }
  }
  use_resource_prefixes = true
}

module "project-tf" {
  source = "./modules/project"
  # prj-myco-cloud-dev-tf
  name   = module.names-org.names.prj.tf
}

Variables

name description type required default
environment Environment abbreviation used in names and labels. string
resources Short resource names by type. map(list(string))
team Team name. string
labels Per-resource labels. map(map(map(string))) {}
prefix Optional name prefix. string null
separator_override Optional separator override for specific resource types. map(string) {}
suffix Optional name suffix. string null
use_resource_prefixes Prefix names with the resource type. bool false

Outputs

name description sensitive
labels Per resource labels.
names Per resource names.