Skip to content

Commit dec8215

Browse files
authored
Include all context inputs as normalized outputs (#100)
1 parent e9c2275 commit dec8215

File tree

9 files changed

+130
-82
lines changed

9 files changed

+130
-82
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,16 +672,20 @@ No provider.
672672

673673
| Name | Description |
674674
|------|-------------|
675+
| additional\_tag\_map | The merged additional\_tag\_map |
675676
| attributes | List of attributes |
676-
| context | Merged but otherwise unmodified input to this module, to be use as context input to other modules. |
677+
| context | Merged but otherwise unmodified input to this module, to be used as context input to other modules.<br>Note: this version will have null values as defaults, not the values actually used as defaults. |
677678
| delimiter | Delimiter between `namespace`, `environment`, `stage`, `name` and `attributes` |
679+
| enabled | True if module is enabled, false otherwise |
678680
| environment | Normalized environment |
679681
| id | Disambiguated ID restricted to `id_length_limit` characters in total |
680682
| id\_full | Disambiguated ID not restricted in length |
681-
| label\_order | The naming order of the id output and Name tag |
683+
| id\_length\_limit | The id\_length\_limit actually used to create the ID, with `0` meaning unlimited |
684+
| label\_order | The naming order actually used to create the ID |
682685
| name | Normalized name |
683686
| namespace | Normalized namespace |
684687
| normalized\_context | Normalized context of this module |
688+
| regex\_replace\_chars | The regex\_replace\_chars actually used to create the ID |
685689
| stage | Normalized stage |
686690
| tags | Normalized Tag map |
687691
| tags\_as\_list\_of\_maps | Additional tags as a list of maps, which can be used in several AWS resources |

docs/terraform.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,20 @@ No provider.
3030

3131
| Name | Description |
3232
|------|-------------|
33+
| additional\_tag\_map | The merged additional\_tag\_map |
3334
| attributes | List of attributes |
34-
| context | Merged but otherwise unmodified input to this module, to be use as context input to other modules. |
35+
| context | Merged but otherwise unmodified input to this module, to be used as context input to other modules.<br>Note: this version will have null values as defaults, not the values actually used as defaults. |
3536
| delimiter | Delimiter between `namespace`, `environment`, `stage`, `name` and `attributes` |
37+
| enabled | True if module is enabled, false otherwise |
3638
| environment | Normalized environment |
3739
| id | Disambiguated ID restricted to `id_length_limit` characters in total |
3840
| id\_full | Disambiguated ID not restricted in length |
39-
| label\_order | The naming order of the id output and Name tag |
41+
| id\_length\_limit | The id\_length\_limit actually used to create the ID, with `0` meaning unlimited |
42+
| label\_order | The naming order actually used to create the ID |
4043
| name | Normalized name |
4144
| namespace | Normalized namespace |
4245
| normalized\_context | Normalized context of this module |
46+
| regex\_replace\_chars | The regex\_replace\_chars actually used to create the ID |
4347
| stage | Normalized stage |
4448
| tags | Normalized Tag map |
4549
| tags\_as\_list\_of\_maps | Additional tags as a list of maps, which can be used in several AWS resources |

examples/complete/context.tf

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ variable "context" {
4444
label_order = []
4545
id_length_limit = null
4646
}
47-
description = <<EOT
48-
Single object for setting entire context at once.
49-
See description of individual variables for details.
50-
Leave string and numeric variables as `null` to use default value.
51-
Individual variable settings (non-null) override settings in context object,
52-
except for attributes, tags, and additional_tag_map, which are merged.
47+
description = <<-EOT
48+
Single object for setting entire context at once.
49+
See description of individual variables for details.
50+
Leave string and numeric variables as `null` to use default value.
51+
Individual variable settings (non-null) override settings in context object,
52+
except for attributes, tags, and additional_tag_map, which are merged.
5353
EOT
5454
}
5555

