Skip to content

Commit 6a7c42e

Browse files
authored
feat: add support for choosing letter case of context tags (#107)
1 parent f145d2a commit 6a7c42e

File tree

19 files changed

+627
-28
lines changed

19 files changed

+627
-28
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ Available targets:
658658

659659
| Name | Version |
660660
|------|---------|
661-
| terraform | >= 0.12.26 |
661+
| terraform | >= 0.13.0 |
662662

663663
## Providers
664664

@@ -670,12 +670,14 @@ No provider.
670670
|------|-------------|------|---------|:--------:|
671671
| additional\_tag\_map | Additional tags for appending to tags\_as\_list\_of\_maps. Not added to `tags`. | `map(string)` | `{}` | no |
672672
| attributes | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no |
673-
| context | Single object for setting entire context at once.<br>See description of individual variables for details.<br>Leave string and numeric variables as `null` to use default value.<br>Individual variable settings (non-null) override settings in context object,<br>except for attributes, tags, and additional\_tag\_map, which are merged. | <pre>object({<br> enabled = bool<br> namespace = string<br> environment = string<br> stage = string<br> name = string<br> delimiter = string<br> attributes = list(string)<br> tags = map(string)<br> additional_tag_map = map(string)<br> regex_replace_chars = string<br> label_order = list(string)<br> id_length_limit = number<br> })</pre> | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "enabled": true,<br> "environment": null,<br> "id_length_limit": null,<br> "label_order": [],<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {}<br>}</pre> | no |
673+
| context | Single object for setting entire context at once.<br>See description of individual variables for details.<br>Leave string and numeric variables as `null` to use default value.<br>Individual variable settings (non-null) override settings in context object,<br>except for attributes, tags, and additional\_tag\_map, which are merged. | <pre>object({<br> enabled = bool<br> namespace = string<br> environment = string<br> stage = string<br> name = string<br> delimiter = string<br> attributes = list(string)<br> tags = map(string)<br> additional_tag_map = map(string)<br> regex_replace_chars = string<br> label_order = list(string)<br> id_length_limit = number<br> label_key_case = string<br> label_value_case = string<br> })</pre> | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "enabled": true,<br> "environment": null,<br> "id_length_limit": null,<br> "label_key_case": null,<br> "label_order": [],<br> "label_value_case": null,<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {}<br>}</pre> | no |
674674
| delimiter | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`.<br>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
675675
| enabled | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
676676
| environment | Environment, e.g. 'uw2', 'us-west-2', OR 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |
677677
| id\_length\_limit | Limit `id` to this many characters.<br>Set to `0` for unlimited length.<br>Set to `null` for default, which is `0`.<br>Does not affect `id_full`. | `number` | `null` | no |
678+
| label\_key\_case | The letter case of label keys (`tag` names) (i.e. `name`, `namespace`, `environment`, `stage`, `attributes`) to use in `tags`.<br>Possible values: `lower`, `title`, `upper`. <br>Default value: `title`. | `string` | `null` | no |
678679
| label\_order | The naming order of the id output and Name tag.<br>Defaults to ["namespace", "environment", "stage", "name", "attributes"].<br>You can omit any of the 5 elements, but at least one must be present. | `list(string)` | `null` | no |
680+
| label\_value\_case | The letter case of output label values (also used in `tags` and `id`).<br>Possible values: `lower`, `title`, `upper` and `none` (no transformation). <br>Default value: `lower`. | `string` | `null` | no |
679681
| name | Solution name, e.g. 'app' or 'jenkins' | `string` | `null` | no |
680682
| namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | `string` | `null` | no |
681683
| regex\_replace\_chars | Regex to replace chars with empty string in `namespace`, `environment`, `stage` and `name`.<br>If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no |
@@ -794,7 +796,7 @@ In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow.
794796

795797
## Copyright
796798

797-
Copyright © 2017-2020 [Cloud Posse, LLC](https://cpco.io/copyright)
799+
Copyright © 2017-2021 [Cloud Posse, LLC](https://cpco.io/copyright)
798800

799801

800802

docs/terraform.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
| Name | Version |
55
|------|---------|
6-
| terraform | >= 0.12.26 |
6+
| terraform | >= 0.13.0 |
77

88
## Providers
99

@@ -15,12 +15,14 @@ No provider.
1515
|------|-------------|------|---------|:--------:|
1616
| additional\_tag\_map | Additional tags for appending to tags\_as\_list\_of\_maps. Not added to `tags`. | `map(string)` | `{}` | no |
1717
| attributes | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no |
18-
| context | Single object for setting entire context at once.<br>See description of individual variables for details.<br>Leave string and numeric variables as `null` to use default value.<br>Individual variable settings (non-null) override settings in context object,<br>except for attributes, tags, and additional\_tag\_map, which are merged. | <pre>object({<br> enabled = bool<br> namespace = string<br> environment = string<br> stage = string<br> name = string<br> delimiter = string<br> attributes = list(string)<br> tags = map(string)<br> additional_tag_map = map(string)<br> regex_replace_chars = string<br> label_order = list(string)<br> id_length_limit = number<br> })</pre> | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "enabled": true,<br> "environment": null,<br> "id_length_limit": null,<br> "label_order": [],<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {}<br>}</pre> | no |
18+
| context | Single object for setting entire context at once.<br>See description of individual variables for details.<br>Leave string and numeric variables as `null` to use default value.<br>Individual variable settings (non-null) override settings in context object,<br>except for attributes, tags, and additional\_tag\_map, which are merged. | <pre>object({<br> enabled = bool<br> namespace = string<br> environment = string<br> stage = string<br> name = string<br> delimiter = string<br> attributes = list(string)<br> tags = map(string)<br> additional_tag_map = map(string)<br> regex_replace_chars = string<br> label_order = list(string)<br> id_length_limit = number<br> label_key_case = string<br> label_value_case = string<br> })</pre> | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "enabled": true,<br> "environment": null,<br> "id_length_limit": null,<br> "label_key_case": null,<br> "label_order": [],<br> "label_value_case": null,<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {}<br>}</pre> | no |
1919
| delimiter | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`.<br>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
2020
| enabled | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
2121
| environment | Environment, e.g. 'uw2', 'us-west-2', OR 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |
2222
| id\_length\_limit | Limit `id` to this many characters.<br>Set to `0` for unlimited length.<br>Set to `null` for default, which is `0`.<br>Does not affect `id_full`. | `number` | `null` | no |
23+
| label\_key\_case | The letter case of label keys (`tag` names) (i.e. `name`, `namespace`, `environment`, `stage`, `attributes`) to use in `tags`.<br>Possible values: `lower`, `title`, `upper`. <br>Default value: `title`. | `string` | `null` | no |
2324
| label\_order | The naming order of the id output and Name tag.<br>Defaults to ["namespace", "environment", "stage", "name", "attributes"].<br>You can omit any of the 5 elements, but at least one must be present. | `list(string)` | `null` | no |
25+
| label\_value\_case | The letter case of output label values (also used in `tags` and `id`).<br>Possible values: `lower`, `title`, `upper` and `none` (no transformation). <br>Default value: `lower`. | `string` | `null` | no |
2426
| name | Solution name, e.g. 'app' or 'jenkins' | `string` | `null` | no |
2527
| namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | `string` | `null` | no |
2628
| regex\_replace\_chars | Regex to replace chars with empty string in `namespace`, `environment`, `stage` and `name`.<br>If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no |

