Skip to content

WalletConnect/terraform-null-label

Repository files navigation

label module

Module to generate consistent names and tags for resources.

There are 5 inputs considered "labels" or "ID elements" (because the labels are used to construct the ID):

  1. namespace
  2. region
  3. stage
  4. name
  5. attributes

This module generates IDs using the following convention by default: {namespace}-{region}-{stage}-{name}-{attributes}. However, it is highly configurable. The delimiter (e.g. -) is configurable. Each label item is optional (although you must provide at least one). So if you prefer the term stage to region and do not need tenant, you can exclude them and the label id will look like {namespace}-{stage}-{name}-{attributes}.

  • The attributes input is actually a list of strings and {attributes} expands to the list elements joined by the delimiter.
  • If attributes is excluded but namespace, stage, and region are included, id will look like {namespace}-{region}-{stage}-{name}. Excluding attributes is discouraged, though, because attributes are the main way modules modify the ID to ensure uniqueness when provisioning the same resource types.
  • If you want the label items in a different order, you can specify that, too, with the label_order list.
  • You can set a maximum length for the id, and the module will create a (probably) unique name that fits within that length. (The module uses a portion of the MD5 hash of the full id to represent the missing part, so there remains a slight chance of name collision.)
  • You can control the letter case of the generated labels which make up the id using var.label_value_case.
  • All the non-empty labels are also exported as tags, whether they appear in the id or not.

It's recommended to use one label module for every unique resource of a given resource type. For example, if you have 10 instances, there should be 10 different labels. However, if you have multiple different kinds of resources (e.g. instances, security groups, file systems, and elastic ips), then they can all share the same label assuming they are logically related.

For most purposes, the id output is sufficient to create an ID or label for a resource, and if you want a different ID or a different format, you would instantiate another instance of label and configure it accordingly.

Requirements

Name Version
terraform >= 1.0

Providers

No providers.

Modules

No modules.

Resources

No resources.

Inputs

Name Description Type Default Required
attributes ID element. Additional attributes (e.g. workers or cluster) to add to id,
in the order they appear in the list. New attributes are appended to the
end of the list. The elements of the list are joined by the delimiter
and treated as a single ID element.
list(string) [] no
context Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as null to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes and tags, which are merged.
any
{
"attributes": [],
"delimiter": null,
"id_length_limit": null,
"label_key_case": null,
"label_order": [],
"label_value_case": null,
"name": null,
"namespace": null,
"regex_replace_chars": null,
"region": null,
"stage": null,
"tags": {}
}
no
delimiter Delimiter to be used between ID elements.
Defaults to - (hyphen). Set to "" to use no delimiter at all.
string null no
id_length_limit Limit id to this many characters (minimum 6).
Set to 0 for unlimited length.
Set to null for keep the existing setting, which defaults to 0.
Does not affect id_full.
number null no
label_key_case Controls the letter case of the tags keys (label names) for tags generated by this module.
Does not affect keys of tags passed in via the tags input.
Possible values: lower, title, upper.
Default value: title.
string null no
label_order The order in which the labels (ID elements) appear in the id.
Defaults to ["namespace", "region", "stage", "name", "attributes"].
You can omit any of the 5 labels, but at least one must be present.
list(string) null no
label_value_case Controls the letter case of ID elements (labels) as included in id,
set as tag values, and output by this module individually.
Does not affect values of tags passed in via the tags input.
Possible values: lower, title, upper and none (no transformation).
Set this to title and set delimiter to "" to yield Pascal Case IDs.
Default value: lower.
string null no
name ID element. Usually the component name.
This is the only ID element not also included as a tag.
The "name" tag is set to the full id string. There is no tag with the value of the name input.
string null no
namespace ID element. Usually the organization name, i.e. 'walletconnect' to help ensure generated IDs are globally unique. string null no
regex_replace_chars Terraform regular expression (regex) string.
Characters matching the regex will be removed from the ID elements.
If not set, "/[^a-zA-Z0-9-]/" is used to remove all characters other than hyphens, letters and digits.
string null no
region ID element. Usually used for region e.g. 'uw2', 'us-west-2'. string null no
stage ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release'. string null no
tags Additional tags. map(string) {} no

Outputs

Name Description
attributes List of attributes
context Merged but otherwise unmodified input to this module, to be used as context input to other modules.
Note: this version will have null values as defaults, not the values actually used as defaults.
delimiter Delimiter between namespace, tenant, region, stage, name and attributes
id Disambiguated ID string restricted to id_length_limit characters in total
id_full ID string not restricted in length
id_length_limit The id_length_limit actually used to create the ID, with 0 meaning unlimited
label_order The naming order actually used to create the ID
name Normalized name
namespace Normalized namespace
normalized_context Normalized context of this module
regex_replace_chars The regex_replace_chars actually used to create the ID
region Normalized region
stage Normalized stage
tags Normalized Tag map

About

No description or website provided.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages