This is how I do it.
Explore the docs »
Report Bug
.
Request Feature
My opinionated label module.
This Terraform module consumes my terraform-null-context and produces
consistent names and tags for all of my resources. It implements a strict naming
and tagging convention that follows the format from
cloudposse/terraform-null-label.
The Cloud Posse label module provides detailed documentation and reasoning however by itself it has too many knobs and provides more options that I use. This module configures the Cloud Posse label exactly how I like it while taking advantage of my context module to carry standard part of the label around.
This module uses the concept of "project" to represent what the underlying cloudposse/terraform-null-label module calls "stage".
Why the difference?
- The CloudPosse module was originally designed with "stage" representing deployment stages (dev, staging, prod)
- In Ben's modules, we use "environment" for that purpose (following
namespace-role-region→environment) - We repurposed the CloudPosse "stage" field to represent "project" or "application" — the specific workload or service being deployed
What this means for you:
- When you pass
project = "example"to this module, it maps tostage = "example"in the CloudPosse module - Outputs like
module.label.idwill include the project name in the correct position - The
projectoutput exposesmodule.label.stageinternally (see comments inoutputs.tf)
This mapping is intentional and consistent across all of Ben's Terraform modules.
module "context" {
source = "bendoerr-terraform-modules/context/null"
version = "xxx"
namespace = "bd"
role = "production"
region = "us-east-1"
project = "example"
}
module "label" {
source = "bendoerr-terraform-modules/label/null"
version = "xxx"
context = module.context.shared
name = "function"
}
resource "aws_lambda_function" "function" {
function_name = module.label.id # bd-prd-ue1-example-function
tags = module.label.tags # { Name: bd-prd-ue1-example-function,
# Namespace: bd,
# Role: production,
# Region: us-east-1,
# Project: example,
# Environment: prod-ue1,
# }
...
}
resource "aws_route53_record" "function" {
name = "${module.label.dns_name}.${vars.zone_name}" # function.ue1.cloud.bendoerr.me
# assuming vars.zone_name = cloud.bendoerr.me
...
}Project: bendoerr-terraform-modules/terraform-null-label
Name Monthly Qty Unit Monthly Cost
OVERALL TOTAL $0.00
──────────────────────────────────
No cloud resources were detected
This module creates no resources and will not generate any cost against any cloud provider you use.
| Name | Version |
|---|---|
| terraform | >= 0.13 |
This module is designed to be consumed with pessimistic version constraints (~>) to ensure predictable behavior across deployments:
module "label" {
source = "bendoerr-terraform-modules/label/null"
version = "~> 0.3.0" # Allows 0.3.x, prevents 0.4.0
# ...
}Why pessimistic constraints?
- Prevents unexpected breaking changes from major or minor version updates
- Ensures consistent behavior across environments and team members
- Makes upgrade impact predictable and controllable
When a new minor or major version releases, you control when to adopt it. This is intentional - we prefer explicit, tested upgrades over automatic version bumps that might introduce breaking changes.
For more information on Terraform version constraints, see the official documentation.
| Name | Source | Version |
|---|---|---|
| label | cloudposse/label/null | 0.25.0 |
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| context | Shared Context from Ben's terraform-null-label | object({ |
n/a | yes |
| name | Name of this resource | string |
n/a | yes |
| project | Name of the project or application, this can override the context's project | string |
"" |
no |
| Name | Description |
|---|---|
| attributes | List of attributes |
| delimiter | Delimiter between namespace, environment, stage, name and attributes |
| dns_name | Normalized DNS Name |
| environment | Normalized environment |
| id | Disambiguated ID |
| label_order | The naming order of the id output and Name tag |
| name | Normalized name |
| namespace | Normalized namespace |
| project | Normalized project |
| tags | Normalized Tag map |
| tags_as_list_of_maps | Additional tags as a list of maps, which can be used in several AWS resources |
See the open issues for a list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- If you have suggestions for adding or removing projects, feel free to open an issue to discuss it, or directly create a pull request after you edit the README.md file with necessary changes.
- Please make sure you check your spelling and grammar.
- Create individual PR for each suggestion.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the MIT License. See LICENSE for more information.
- Benjamin R. Doerr - Terraformer - Benjamin R. Doerr - Built Ben's Terraform Modules
Only the latest tagged version is supported.
See SECURITY.md.