examples/autoscalinggroup/context.tf

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ variable "context" {
5858
regex_replace_chars = string
5959
label_order = list(string)
6060
id_length_limit = number
61+
label_key_case = string
62+
label_value_case = string
6163
})
6264
default = {
6365
enabled = true
@@ -72,6 +74,8 @@ variable "context" {
7274
regex_replace_chars = null
7375
label_order = []
7476
id_length_limit = null
77+
label_key_case = null
78+
label_value_case = null
7579
}
7680
description = <<-EOT
7781
Single object for setting entire context at once.
@@ -80,6 +84,16 @@ variable "context" {
8084
Individual variable settings (non-null) override settings in context object,
8185
except for attributes, tags, and additional_tag_map, which are merged.
8286
EOT
87+
88+
validation {
89+
condition = var.context["label_key_case"] == null ? true : contains(["lower", "title", "upper"], var.context["label_key_case"])
90+
error_message = "Allowed values: `lower`, `title`, `upper`."
91+
}
92+
93+
validation {
94+
condition = var.context["label_value_case"] == null ? true : contains(["lower", "title", "upper", "none"], var.context["label_value_case"])
95+
error_message = "Allowed values: `lower`, `title`, `upper`, `none`."
96+
}
8397
}
8498

8599
variable "enabled" {
@@ -169,4 +183,34 @@ variable "id_length_limit" {
169183
EOT
170184
}
171185

186+
variable "label_key_case" {
187+
type = string
188+
default = null
189+
description = <<-EOT
190+
The letter case of label keys (`tag` names) (i.e. `name`, `namespace`, `environment`, `stage`, `attributes`) to use in `tags`.
191+
Possible values: `lower`, `title`, `upper`.
192+
Default value: `title`.
193+
EOT
194+
195+
validation {
196+
condition = var.label_key_case == null ? true : contains(["lower", "title", "upper"], var.label_key_case)
197+
error_message = "Allowed values: `lower`, `title`, `upper`."
198+
}
199+
}
200+
201+
variable "label_value_case" {
202+
type = string
203+
default = null
204+
description = <<-EOT
205+
The letter case of output label values (also used in `tags` and `id`).
206+
Possible values: `lower`, `title`, `upper` and `none` (no transformation).
207+
Default value: `lower`.
208+
EOT
209+
210+
validation {
211+
condition = var.label_value_case == null ? true : contains(["lower", "title", "upper", "none"], var.label_value_case)
212+
error_message = "Allowed values: `lower`, `title`, `upper`, `none`."
213+
}
214+
}
215+
172216
#### End of copy of cloudposse/terraform-null-label/variables.tf
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
terraform {
2-
required_version = ">= 0.12.0"
2+
required_version = ">= 0.13.0"
33
}

examples/complete/context.tf

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ variable "context" {
5858
regex_replace_chars = string
5959
label_order = list(string)
6060
id_length_limit = number
61+
label_key_case = string
62+
label_value_case = string
6163
})
6264
default = {
6365
enabled = true
@@ -72,6 +74,8 @@ variable "context" {
7274
regex_replace_chars = null
7375
label_order = []
7476
id_length_limit = null
77+
label_key_case = null
78+
label_value_case = null
7579
}
7680
description = <<-EOT
7781
Single object for setting entire context at once.
@@ -80,6 +84,16 @@ variable "context" {
8084
Individual variable settings (non-null) override settings in context object,
8185
except for attributes, tags, and additional_tag_map, which are merged.
8286
EOT
87+
88+
validation {
89+
condition = var.context["label_key_case"] == null ? true : contains(["lower", "title", "upper"], var.context["label_key_case"])
90+
error_message = "Allowed values: `lower`, `title`, `upper`."
91+
}
92+
93+
validation {
94+
condition = var.context["label_value_case"] == null ? true : contains(["lower", "title", "upper", "none"], var.context["label_value_case"])
95+
error_message = "Allowed values: `lower`, `title`, `upper`, `none`."
96+
}
8397
}
8498

8599
variable "enabled" {
@@ -169,4 +183,34 @@ variable "id_length_limit" {
169183
EOT
170184
}
171185

186+
variable "label_key_case" {
187+
type = string
188+
default = null
189+
description = <<-EOT
190+
The letter case of label keys (`tag` names) (i.e. `name`, `namespace`, `environment`, `stage`, `attributes`) to use in `tags`.
191+
Possible values: `lower`, `title`, `upper`.
192+
Default value: `title`.
193+
EOT
194+
195+
validation {
196+
condition = var.label_key_case == null ? true : contains(["lower", "title", "upper"], var.label_key_case)
197+
error_message = "Allowed values: `lower`, `title`, `upper`."
198+
}
199+
}
200+
201+
variable "label_value_case" {
202+
type = string
203+
default = null
204+
description = <<-EOT
205+
The letter case of output label values (also used in `tags` and `id`).
206+
Possible values: `lower`, `title`, `upper` and `none` (no transformation).
207+
Default value: `lower`.
208+
EOT
209+
210+
validation {
211+
condition = var.label_value_case == null ? true : contains(["lower", "title", "upper", "none"], var.label_value_case)
212+
error_message = "Allowed values: `lower`, `title`, `upper`, `none`."
213+
}
214+
}
215+
172216
#### End of copy of cloudposse/terraform-null-label/variables.tf

examples/complete/label8d.tf

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
module "label8d" {
2+
source = "../../"
3+
4+
enabled = true
5+
namespace = "eg"
6+
environment = "demo"
7+
name = "blue"
8+
attributes = ["cluster"]
9+
delimiter = "-"
10+
11+
tags = {
12+
"kubernetes.io/cluster/" = "shared"
13+
}
14+
}
15+
16+
module "label8d_context" {
17+
source = "../../"
18+
19+
context = module.label8d.context
20+
}
21+
22+
output "label8d_context_id" {
23+
value = module.label8d_context.id
24+
}
25+
26+
output "label8d_context_context" {
27+
value = module.label8d_context.context
28+
}
29+
30+
output "label8d_context_tags" {
31+
value = module.label8d_context.tags
32+
}
33+
34+
output "label8d_id" {
35+
value = module.label8d.id
36+
}
37+
38+
output "label8d_context" {
39+
value = module.label8d.context
40+
}
41+
42+
output "label8d_tags" {
43+
value = module.label8d.tags
44+
}

examples/complete/label8dcd.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module "label8dcd" {
2+
source = "../../"
3+
4+
enabled = true
5+
namespace = "eg"
6+
environment = "demo"
7+
name = "blue"
8+
attributes = ["cluster"]
9+
delimiter = "x"
10+
}
11+
12+
module "label8dcd_context" {
13+
source = "../../"
14+
15+
context = module.label8dcd.context
16+
}
17+
18+
output "label8dcd_context_id" {
19+
value = module.label8dcd_context.id
20+
}
21+
22+
output "label8dcd_id" {
23+
value = module.label8dcd.id
24+
}

examples/complete/label8dnd.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module "label8dnd" {
2+
source = "../../"
3+
4+
enabled = true
5+
namespace = "eg"
6+
environment = "demo"
7+
name = "blue"
8+
attributes = ["cluster"]
9+
delimiter = ""
10+
}
11+
12+
module "label8dnd_context" {
13+
source = "../../"
14+
15+
context = module.label8dnd.context
16+
}
17+
18+
output "label8dnd_context_id" {
19+
value = module.label8dnd_context.id
20+
}
21+
22+
output "label8dnd_id" {
23+
value = module.label8dnd.id
24+
}

examples/complete/label8l.tf

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
module "label8l" {
2+
source = "../../"
3+
enabled = true
4+
namespace = "eg"
5+
environment = "demo"
6+
name = "blue"
7+
attributes = ["cluster"]
8+
delimiter = "-"
9+
label_key_case = "lower"
10+
label_value_case = "lower"
11+
12+
tags = {
13+
"kubernetes.io/cluster/" = "shared"
14+
"upperTEST" = "testUPPER"
15+
}
16+
}
17+
18+
module "label8l_context" {
19+
source = "../../"
20+
21+
context = module.label8l.context
22+
}
23+
24+
output "label8l_context_id" {
25+
value = module.label8l_context.id
26+
}
27+
28+
output "label8l_context_context" {
29+
value = module.label8l_context.context
30+
}
31+
32+
output "label8l_context_tags" {
33+
value = module.label8l_context.tags
34+
}
35+
36+
output "label8l_id" {
37+
value = module.label8l.id
38+
}
39+
40+
output "label8l_context" {
41+
value = module.label8l.context
42+
}
43+
44+
output "label8l_tags" {
45+
value = module.label8l.tags
46+
}

examples/complete/label8n.tf

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
module "label8n" {
2+
source = "../../"
3+
4+
enabled = true
5+
namespace = "EG"
6+
environment = "demo"
7+
name = "blue"
8+
attributes = ["eks", "ClusteR"]
9+
delimiter = "-"
10+
label_value_case = "none"
11+
12+
tags = {
13+
"kubernetes.io/cluster/" = "shared"
14+
}
15+
}
16+
17+
module "label8n_context" {
18+
source = "../../"
19+
20+
context = module.label8n.context
21+
}
22+
23+
output "label8n_context_id" {
24+
value = module.label8n_context.id
25+
}
26+
27+
output "label8n_context_context" {
28+
value = module.label8n_context.context
29+
}
30+
31+
output "label8n_context_tags" {
32+
value = module.label8n_context.tags
33+
}
34+
35+
output "label8n_id" {
36+
value = module.label8n.id
37+
}
38+
39+
output "label8n_context" {
40+
value = module.label8n.context
41+
}
42+
43+
output "label8n_tags" {
44+
value = module.label8n.tags
45+
}

0 commit comments

Comments
 (0)