Skip to content

Commit 5d770f4

Browse files
authored
Fix race conditions for attributes (#39)
* Fix race conditions for `attributes` * Address PR comments
1 parent efcfeeb commit 5d770f4

File tree

7 files changed

+111
-96
lines changed

7 files changed

+111
-96
lines changed

README.md

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ module "label1" {
246246
stage = "build"
247247
name = "Winston Churchroom"
248248
attributes = ["fire", "water", "earth", "air"]
249+
delimiter = "-"
249250
250251
label_order = ["name", "environment", "stage", "attributes"]
251252
@@ -256,10 +257,11 @@ module "label1" {
256257
}
257258
258259
module "label2" {
259-
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=master"
260-
context = "${module.label1.context}"
261-
name = "Charlie"
262-
stage = "test"
260+
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=master"
261+
context = "${module.label1.context}"
262+
name = "Charlie"
263+
stage = "test"
264+
delimiter = "+"
263265
264266
tags = {
265267
"City" = "London"
@@ -268,9 +270,11 @@ module "label2" {
268270
}
269271
270272
module "label3" {
271-
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=master"
272-
name = "Starfish"
273-
stage = "release"
273+
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=master"
274+
name = "Starfish"
275+
stage = "release"
276+
context = "${module.label1.context}"
277+
delimiter = "."
274278
275279
tags = {
276280
"Eat" = "Carrot"
@@ -283,14 +287,14 @@ This creates label outputs like this:
283287

284288
```hcl
285289
label1 = {
286-
attributes = fire-water-earth-air
290+
attributes = [fire water earth air]
287291
id = winstonchurchroom-uat-build-fire-water-earth-air
288292
name = winstonchurchroom
289293
namespace = cloudposse
290294
stage = build
291295
}
292296
label1_context = {
293-
attributes = [fire-water-earth-air]
297+
attributes = [fire water earth air]
294298
delimiter = [-]
295299
environment = [uat]
296300
label_order = [name environment stage attributes]
@@ -308,54 +312,55 @@ label1_tags = {
308312
Stage = build
309313
}
310314
label2 = {
311-
attributes = fire-water-earth-air
312-
id = charlie-uat-test-fire-water-earth-air
315+
attributes = [fire water earth air]
316+
id = charlie+uat+test+fire+water+earth+air
313317
name = charlie
314318
namespace = cloudposse
315319
stage = test
316320
}
317321
label2_context = {
318-
attributes = [fire-water-earth-air]
319-
delimiter = [-]
322+
attributes = [fire water earth air]
323+
delimiter = [+]
320324
environment = [uat]
321325
label_order = [name environment stage attributes]
322326
name = [charlie]
323327
namespace = [cloudposse]
324328
stage = [test]
325329
tags_keys = [City Environment Name Namespace Stage]
326-
tags_values = [London Public charlie-uat-test-fire-water-earth-air cloudposse test]
330+
tags_values = [London Public charlie+uat+test+fire+water+earth+air cloudposse test]
327331
}
328332
label2_tags = {
329333
City = London
330334
Environment = Public
331-
Name = charlie-uat-test-fire-water-earth-air
335+
Name = charlie+uat+test+fire+water+earth+air
332336
Namespace = cloudposse
333337
Stage = test
334338
}
335339
label3 = {
336-
attributes =
337-
id = release-starfish
340+
attributes = [fire water earth air]
341+
id = starfish.uat.release.fire.water.earth.air
338342
name = starfish
339-
namespace =
343+
namespace = cloudposse
340344
stage = release
341345
}
342346
label3_context = {
343-
attributes = []
344-
delimiter = [-]
345-
environment = []
346-
label_order = [namespace environment stage name attributes]
347+
attributes = [fire water earth air]
348+
delimiter = [.]
349+
environment = [uat]
350+
label_order = [name environment stage attributes]
347351
name = [starfish]
348-
namespace = []
352+
namespace = [cloudposse]
349353
stage = [release]
350-
tags_keys = [Animal Eat Environment Name Namespace Stage]
351-
tags_values = [Rabbit Carrot release-starfish release]
354+
tags_keys = [Animal City Eat Environment Name Namespace Stage]
355+
tags_values = [Rabbit Dublin Carrot uat starfish.uat.release.fire.water.earth.air cloudposse release]
352356
}
353357
label3_tags = {
354358
Animal = Rabbit
359+
City = Dublin
355360
Eat = Carrot
356-
Environment =
357-
Name = release-starfish
358-
Namespace =
361+
Environment = uat
362+
Name = starfish.uat.release.fire.water.earth.air
363+
Namespace = cloudposse
359364
Stage = release
360365
}
361366
```
@@ -383,12 +388,12 @@ Available targets:
383388
| additional_tag_map | Additional tags for appending to each tag map | map | `<map>` | no |
384389
| attributes | Additional attributes (e.g. `1`) | list | `<list>` | no |
385390
| context | Default context to use for passing state between label invocations | map | `<map>` | no |
386-
| delimiter | Delimiter to be used between `name`, `namespace`, `stage`, etc. | string | `-` | no |
391+
| delimiter | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes` | string | `-` | no |
387392
| enabled | Set to false to prevent the module from creating any resources | string | `true` | no |
388393
| environment | Environment, e.g. 'prod', 'staging', 'dev', 'pre-prod', 'UAT' | string | `` | no |
389394
| label_order | The naming order of the id output and Name tag | list | `<list>` | no |
390395
| name | Solution name, e.g. 'app' or 'jenkins' | string | `` | no |
391-
| namespace | Namespace, which could be your organization name, e.g. 'eg' or 'cp' | string | `` | no |
396+
| namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | string | `` | no |
392397
| stage | Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release' | string | `` | no |
393398
| tags | Additional tags (e.g. `map('BusinessUnit','XYZ')` | map | `<map>` | no |
394399

README.yaml

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ usage: |-
259259
stage = "build"
260260
name = "Winston Churchroom"
261261
attributes = ["fire", "water", "earth", "air"]
262+
delimiter = "-"
262263
263264
label_order = ["name", "environment", "stage", "attributes"]
264265
@@ -269,10 +270,11 @@ usage: |-
269270
}
270271
271272
module "label2" {
272-
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=master"
273-
context = "${module.label1.context}"
274-
name = "Charlie"
275-
stage = "test"
273+
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=master"
274+
context = "${module.label1.context}"
275+
name = "Charlie"
276+
stage = "test"
277+
delimiter = "+"
276278
277279
tags = {
278280
"City" = "London"
@@ -281,9 +283,11 @@ usage: |-
281283
}
282284
283285
module "label3" {
284-
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=master"
285-
name = "Starfish"
286-
stage = "release"
286+
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=master"
287+
name = "Starfish"
288+
stage = "release"
289+
context = "${module.label1.context}"
290+
delimiter = "."
287291
288292
tags = {
289293
"Eat" = "Carrot"
@@ -296,14 +300,14 @@ usage: |-
296300
297301
```hcl
298302
label1 = {
299-
attributes = fire-water-earth-air
303+
attributes = [fire water earth air]
300304
id = winstonchurchroom-uat-build-fire-water-earth-air
301305
name = winstonchurchroom
302306
namespace = cloudposse
303307
stage = build
304308
}
305309
label1_context = {
306-
attributes = [fire-water-earth-air]
310+
attributes = [fire water earth air]
307311
delimiter = [-]
308312
environment = [uat]
309313
label_order = [name environment stage attributes]
@@ -321,54 +325,55 @@ usage: |-
321325
Stage = build
322326
}
323327
label2 = {
324-
attributes = fire-water-earth-air
325-
id = charlie-uat-test-fire-water-earth-air
328+
attributes = [fire water earth air]
329+
id = charlie+uat+test+fire+water+earth+air
326330
name = charlie
327331
namespace = cloudposse
328332
stage = test
329333
}
330334
label2_context = {
331-
attributes = [fire-water-earth-air]
332-
delimiter = [-]
335+
attributes = [fire water earth air]
336+
delimiter = [+]
333337
environment = [uat]
334338
label_order = [name environment stage attributes]
335339
name = [charlie]
336340
namespace = [cloudposse]
337341
stage = [test]
338342
tags_keys = [City Environment Name Namespace Stage]
339-
tags_values = [London Public charlie-uat-test-fire-water-earth-air cloudposse test]
343+
tags_values = [London Public charlie+uat+test+fire+water+earth+air cloudposse test]
340344
}
341345
label2_tags = {
342346
City = London
343347
Environment = Public
344-
Name = charlie-uat-test-fire-water-earth-air
348+
Name = charlie+uat+test+fire+water+earth+air
345349
Namespace = cloudposse
346350
Stage = test
347351
}
348352
label3 = {
349-
attributes =
350-
id = release-starfish
353+
attributes = [fire water earth air]
354+
id = starfish.uat.release.fire.water.earth.air
351355
name = starfish
352-
namespace =
356+
namespace = cloudposse
353357
stage = release
354358
}
355359
label3_context = {
356-
attributes = []
357-
delimiter = [-]
358-
environment = []
359-
label_order = [namespace environment stage name attributes]
360+
attributes = [fire water earth air]
361+
delimiter = [.]
362+
environment = [uat]
363+
label_order = [name environment stage attributes]
360364
name = [starfish]
361-
namespace = []
365+
namespace = [cloudposse]
362366
stage = [release]
363-
tags_keys = [Animal Eat Environment Name Namespace Stage]
364-
tags_values = [Rabbit Carrot release-starfish release]
367+
tags_keys = [Animal City Eat Environment Name Namespace Stage]
368+
tags_values = [Rabbit Dublin Carrot uat starfish.uat.release.fire.water.earth.air cloudposse release]
365369
}
366370
label3_tags = {
367371
Animal = Rabbit
372+
City = Dublin
368373
Eat = Carrot
369-
Environment =
370-
Name = release-starfish
371-
Namespace =
374+
Environment = uat
375+
Name = starfish.uat.release.fire.water.earth.air
376+
Namespace = cloudposse
372377
Stage = release
373378
}
374379
```

docs/terraform.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
| additional_tag_map | Additional tags for appending to each tag map | map | `<map>` | no |
77
| attributes | Additional attributes (e.g. `1`) | list | `<list>` | no |
88
| context | Default context to use for passing state between label invocations | map | `<map>` | no |
9-
| delimiter | Delimiter to be used between `name`, `namespace`, `stage`, etc. | string | `-` | no |
9+
| delimiter | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes` | string | `-` | no |
1010
| enabled | Set to false to prevent the module from creating any resources | string | `true` | no |
1111
| environment | Environment, e.g. 'prod', 'staging', 'dev', 'pre-prod', 'UAT' | string | `` | no |
1212
| label_order | The naming order of the id output and Name tag | list | `<list>` | no |
1313
| name | Solution name, e.g. 'app' or 'jenkins' | string | `` | no |
14-
| namespace | Namespace, which could be your organization name, e.g. 'eg' or 'cp' | string | `` | no |
14+
| namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | string | `` | no |
1515
| stage | Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release' | string | `` | no |
1616
| tags | Additional tags (e.g. `map('BusinessUnit','XYZ')` | map | `<map>` | no |
1717

examples/complete/main.tf

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module "label1" {
55
stage = "build"
66
name = "Winston Churchroom"
77
attributes = ["fire", "water", "earth", "air"]
8+
delimiter = "-"
89

910
label_order = ["name", "environment", "stage", "attributes"]
1011

@@ -15,10 +16,11 @@ module "label1" {
1516
}
1617

1718
module "label2" {
18-
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=master"
19-
context = "${module.label1.context}"
20-
name = "Charlie"
21-
stage = "test"
19+
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=master"
20+
context = "${module.label1.context}"
21+
name = "Charlie"
22+
stage = "test"
23+
delimiter = "+"
2224

2325
tags = {
2426
"City" = "London"
@@ -27,9 +29,11 @@ module "label2" {
2729
}
2830

2931
module "label3" {
30-
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=master"
31-
name = "Starfish"
32-
stage = "release"
32+
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=master"
33+
name = "Starfish"
34+
stage = "release"
35+
context = "${module.label1.context}"
36+
delimiter = "."
3337

3438
tags = {
3539
"Eat" = "Carrot"

0 commit comments

Comments
 (0)