Skip to content

Commit 5fea994

Browse files
authored
Fix tags (#43)
* Don't include tags with empty values * Fix README links * Update README
1 parent 5d770f4 commit 5fea994

File tree

5 files changed

+16
-18
lines changed

5 files changed

+16
-18
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Cloud Posse](https://cloudposse.com/logo-300x69.svg)](https://cloudposse.com)
44

5-
# terraform-null-label [![Build Status](https://travis-ci.org/cloudposse/terraform-null-label.svg?branch=master)](https://travis-ci.org/cloudposse/terraform-null-label-cloudtrail) [![Latest Release](https://img.shields.io/github/release/cloudposse/terraform-null-label.svg)](https://github.com/cloudposse/terraform-null-label/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com)
5+
# terraform-null-label [![Build Status](https://travis-ci.org/cloudposse/terraform-null-label.svg?branch=master)](https://travis-ci.org/cloudposse/terraform-null-label) [![Latest Release](https://img.shields.io/github/release/cloudposse/terraform-null-label.svg)](https://github.com/cloudposse/terraform-null-label/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com)
66

77

88
Terraform module designed to generate consistent label names and tags for resources. Use `terraform-null-label` to implement a strict naming convention.
@@ -401,9 +401,9 @@ Available targets:
401401

402402
| Name | Description |
403403
|------|-------------|
404-
| attributes | Normalized attributes |
405-
| context | Context of this module to pass between other modules |
406-
| delimiter | Delimiter used in label ID |
404+
| attributes | List of attributes |
405+
| context | Context of this module to pass to other label modules |
406+
| delimiter | Delimiter between `namespace`, `environment`, `stage`, `name` and `attributes` |
407407
| environment | Normalized environment |
408408
| id | Disambiguated ID |
409409
| label_order | The naming order of the id output and Name tag |

README.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ github_repo: cloudposse/terraform-null-label
2020
badges:
2121
- name: "Build Status"
2222
image: "https://travis-ci.org/cloudposse/terraform-null-label.svg?branch=master"
23-
url: "https://travis-ci.org/cloudposse/terraform-null-label-cloudtrail"
23+
url: "https://travis-ci.org/cloudposse/terraform-null-label"
2424
- name: "Latest Release"
2525
image: "https://img.shields.io/github/release/cloudposse/terraform-null-label.svg"
2626
url: "https://github.com/cloudposse/terraform-null-label/releases/latest"

docs/terraform.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

2020
| Name | Description |
2121
|------|-------------|
22-
| attributes | Normalized attributes |
23-
| context | Context of this module to pass between other modules |
24-
| delimiter | Delimiter used in label ID |
22+
| attributes | List of attributes |
23+
| context | Context of this module to pass to other label modules |
24+
| delimiter | Delimiter between `namespace`, `environment`, `stage`, `name` and `attributes` |
2525
| environment | Normalized environment |
2626
| id | Disambiguated ID |
2727
| label_order | The naming order of the id output and Name tag |

main.tf

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,11 @@ locals {
4444
delimiter = "${var.delimiter != "-" ? var.delimiter : local.delimiter_context_or_default}"
4545
# Merge attributes
4646
attributes = ["${distinct(compact(concat(var.attributes, local.context_local["attributes"])))}"]
47-
# Generate tags
48-
generated_tags = {
49-
"Name" = "${local.id}"
50-
"Namespace" = "${local.namespace}"
51-
"Environment" = "${local.environment}"
52-
"Stage" = "${local.stage}"
53-
}
47+
# Generate tags (don't include tags with empty values)
48+
generated_tags = "${zipmap(
49+
compact(list("Name", local.namespace != "" ? "Namespace" : "", local.environment != "" ? "Environment" : "", local.stage != "" ? "Stage" : "")),
50+
compact(list(local.id, local.namespace, local.environment, local.stage))
51+
)}"
5452
tags = "${merge(zipmap(local.context_local["tags_keys"], local.context_local["tags_values"]), local.generated_tags, var.tags)}"
5553
tags_as_list_of_maps = ["${data.null_data_source.tags_as_list_of_maps.*.outputs}"]
5654
label_order_default_list = "${list("namespace", "environment", "stage", "name", "attributes")}"

outputs.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ output "environment" {
2525

2626
output "attributes" {
2727
value = "${local.attributes}"
28-
description = "Normalized attributes"
28+
description = "List of attributes"
2929
}
3030

3131
output "delimiter" {
3232
value = "${local.enabled ? local.delimiter : ""}"
33-
description = "Delimiter used in label ID"
33+
description = "Delimiter between `namespace`, `environment`, `stage`, `name` and `attributes`"
3434
}
3535

3636
output "tags" {
@@ -45,7 +45,7 @@ output "tags_as_list_of_maps" {
4545

4646
output "context" {
4747
value = "${local.output_context}"
48-
description = "Context of this module to pass between other modules"
48+
description = "Context of this module to pass to other label modules"
4949
}
5050

5151
output "label_order" {

0 commit comments

Comments
 (0)