Skip to content

Commit

Permalink
Fix race conditions for attributes (#39)
Browse files Browse the repository at this point in the history
* Fix race conditions for `attributes`

* Address PR comments
  • Loading branch information
aknysh authored Sep 5, 2018
1 parent efcfeeb commit 5d770f4
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 96 deletions.
65 changes: 35 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ module "label1" {
stage = "build"
name = "Winston Churchroom"
attributes = ["fire", "water", "earth", "air"]
delimiter = "-"
label_order = ["name", "environment", "stage", "attributes"]
Expand All @@ -256,10 +257,11 @@ module "label1" {
}
module "label2" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=master"
context = "${module.label1.context}"
name = "Charlie"
stage = "test"
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=master"
context = "${module.label1.context}"
name = "Charlie"
stage = "test"
delimiter = "+"
tags = {
"City" = "London"
Expand All @@ -268,9 +270,11 @@ module "label2" {
}
module "label3" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=master"
name = "Starfish"
stage = "release"
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=master"
name = "Starfish"
stage = "release"
context = "${module.label1.context}"
delimiter = "."
tags = {
"Eat" = "Carrot"
Expand All @@ -283,14 +287,14 @@ This creates label outputs like this:

```hcl
label1 = {
attributes = fire-water-earth-air
attributes = [fire water earth air]
id = winstonchurchroom-uat-build-fire-water-earth-air
name = winstonchurchroom
namespace = cloudposse
stage = build
}
label1_context = {
attributes = [fire-water-earth-air]
attributes = [fire water earth air]
delimiter = [-]
environment = [uat]
label_order = [name environment stage attributes]
Expand All @@ -308,54 +312,55 @@ label1_tags = {
Stage = build
}
label2 = {
attributes = fire-water-earth-air
id = charlie-uat-test-fire-water-earth-air
attributes = [fire water earth air]
id = charlie+uat+test+fire+water+earth+air
name = charlie
namespace = cloudposse
stage = test
}
label2_context = {
attributes = [fire-water-earth-air]
delimiter = [-]
attributes = [fire water earth air]
delimiter = [+]
environment = [uat]
label_order = [name environment stage attributes]
name = [charlie]
namespace = [cloudposse]
stage = [test]
tags_keys = [City Environment Name Namespace Stage]
tags_values = [London Public charlie-uat-test-fire-water-earth-air cloudposse test]
tags_values = [London Public charlie+uat+test+fire+water+earth+air cloudposse test]
}
label2_tags = {
City = London
Environment = Public
Name = charlie-uat-test-fire-water-earth-air
Name = charlie+uat+test+fire+water+earth+air
Namespace = cloudposse
Stage = test
}
label3 = {
attributes =
id = release-starfish
attributes = [fire water earth air]
id = starfish.uat.release.fire.water.earth.air
name = starfish
namespace =
namespace = cloudposse
stage = release
}
label3_context = {
attributes = []
delimiter = [-]
environment = []
label_order = [namespace environment stage name attributes]
attributes = [fire water earth air]
delimiter = [.]
environment = [uat]
label_order = [name environment stage attributes]
name = [starfish]
namespace = []
namespace = [cloudposse]
stage = [release]
tags_keys = [Animal Eat Environment Name Namespace Stage]
tags_values = [Rabbit Carrot release-starfish release]
tags_keys = [Animal City Eat Environment Name Namespace Stage]
tags_values = [Rabbit Dublin Carrot uat starfish.uat.release.fire.water.earth.air cloudposse release]
}
label3_tags = {
Animal = Rabbit
City = Dublin
Eat = Carrot
Environment =
Name = release-starfish
Namespace =
Environment = uat
Name = starfish.uat.release.fire.water.earth.air
Namespace = cloudposse
Stage = release
}
```
Expand Down Expand Up @@ -383,12 +388,12 @@ Available targets:
| additional_tag_map | Additional tags for appending to each tag map | map | `<map>` | no |
| attributes | Additional attributes (e.g. `1`) | list | `<list>` | no |
| context | Default context to use for passing state between label invocations | map | `<map>` | no |
| delimiter | Delimiter to be used between `name`, `namespace`, `stage`, etc. | string | `-` | no |
| delimiter | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes` | string | `-` | no |
| enabled | Set to false to prevent the module from creating any resources | string | `true` | no |
| environment | Environment, e.g. 'prod', 'staging', 'dev', 'pre-prod', 'UAT' | string | `` | no |
| label_order | The naming order of the id output and Name tag | list | `<list>` | no |
| name | Solution name, e.g. 'app' or 'jenkins' | string | `` | no |
| namespace | Namespace, which could be your organization name, e.g. 'eg' or 'cp' | string | `` | no |
| namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | string | `` | no |
| stage | Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release' | string | `` | no |
| tags | Additional tags (e.g. `map('BusinessUnit','XYZ')` | map | `<map>` | no |

Expand Down
61 changes: 33 additions & 28 deletions README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ usage: |-
stage = "build"
name = "Winston Churchroom"
attributes = ["fire", "water", "earth", "air"]
delimiter = "-"
label_order = ["name", "environment", "stage", "attributes"]
Expand All @@ -269,10 +270,11 @@ usage: |-
}
module "label2" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=master"
context = "${module.label1.context}"
name = "Charlie"
stage = "test"
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=master"
context = "${module.label1.context}"
name = "Charlie"
stage = "test"
delimiter = "+"
tags = {
"City" = "London"
Expand All @@ -281,9 +283,11 @@ usage: |-
}
module "label3" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=master"
name = "Starfish"
stage = "release"
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=master"
name = "Starfish"
stage = "release"
context = "${module.label1.context}"
delimiter = "."
tags = {
"Eat" = "Carrot"
Expand All @@ -296,14 +300,14 @@ usage: |-
```hcl
label1 = {
attributes = fire-water-earth-air
attributes = [fire water earth air]
id = winstonchurchroom-uat-build-fire-water-earth-air
name = winstonchurchroom
namespace = cloudposse
stage = build
}
label1_context = {
attributes = [fire-water-earth-air]
attributes = [fire water earth air]
delimiter = [-]
environment = [uat]
label_order = [name environment stage attributes]
Expand All @@ -321,54 +325,55 @@ usage: |-
Stage = build
}
label2 = {
attributes = fire-water-earth-air
id = charlie-uat-test-fire-water-earth-air
attributes = [fire water earth air]
id = charlie+uat+test+fire+water+earth+air
name = charlie
namespace = cloudposse
stage = test
}
label2_context = {
attributes = [fire-water-earth-air]
delimiter = [-]
attributes = [fire water earth air]
delimiter = [+]
environment = [uat]
label_order = [name environment stage attributes]
name = [charlie]
namespace = [cloudposse]
stage = [test]
tags_keys = [City Environment Name Namespace Stage]
tags_values = [London Public charlie-uat-test-fire-water-earth-air cloudposse test]
tags_values = [London Public charlie+uat+test+fire+water+earth+air cloudposse test]
}
label2_tags = {
City = London
Environment = Public
Name = charlie-uat-test-fire-water-earth-air
Name = charlie+uat+test+fire+water+earth+air
Namespace = cloudposse
Stage = test
}
label3 = {
attributes =
id = release-starfish
attributes = [fire water earth air]
id = starfish.uat.release.fire.water.earth.air
name = starfish
namespace =
namespace = cloudposse
stage = release
}
label3_context = {
attributes = []
delimiter = [-]
environment = []
label_order = [namespace environment stage name attributes]
attributes = [fire water earth air]
delimiter = [.]
environment = [uat]
label_order = [name environment stage attributes]
name = [starfish]
namespace = []
namespace = [cloudposse]
stage = [release]
tags_keys = [Animal Eat Environment Name Namespace Stage]
tags_values = [Rabbit Carrot release-starfish release]
tags_keys = [Animal City Eat Environment Name Namespace Stage]
tags_values = [Rabbit Dublin Carrot uat starfish.uat.release.fire.water.earth.air cloudposse release]
}
label3_tags = {
Animal = Rabbit
City = Dublin
Eat = Carrot
Environment =
Name = release-starfish
Namespace =
Environment = uat
Name = starfish.uat.release.fire.water.earth.air
Namespace = cloudposse
Stage = release
}
```
Expand Down
4 changes: 2 additions & 2 deletions docs/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
| additional_tag_map | Additional tags for appending to each tag map | map | `<map>` | no |
| attributes | Additional attributes (e.g. `1`) | list | `<list>` | no |
| context | Default context to use for passing state between label invocations | map | `<map>` | no |
| delimiter | Delimiter to be used between `name`, `namespace`, `stage`, etc. | string | `-` | no |
| delimiter | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes` | string | `-` | no |
| enabled | Set to false to prevent the module from creating any resources | string | `true` | no |
| environment | Environment, e.g. 'prod', 'staging', 'dev', 'pre-prod', 'UAT' | string | `` | no |
| label_order | The naming order of the id output and Name tag | list | `<list>` | no |
| name | Solution name, e.g. 'app' or 'jenkins' | string | `` | no |
| namespace | Namespace, which could be your organization name, e.g. 'eg' or 'cp' | string | `` | no |
| namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | string | `` | no |
| stage | Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release' | string | `` | no |
| tags | Additional tags (e.g. `map('BusinessUnit','XYZ')` | map | `<map>` | no |

Expand Down
18 changes: 11 additions & 7 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module "label1" {
stage = "build"
name = "Winston Churchroom"
attributes = ["fire", "water", "earth", "air"]
delimiter = "-"

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

Expand All @@ -15,10 +16,11 @@ module "label1" {
}

module "label2" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=master"
context = "${module.label1.context}"
name = "Charlie"
stage = "test"
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=master"
context = "${module.label1.context}"
name = "Charlie"
stage = "test"
delimiter = "+"

tags = {
"City" = "London"
Expand All @@ -27,9 +29,11 @@ module "label2" {
}

module "label3" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=master"
name = "Starfish"
stage = "release"
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=master"
name = "Starfish"
stage = "release"
context = "${module.label1.context}"
delimiter = "."

tags = {
"Eat" = "Carrot"
Expand Down
Loading

0 comments on commit 5d770f4

Please sign in to comment.