Skip to content

Commit

Permalink
feat: add support for choosing letter case of context tags (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
SweetOps committed Feb 1, 2021
1 parent f145d2a commit 6a7c42e
Show file tree
Hide file tree
Showing 19 changed files with 627 additions and 28 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ Available targets:

| Name | Version |
|------|---------|
| terraform | >= 0.12.26 |
| terraform | >= 0.13.0 |

## Providers

Expand All @@ -670,12 +670,14 @@ No provider.
|------|-------------|------|---------|:--------:|
| additional\_tag\_map | Additional tags for appending to tags\_as\_list\_of\_maps. Not added to `tags`. | `map(string)` | `{}` | no |
| attributes | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no |
| 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 |
| 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 |
| 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 |
| enabled | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
| environment | Environment, e.g. 'uw2', 'us-west-2', OR 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |
| 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 |
| 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 |
| 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 |
| 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 |
| name | Solution name, e.g. 'app' or 'jenkins' | `string` | `null` | no |
| namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | `string` | `null` | no |
| 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 |
Expand Down Expand Up @@ -794,7 +796,7 @@ In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow.

## Copyright

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



Expand Down
6 changes: 4 additions & 2 deletions docs/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

| Name | Version |
|------|---------|
| terraform | >= 0.12.26 |
| terraform | >= 0.13.0 |

## Providers

Expand All @@ -15,12 +15,14 @@ No provider.
|------|-------------|------|---------|:--------:|
| additional\_tag\_map | Additional tags for appending to tags\_as\_list\_of\_maps. Not added to `tags`. | `map(string)` | `{}` | no |
| attributes | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no |
| 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 |
| 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 |
| 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 |
| enabled | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
| environment | Environment, e.g. 'uw2', 'us-west-2', OR 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |
| 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 |
| 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 |
| 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 |
| 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 |
| name | Solution name, e.g. 'app' or 'jenkins' | `string` | `null` | no |
| namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | `string` | `null` | no |
| 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 |
Expand Down
44 changes: 44 additions & 0 deletions examples/autoscalinggroup/context.tf
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ variable "context" {
regex_replace_chars = string
label_order = list(string)
id_length_limit = number
label_key_case = string
label_value_case = string
})
default = {
enabled = true
Expand All @@ -72,6 +74,8 @@ variable "context" {
regex_replace_chars = null
label_order = []
id_length_limit = null
label_key_case = null
label_value_case = null
}
description = <<-EOT
Single object for setting entire context at once.
Expand All @@ -80,6 +84,16 @@ variable "context" {
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional_tag_map, which are merged.
EOT

validation {
condition = var.context["label_key_case"] == null ? true : contains(["lower", "title", "upper"], var.context["label_key_case"])
error_message = "Allowed values: `lower`, `title`, `upper`."
}

validation {
condition = var.context["label_value_case"] == null ? true : contains(["lower", "title", "upper", "none"], var.context["label_value_case"])
error_message = "Allowed values: `lower`, `title`, `upper`, `none`."
}
}

variable "enabled" {
Expand Down Expand Up @@ -169,4 +183,34 @@ variable "id_length_limit" {
EOT
}

variable "label_key_case" {
type = string
default = null
description = <<-EOT
The letter case of label keys (`tag` names) (i.e. `name`, `namespace`, `environment`, `stage`, `attributes`) to use in `tags`.
Possible values: `lower`, `title`, `upper`.
Default value: `title`.
EOT

validation {
condition = var.label_key_case == null ? true : contains(["lower", "title", "upper"], var.label_key_case)
error_message = "Allowed values: `lower`, `title`, `upper`."
}
}

variable "label_value_case" {
type = string
default = null
description = <<-EOT
The letter case of output label values (also used in `tags` and `id`).
Possible values: `lower`, `title`, `upper` and `none` (no transformation).
Default value: `lower`.
EOT

validation {
condition = var.label_value_case == null ? true : contains(["lower", "title", "upper", "none"], var.label_value_case)
error_message = "Allowed values: `lower`, `title`, `upper`, `none`."
}
}

#### End of copy of cloudposse/terraform-null-label/variables.tf
2 changes: 1 addition & 1 deletion examples/autoscalinggroup/versions.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
terraform {
required_version = ">= 0.12.0"
required_version = ">= 0.13.0"
}
44 changes: 44 additions & 0 deletions examples/complete/context.tf
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ variable "context" {
regex_replace_chars = string
label_order = list(string)
id_length_limit = number
label_key_case = string
label_value_case = string
})
default = {
enabled = true
Expand All @@ -72,6 +74,8 @@ variable "context" {
regex_replace_chars = null
label_order = []
id_length_limit = null
label_key_case = null
label_value_case = null
}
description = <<-EOT
Single object for setting entire context at once.
Expand All @@ -80,6 +84,16 @@ variable "context" {
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional_tag_map, which are merged.
EOT

validation {
condition = var.context["label_key_case"] == null ? true : contains(["lower", "title", "upper"], var.context["label_key_case"])
error_message = "Allowed values: `lower`, `title`, `upper`."
}

validation {
condition = var.context["label_value_case"] == null ? true : contains(["lower", "title", "upper", "none"], var.context["label_value_case"])
error_message = "Allowed values: `lower`, `title`, `upper`, `none`."
}
}

variable "enabled" {
Expand Down Expand Up @@ -169,4 +183,34 @@ variable "id_length_limit" {
EOT
}

variable "label_key_case" {
type = string
default = null
description = <<-EOT
The letter case of label keys (`tag` names) (i.e. `name`, `namespace`, `environment`, `stage`, `attributes`) to use in `tags`.
Possible values: `lower`, `title`, `upper`.
Default value: `title`.
EOT

validation {
condition = var.label_key_case == null ? true : contains(["lower", "title", "upper"], var.label_key_case)
error_message = "Allowed values: `lower`, `title`, `upper`."
}
}

variable "label_value_case" {
type = string
default = null
description = <<-EOT
The letter case of output label values (also used in `tags` and `id`).
Possible values: `lower`, `title`, `upper` and `none` (no transformation).
Default value: `lower`.
EOT

validation {
condition = var.label_value_case == null ? true : contains(["lower", "title", "upper", "none"], var.label_value_case)
error_message = "Allowed values: `lower`, `title`, `upper`, `none`."
}
}

#### End of copy of cloudposse/terraform-null-label/variables.tf
44 changes: 44 additions & 0 deletions examples/complete/label8d.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module "label8d" {
source = "../../"

enabled = true
namespace = "eg"
environment = "demo"
name = "blue"
attributes = ["cluster"]
delimiter = "-"

tags = {
"kubernetes.io/cluster/" = "shared"
}
}

module "label8d_context" {
source = "../../"

context = module.label8d.context
}

output "label8d_context_id" {
value = module.label8d_context.id
}

output "label8d_context_context" {
value = module.label8d_context.context
}

output "label8d_context_tags" {
value = module.label8d_context.tags
}

output "label8d_id" {
value = module.label8d.id
}

output "label8d_context" {
value = module.label8d.context
}

output "label8d_tags" {
value = module.label8d.tags
}
24 changes: 24 additions & 0 deletions examples/complete/label8dcd.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module "label8dcd" {
source = "../../"

enabled = true
namespace = "eg"
environment = "demo"
name = "blue"
attributes = ["cluster"]
delimiter = "x"
}

module "label8dcd_context" {
source = "../../"

context = module.label8dcd.context
}

output "label8dcd_context_id" {
value = module.label8dcd_context.id
}

output "label8dcd_id" {
value = module.label8dcd.id
}
24 changes: 24 additions & 0 deletions examples/complete/label8dnd.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module "label8dnd" {
source = "../../"

enabled = true
namespace = "eg"
environment = "demo"
name = "blue"
attributes = ["cluster"]
delimiter = ""
}

module "label8dnd_context" {
source = "../../"

context = module.label8dnd.context
}

output "label8dnd_context_id" {
value = module.label8dnd_context.id
}

output "label8dnd_id" {
value = module.label8dnd.id
}
46 changes: 46 additions & 0 deletions examples/complete/label8l.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module "label8l" {
source = "../../"
enabled = true
namespace = "eg"
environment = "demo"
name = "blue"
attributes = ["cluster"]
delimiter = "-"
label_key_case = "lower"
label_value_case = "lower"

tags = {
"kubernetes.io/cluster/" = "shared"
"upperTEST" = "testUPPER"
}
}

module "label8l_context" {
source = "../../"

context = module.label8l.context
}

output "label8l_context_id" {
value = module.label8l_context.id
}

output "label8l_context_context" {
value = module.label8l_context.context
}

output "label8l_context_tags" {
value = module.label8l_context.tags
}

output "label8l_id" {
value = module.label8l.id
}

output "label8l_context" {
value = module.label8l.context
}

output "label8l_tags" {
value = module.label8l.tags
}
45 changes: 45 additions & 0 deletions examples/complete/label8n.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module "label8n" {
source = "../../"

enabled = true
namespace = "EG"
environment = "demo"
name = "blue"
attributes = ["eks", "ClusteR"]
delimiter = "-"
label_value_case = "none"

tags = {
"kubernetes.io/cluster/" = "shared"
}
}

module "label8n_context" {
source = "../../"

context = module.label8n.context
}

output "label8n_context_id" {
value = module.label8n_context.id
}

output "label8n_context_context" {
value = module.label8n_context.context
}

output "label8n_context_tags" {
value = module.label8n_context.tags
}

output "label8n_id" {
value = module.label8n.id
}

output "label8n_context" {
value = module.label8n.context
}

output "label8n_tags" {
value = module.label8n.tags
}

0 comments on commit 6a7c42e

Please sign in to comment.