@@ -68,7 +68,7 @@ variable "namespace" {
6868
variable "environment" {
6969
type = string
7070
default = null
71-
description = "Environment, e.g. 'prod', 'staging', 'dev', 'pre-prod', 'UAT'"
71+
description = "Environment, e.g. 'uw2', 'us-west-2', OR 'prod', 'staging', 'dev', 'UAT'"
7272
}
7373

7474
variable "stage" {
@@ -86,7 +86,10 @@ variable "name" {
8686
variable "delimiter" {
8787
type = string
8888
default = null
89-
description = "Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`"
89+
description = <<-EOT
90+
Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`.
91+
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all.
92+
EOT
9093
}
9194

9295
variable "attributes" {
@@ -104,34 +107,36 @@ variable "tags" {
104107
variable "additional_tag_map" {
105108
type = map(string)
106109
default = {}
107-
description = "Additional tags for appending to each tag map"
110+
description = "Additional tags for appending to tags_as_list_of_maps. Not added to `tags`."
108111
}
109112

110113
variable "label_order" {
111114
type = list(string)
112115
default = null
113-
description = "The naming order of the id output and Name tag"
116+
description = <<-EOT
117+
The naming order of the id output and Name tag.
118+
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
119+
You can omit any of the 5 elements, but at least one must be present.
120+
EOT
114121
}
115122

116123
variable "regex_replace_chars" {
117124
type = string
118125
default = null
119-
description = <<EOT
120-
Regex to replace chars with empty string in
121-
`namespace`, `environment`, `stage` and `name`.
122-
If not set, "/[^a-zA-Z0-9-]/" is used to remove
123-
all characters other than hyphens, letters and digits.
126+
description = <<-EOT
127+
Regex to replace chars with empty string in `namespace`, `environment`, `stage` and `name`.
128+
If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits.
124129
EOT
125130
}
126131

127132
variable "id_length_limit" {
128133
type = number
129134
default = null
130-
description = <<EOT
131-
Limit `id` to this many characters.
132-
Set to `0` for unlimited length.
133-
Set to `null` for default, which is `0`.
134-
Does not affect `id_full`.
135+
description = <<-EOT
136+
Limit `id` to this many characters.
137+
Set to `0` for unlimited length.
138+
Set to `null` for default, which is `0`.
139+
Does not affect `id_full`.
135140
EOT
136141
}
137142

examples/complete/label6f.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module "label6f" {
44
delimiter = "~"
55
id_length_limit = 0
66

7+
# Use values from tfvars
78
context = module.this.context
89
}
910

examples/complete/label6t.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module "label6t" {
22
source = "../../"
33

4+
# Use values from tfvars,
5+
# specifically: complete.auto.tfvars
46
context = module.this.context
57
}
68

exports/context.tf

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44
# Cloud Posse's standard configuration inputs suitable for passing
55
# to Cloud Posse modules.
66
#
7+
# Modules should access the whole context as `module.this.context`
8+
# to get the input variables with nulls for defaults,
9+
# for example `context = module.this.context`,
10+
# and access individual variables as `module.this.<var>`,
11+
# with final values filled in.
12+
#
13+
# For example, when using defaults, `module.this.context.delimiter`
14+
# will be null, and `module.this.delimiter` will be `-` (hyphen).
15+
#
716
# ONLY EDIT THIS FILE IN github.com/cloudposse/terraform-null-label
817
# All other instances of this file should be a copy of that one
918
#
@@ -38,12 +47,12 @@ variable "context" {
3847
label_order = []
3948
id_length_limit = null
4049
}
41-
description = <<EOT
42-
Single object for setting entire context at once.
43-
See description of individual variables for details.
44-
Leave string and numeric variables as `null` to use default value.
45-
Individual variable settings (non-null) override settings in context object,
46-
except for attributes, tags, and additional_tag_map, which are merged.
50+
description = <<-EOT
51+
Single object for setting entire context at once.
52+
See description of individual variables for details.
53+
Leave string and numeric variables as `null` to use default value.
54+
Individual variable settings (non-null) override settings in context object,
55+
except for attributes, tags, and additional_tag_map, which are merged.
4756
EOT
4857
}
4958

@@ -80,9 +89,9 @@ variable "name" {
8089
variable "delimiter" {
8190
type = string
8291
default = null
83-
description = <<EOT
84-
Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`.
85-
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all.
92+
description = <<-EOT
93+
Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`.
94+
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all.
8695
EOT
8796
}
8897

@@ -107,30 +116,30 @@ variable "additional_tag_map" {
107116
variable "label_order" {
108117
type = list(string)
109118
default = null
110-
description = <<EOT
111-
The naming order of the id output and Name tag.
112-
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
113-
You can omit any of the 5 elements, but at least one must be present.
119+
description = <<-EOT
120+
The naming order of the id output and Name tag.
121+
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
122+
You can omit any of the 5 elements, but at least one must be present.
114123
EOT
115124
}
116125

117126
variable "regex_replace_chars" {
118127
type = string
119128
default = null
120-
description = <<EOT
121-
Regex to replace chars with empty string in `namespace`, `environment`, `stage` and `name`.
122-
If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits.
129+
description = <<-EOT
130+
Regex to replace chars with empty string in `namespace`, `environment`, `stage` and `name`.
131+
If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits.
123132
EOT
124133
}
125134

126135
variable "id_length_limit" {
127136
type = number
128137
default = null
129-
description = <<EOT
130-
Limit `id` to this many characters.
131-
Set to `0` for unlimited length.
132-
Set to `null` for default, which is `0`.
133-
Does not affect `id_full`.
138+
description = <<-EOT
139+
Limit `id` to this many characters.
140+
Set to `0` for unlimited length.
141+
Set to `null` for default, which is `0`.
142+
Does not affect `id_full`.
134143
EOT
135144
}
136145

@@ -144,7 +153,7 @@ EOT
144153
# for example, `module.this.context.enabled`
145154
#
146155
module "this" {
147-
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.19.0"
156+
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.19.1"
148157

149158
enabled = var.enabled
150159
namespace = var.namespace

main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ locals {
105105
namespace = local.namespace
106106
environment = local.environment
107107
stage = local.stage
108+
delimiter = local.delimiter
108109
attributes = local.attributes
109110
tags = local.tags
110-
delimiter = local.delimiter
111+
additional_tag_map = local.additional_tag_map
111112
label_order = local.label_order
112113
regex_replace_chars = local.regex_replace_chars
113-
additional_tag_map = local.additional_tag_map
114114
id_length_limit = local.id_length_limit
115115
}
116116

outputs.tf

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,64 @@ output "id_full" {
88
description = "Disambiguated ID not restricted in length"
99
}
1010

11-
output "name" {
12-
value = local.enabled ? local.name : ""
13-
description = "Normalized name"
11+
output "enabled" {
12+
value = local.enabled
13+
description = "True if module is enabled, false otherwise"
1414
}
1515

1616
output "namespace" {
1717
value = local.enabled ? local.namespace : ""
1818
description = "Normalized namespace"
1919
}
2020

21-
output "stage" {
22-
value = local.enabled ? local.stage : ""
23-
description = "Normalized stage"
24-
}
25-
2621
output "environment" {
2722
value = local.enabled ? local.environment : ""
2823
description = "Normalized environment"
2924
}
3025

31-
output "attributes" {
32-
value = local.enabled ? local.attributes : []
33-
description = "List of attributes"
26+
output "name" {
27+
value = local.enabled ? local.name : ""
28+
description = "Normalized name"
29+
}
30+
31+
output "stage" {
32+
value = local.enabled ? local.stage : ""
33+
description = "Normalized stage"
3434
}
3535

3636
output "delimiter" {
3737
value = local.enabled ? local.delimiter : ""
3838
description = "Delimiter between `namespace`, `environment`, `stage`, `name` and `attributes`"
3939
}
4040

41+
output "attributes" {
42+
value = local.enabled ? local.attributes : []
43+
description = "List of attributes"
44+
}
45+
4146
output "tags" {
4247
value = local.enabled ? local.tags : {}
4348
description = "Normalized Tag map"
4449
}
4550

51+
output "additional_tag_map" {
52+
value = local.additional_tag_map
53+
description = "The merged additional_tag_map"
54+
}
55+
4656
output "label_order" {
4757
value = local.label_order
48-
description = "The naming order of the id output and Name tag"
58+
description = "The naming order actually used to create the ID"
59+
}
60+
61+
output "regex_replace_chars" {
62+
value = local.regex_replace_chars
63+
description = "The regex_replace_chars actually used to create the ID"
64+
}
65+
66+
output "id_length_limit" {
67+
value = local.id_length_limit
68+
description = "The id_length_limit actually used to create the ID, with `0` meaning unlimited"
4969
}
5070

5171
output "tags_as_list_of_maps" {
@@ -60,6 +80,9 @@ output "normalized_context" {
6080

6181
output "context" {
6282
value = local.input
63-
description = "Merged but otherwise unmodified input to this module, to be use as context input to other modules."
83+
description = <<-EOT
84+
Merged but otherwise unmodified input to this module, to be used as context input to other modules.
85+
Note: this version will have null values as defaults, not the values actually used as defaults.
86+
EOT
6487
}
6588

0 commit comments

Comments
 (0)