* update tfdoc * rewrite check docs, refactor tfdoc replace, regenerate modules READMEs * remove dead code from check docs * do not fail on missing variable files in check docs * fix typos |
||
---|---|---|
.. | ||
README.md | ||
main.tf | ||
outputs.tf | ||
variables.tf | ||
versions.tf |
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. |