You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Add support for context variable
* Initial prototype of concept
* format code
* Better example
* Much magic applied
* More magic applied
* fixed duplication of strings after passing context
* fixed duplication of strings after passing context
* Got the merge order for the tags correct
* Added some comments
* Removed the lower() function from the delimiter string normalisation
* More comments
* Changed to use replace() for removing whitespace in values
* Joined the attributes together
* Joined the attributes together
* Handles empty values from variables
* Updated Readme
* wrong delimiter in tags, delimiter output added (#31)
* Updated README to include the context input and output, added environment as an optional variable. Swapped out null_resource for null_data_source, which reduces some of the output noise but keeps the funtionality the same.
Copy file name to clipboardExpand all lines: README.md
+102-5Lines changed: 102 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,9 @@
7
7
8
8
Terraform module designed to generate consistent label names and tags for resources. Use `terraform-null-label` to implement a strict naming convention.
9
9
10
-
A label follows the following convention: `{namespace}-{stage}-{name}-{attributes}`. The delimiter (e.g. `-`) is interchangeable.
10
+
A label follows the following convention: `{namespace}-{environment}-{stage}-{name}-{attributes}`. The delimiter (e.g. `-`) is interchangeable.
11
+
The label items are all optional. So if you perfer the term `stage` to `environment` you can exclude environment and the label `id` will look like `{namespace}-{stage}-{name}-{attributes}`.
12
+
If attributes are excluded but `stage` and `environment` are included, `id` will look like `{namespace}-{environment}-{stage}-{name}`
11
13
12
14
It's recommended to use one `terraform-null-label` module for every unique resource of a given resource type.
13
15
For example, if you have 10 instances, there should be 10 different labels.
| context | Context of this module to pass between other modules |
359
+
| delimiter | Delimiter used in label ID |
263
360
| id | Disambiguated ID |
264
361
| name | Normalized name |
265
362
| namespace | Normalized namespace |
@@ -274,7 +371,7 @@ Available targets:
274
371
275
372
Check out these related projects.
276
373
277
-
-[terraform-terraform-label](https://github.com/cloudposse/terraform-terraform-label) - Terraform Module to define a consistent naming convention by (namespace, stage, name, [attributes])
374
+
-[terraform-terraform-label](https://github.com/cloudposse/terraform-terraform-label) - Terraform Module to define a consistent naming convention by (namespace, environment, stage, name, [attributes])
Terraform module designed to generate consistent label names and tags for resources. Use `terraform-null-label` to implement a strict naming convention.
39
39
40
-
A label follows the following convention: `{namespace}-{stage}-{name}-{attributes}`. The delimiter (e.g. `-`) is interchangeable.
40
+
A label follows the following convention: `{namespace}-{environment}-{stage}-{name}-{attributes}`. The delimiter (e.g. `-`) is interchangeable.
41
+
The label items are all optional. So if you perfer the term `stage` to `environment` you can exclude environment and the label `id` will look like `{namespace}-{stage}-{name}-{attributes}`.
42
+
If attributes are excluded but `stage` and `environment` are included, `id` will look like `{namespace}-{environment}-{stage}-{name}`
41
43
42
44
It's recommended to use one `terraform-null-label` module for every unique resource of a given resource type.
43
45
For example, if you have 10 instances, there should be 10 different labels.
@@ -239,6 +241,98 @@ usage: |-
239
241
tags = ["${module.label.tags_as_list_of_maps}"]
240
242
}
241
243
```
244
+
### Advanced Example 3 as per the [complete example](./examples/complete)
245
+
This example shows how you can pass the `context` output of one label module to the next label_module.
246
+
Allowing you to create one label that has the base set of values, and then creating every extra label
247
+
as a derivative of that.
248
+
249
+
```hcl
250
+
module "label1" {
251
+
source = "../../"
252
+
namespace = "CloudPosse"
253
+
environment = "UAT"
254
+
stage = "build"
255
+
name = "Winston Churchroom"
256
+
attributes = ["fire", "water", "earth", "air"]
257
+
258
+
tags = {
259
+
"City" = "Dublin"
260
+
"Environment" = "Private"
261
+
}
262
+
}
263
+
264
+
module "label2" {
265
+
source = "../../"
266
+
context = "${module.label1.context}"
267
+
name = "Charlie"
268
+
stage = "test"
269
+
270
+
tags = {
271
+
"City" = "London"
272
+
"Environment" = "Public"
273
+
}
274
+
}
275
+
276
+
module "label3" {
277
+
source = "../../"
278
+
name = "Starfish"
279
+
stage = "release"
280
+
281
+
tags = {
282
+
"Eat" = "Carrot"
283
+
"Animal" = "Rabbit"
284
+
}
285
+
}
286
+
```
287
+
288
+
This creates label outputs like this.
289
+
```hcl
290
+
Outputs:
291
+
label1 = {
292
+
attributes = fire-water-earth-air
293
+
id = cloudposse-uat-build-winstonchurchroom-fire-water-earth-air
294
+
name = winstonchurchroom
295
+
namespace = cloudposse
296
+
stage = build
297
+
}
298
+
label1_tags = {
299
+
City = Dublin
300
+
Environment = Private
301
+
Name = cloudposse-uat-build-winstonchurchroom-fire-water-earth-air
302
+
Namespace = cloudposse
303
+
Stage = build
304
+
}
305
+
label2 = {
306
+
attributes = fire-water-earth-air
307
+
id = cloudposse-uat-build-charlie-fire-water-earth-air
308
+
name = charlie
309
+
namespace = cloudposse
310
+
stage = build
311
+
}
312
+
label2_tags = {
313
+
City = London
314
+
Environment = Public
315
+
Name = cloudposse-uat-build-charlie-fire-water-earth-air
0 commit comments