Skip to content

Commit

Permalink
Label order (cloudposse#36)
Browse files Browse the repository at this point in the history
* Added missing environment output

* Added the ability to provide a list that defines the order and values in the id output and Name tag

* Add absolute URLs to examples

* Simplify TF code

* Update README

* Update README
  • Loading branch information
Jamie-BitFlight authored and aknysh committed Aug 24, 2018
1 parent 05cad64 commit f139b6b
Show file tree
Hide file tree
Showing 13 changed files with 229 additions and 95 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export README_DEPS ?= docs/targets.md docs/terraform.md

## Lint terraform code
lint:
$(SELF) terraform/install terraform/get-modules terraform/get-plugins terraform/lint terraform/validate
$(SELF) terraform/install terraform/get-modules terraform/get-plugins terraform/lint terraform/validate
89 changes: 66 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ module "eg_prod_bastion_label" {
}
```

This will create an `id` with the value of `eg-prod-bastion-public`.
This will create an `id` with the value of `eg-prod-bastion-public` because when generating `id`, the default order is `namespace`, `environment`, `stage`, `name`, `attributes`
(you can override it by using the `label_order` variable, see [Advanced Example 3](#advanced-example-3)).

Now reference the label when creating an instance:

Expand Down Expand Up @@ -228,28 +229,34 @@ resource "aws_autoscaling_group" "default" {
tags = ["${module.label.tags_as_list_of_maps}"]
}
```
### Advanced Example 3 as per the [complete example](./examples/complete)
This example shows how you can pass the `context` output of one label module to the next label_module.
Allowing you to create one label that has the base set of values, and then creating every extra label

### Advanced Example 3

See [complete example](./examples/complete)

This example shows how you can pass the `context` output of one label module to the next label_module,
allowing you to create one label that has the base set of values, and then creating every extra label
as a derivative of that.

```hcl
module "label1" {
source = "../../"
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=master"
namespace = "CloudPosse"
environment = "UAT"
stage = "build"
name = "Winston Churchroom"
attributes = ["fire", "water", "earth", "air"]
label_order = ["name", "environment", "stage", "attributes"]
tags = {
"City" = "Dublin"
"Environment" = "Private"
}
}
module "label2" {
source = "../../"
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=master"
context = "${module.label1.context}"
name = "Charlie"
stage = "test"
Expand All @@ -261,7 +268,7 @@ module "label2" {
}
module "label3" {
source = "../../"
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=master"
name = "Starfish"
stage = "release"
Expand All @@ -272,50 +279,83 @@ module "label3" {
}
```

This creates label outputs like this.
This creates label outputs like this:

```hcl
Outputs:
label1 = {
attributes = fire-water-earth-air
id = cloudposse-uat-build-winstonchurchroom-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]
delimiter = [-]
environment = [uat]
label_order = [name environment stage attributes]
name = [winstonchurchroom]
namespace = [cloudposse]
stage = [build]
tags_keys = [City Environment Name Namespace Stage]
tags_values = [Dublin Private winstonchurchroom-uat-build-fire-water-earth-air cloudposse build]
}
label1_tags = {
City = Dublin
Environment = Private
Name = cloudposse-uat-build-winstonchurchroom-fire-water-earth-air
Name = winstonchurchroom-uat-build-fire-water-earth-air
Namespace = cloudposse
Stage = build
}
label2 = {
attributes = fire-water-earth-air
id = cloudposse-uat-build-charlie-fire-water-earth-air
id = charlie-uat-test-fire-water-earth-air
name = charlie
namespace = cloudposse
stage = build
stage = test
}
label2_context = {
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]
}
label2_tags = {
City = London
Environment = Public
Name = cloudposse-uat-build-charlie-fire-water-earth-air
Name = charlie-uat-test-fire-water-earth-air
Namespace = cloudposse
Stage = build
Stage = test
}
label3 = {
attributes =
attributes =
id = release-starfish
name = starfish
namespace =
namespace =
stage = release
}
label3_context = {
attributes = []
delimiter = [-]
environment = []
label_order = [namespace environment stage name attributes]
name = [starfish]
namespace = []
stage = [release]
tags_keys = [Animal Eat Environment Name Namespace Stage]
tags_values = [Rabbit Carrot release-starfish release]
}
label3_tags = {
Animal = Rabbit
Eat = Carrot
Environment =
Environment =
Name = release-starfish
Namespace =
Namespace =
Stage = release
}
```
Expand All @@ -329,8 +369,9 @@ label3_tags = {
```
Available targets:
help This help screen
help Help screen
help/all Display help for all targets
help/short This help short screen
lint Lint terraform code
```
Expand All @@ -339,14 +380,15 @@ Available targets:

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| additional_tag_map | Additional tags for appending to each tag map. | map | `<map>` | no |
| attributes | Additional attributes (e.g. `policy` or `role`) | list | `<list>` | no |
| 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 |
| 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. 'cp' or 'cloudposse' | string | `` | no |
| namespace | Namespace, which could be your organization name, 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 All @@ -359,6 +401,7 @@ Available targets:
| delimiter | Delimiter used in label ID |
| environment | Normalized environment |
| id | Disambiguated ID |
| label_order | The naming order of the id output and Name tag |
| name | Normalized name |
| namespace | Normalized namespace |
| stage | Normalized stage |
Expand Down
83 changes: 61 additions & 22 deletions README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ usage: |-
}
```
This will create an `id` with the value of `eg-prod-bastion-public`.
This will create an `id` with the value of `eg-prod-bastion-public` because when generating `id`, the default order is `namespace`, `environment`, `stage`, `name`, `attributes`
(you can override it by using the `label_order` variable, see [Advanced Example 3](#advanced-example-3)).
Now reference the label when creating an instance:
Expand Down Expand Up @@ -241,28 +242,34 @@ usage: |-
tags = ["${module.label.tags_as_list_of_maps}"]
}
```
### Advanced Example 3 as per the [complete example](./examples/complete)
This example shows how you can pass the `context` output of one label module to the next label_module.
Allowing you to create one label that has the base set of values, and then creating every extra label
### Advanced Example 3
See [complete example](./examples/complete)
This example shows how you can pass the `context` output of one label module to the next label_module,
allowing you to create one label that has the base set of values, and then creating every extra label
as a derivative of that.
```hcl
module "label1" {
source = "../../"
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=master"
namespace = "CloudPosse"
environment = "UAT"
stage = "build"
name = "Winston Churchroom"
attributes = ["fire", "water", "earth", "air"]
label_order = ["name", "environment", "stage", "attributes"]
tags = {
"City" = "Dublin"
"Environment" = "Private"
}
}
module "label2" {
source = "../../"
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=master"
context = "${module.label1.context}"
name = "Charlie"
stage = "test"
Expand All @@ -274,7 +281,7 @@ usage: |-
}
module "label3" {
source = "../../"
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=master"
name = "Starfish"
stage = "release"
Expand All @@ -284,56 +291,88 @@ usage: |-
}
}
```
This creates label outputs like this.
This creates label outputs like this:
```hcl
Outputs:
label1 = {
attributes = fire-water-earth-air
id = cloudposse-uat-build-winstonchurchroom-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]
delimiter = [-]
environment = [uat]
label_order = [name environment stage attributes]
name = [winstonchurchroom]
namespace = [cloudposse]
stage = [build]
tags_keys = [City Environment Name Namespace Stage]
tags_values = [Dublin Private winstonchurchroom-uat-build-fire-water-earth-air cloudposse build]
}
label1_tags = {
City = Dublin
Environment = Private
Name = cloudposse-uat-build-winstonchurchroom-fire-water-earth-air
Name = winstonchurchroom-uat-build-fire-water-earth-air
Namespace = cloudposse
Stage = build
}
label2 = {
attributes = fire-water-earth-air
id = cloudposse-uat-build-charlie-fire-water-earth-air
id = charlie-uat-test-fire-water-earth-air
name = charlie
namespace = cloudposse
stage = build
stage = test
}
label2_context = {
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]
}
label2_tags = {
City = London
Environment = Public
Name = cloudposse-uat-build-charlie-fire-water-earth-air
Name = charlie-uat-test-fire-water-earth-air
Namespace = cloudposse
Stage = build
Stage = test
}
label3 = {
attributes =
attributes =
id = release-starfish
name = starfish
namespace =
namespace =
stage = release
}
label3_context = {
attributes = []
delimiter = [-]
environment = []
label_order = [namespace environment stage name attributes]
name = [starfish]
namespace = []
stage = [release]
tags_keys = [Animal Eat Environment Name Namespace Stage]
tags_values = [Rabbit Carrot release-starfish release]
}
label3_tags = {
Animal = Rabbit
Eat = Carrot
Environment =
Environment =
Name = release-starfish
Namespace =
Namespace =
Stage = release
}
```
include:
- "docs/targets.md"
- "docs/terraform.md"
Expand All @@ -355,4 +394,4 @@ contributors:
- name: "Vladimir"
github: "SweetOps"
- name: "Daren Desjardins"
github: "darend"
github: "darend"
3 changes: 2 additions & 1 deletion docs/targets.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
```
Available targets:
help This help screen
help Help screen
help/all Display help for all targets
help/short This help short screen
lint Lint terraform code
```
Loading

0 comments on commit f139b6b

Please sign in to comment.