Skip to content

Commit 3a7014c

Browse files
authored
Include updates to exports/context.tf (#122)
1 parent 2de8bb4 commit 3a7014c

File tree

5 files changed

+31
-32
lines changed

5 files changed

+31
-32
lines changed

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,24 @@ This module generates names using the following convention by default: `{namespa
3333
However, it is highly configurable. The delimiter (e.g. `-`) is configurable. Each label item is optional (although you must provide at least one).
3434
So if you prefer the term `stage` to `environment`
3535
you can exclude environment and the label `id` will look like `{namespace}-{stage}-{name}-{attributes}`.
36-
If attributes are excluded but `stage` and `environment` are included, `id` will look like `{namespace}-{environment}-{stage}-{name}`.
37-
If you want the attributes in a different order, you can specify that, too, with the `label_order` list.
38-
You can set a maximum length for the name, and the module will create a unique name that fits within that length.
36+
- If attributes are excluded but `namespace`, `stage`, and `environment` are included, `id` will look like `{namespace}-{environment}-{stage}-{name}`.
37+
- If you want the attributes in a different order, you can specify that, too, with the `label_order` list.
38+
- You can set a maximum length for the name, and the module will create a unique name that fits within that length.
39+
- You can control the letter case of the generated labels which make up the `id` using `var.label_value_case`.
40+
- The labels are also exported as tags. You can control the case of the tag names (keys) using `var.label_tag_case`.
3941

4042
It's recommended to use one `terraform-null-label` module for every unique resource of a given resource type.
4143
For example, if you have 10 instances, there should be 10 different labels.
4244
However, if you have multiple different kinds of resources (e.g. instances, security groups, file systems, and elastic ips), then they can all share the same label assuming they are logically related.
4345

4446
All [Cloud Posse modules](https://github.com/cloudposse?utf8=%E2%9C%93&q=terraform-&type=&language=) use this module to ensure resources can be instantiated multiple times within an account and without conflict.
4547

46-
**NOTE:** The `null` refers to the primary Terraform [provider](https://www.terraform.io/docs/providers/null/index.html) used in this module.
48+
**NOTE:** The `null` originally referred to the primary Terraform [provider](https://www.terraform.io/docs/providers/null/index.html) used in this module.
49+
With Terraform 0.12, this module no longer needs any provider, but the name was kept for continuity.
4750

48-
Releases of this module from `0.12.0` onward support `HCL2` and only work with Terraform 0.12 or newer. Releases prior to this are compatible with earlier versions of terraform like Terraform 0.11.
51+
- Releases of this module from `0.23.0` onward only work with Terraform 0.13 or newer.
52+
- Releases of this module from `0.12.0` through `0.22.1` support `HCL2` and are compatible with Terraform 0.12 or newer.
53+
- Releases of this module prior to `0.12.0` are compatible with earlier versions of terraform like Terraform 0.11.
4954

5055

5156
---
@@ -693,7 +698,7 @@ No provider.
693698
| 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 |
694699
| enabled | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
695700
| environment | Environment, e.g. 'uw2', 'us-west-2', OR 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |
696-
| 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 |
701+
| id\_length\_limit | Limit `id` to this many characters (minimum 6).<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 |
697702
| 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 |
698703
| 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 |
699704
| 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 |

README.yaml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,24 @@ description: |-
3030
However, it is highly configurable. The delimiter (e.g. `-`) is configurable. Each label item is optional (although you must provide at least one).
3131
So if you prefer the term `stage` to `environment`
3232
you can exclude environment and the label `id` will look like `{namespace}-{stage}-{name}-{attributes}`.
33-
If attributes are excluded but `stage` and `environment` are included, `id` will look like `{namespace}-{environment}-{stage}-{name}`.
34-
If you want the attributes in a different order, you can specify that, too, with the `label_order` list.
35-
You can set a maximum length for the name, and the module will create a unique name that fits within that length.
33+
- If attributes are excluded but `namespace`, `stage`, and `environment` are included, `id` will look like `{namespace}-{environment}-{stage}-{name}`.
34+
- If you want the attributes in a different order, you can specify that, too, with the `label_order` list.
35+
- You can set a maximum length for the name, and the module will create a unique name that fits within that length.
36+
- You can control the letter case of the generated labels which make up the `id` using `var.label_value_case`.
37+
- The labels are also exported as tags. You can control the case of the tag names (keys) using `var.label_tag_case`.
3638
3739
It's recommended to use one `terraform-null-label` module for every unique resource of a given resource type.
3840
For example, if you have 10 instances, there should be 10 different labels.
3941
However, if you have multiple different kinds of resources (e.g. instances, security groups, file systems, and elastic ips), then they can all share the same label assuming they are logically related.
4042
4143
All [Cloud Posse modules](https://github.com/cloudposse?utf8=%E2%9C%93&q=terraform-&type=&language=) use this module to ensure resources can be instantiated multiple times within an account and without conflict.
4244
43-
**NOTE:** The `null` refers to the primary Terraform [provider](https://www.terraform.io/docs/providers/null/index.html) used in this module.
45+
**NOTE:** The `null` originally referred to the primary Terraform [provider](https://www.terraform.io/docs/providers/null/index.html) used in this module.
46+
With Terraform 0.12, this module no longer needs any provider, but the name was kept for continuity.
4447
45-
Releases of this module from `0.12.0` onward support `HCL2` and only work with Terraform 0.12 or newer. Releases prior to this are compatible with earlier versions of terraform like Terraform 0.11.
48+
- Releases of this module from `0.23.0` onward only work with Terraform 0.13 or newer.
49+
- Releases of this module from `0.12.0` through `0.22.1` support `HCL2` and are compatible with Terraform 0.12 or newer.
50+
- Releases of this module prior to `0.12.0` are compatible with earlier versions of terraform like Terraform 0.11.
4651
usage: |-
4752
### Defaults
4853

docs/terraform.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ No provider.
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 |
22-
| 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 |
22+
| id\_length\_limit | Limit `id` to this many characters (minimum 6).<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 |
2323
| 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 |
2424
| 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 |
2525
| 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 |

exports/context.tf

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
module "this" {
2222
source = "cloudposse/label/null"
23-
version = "0.24.0" # requires Terraform >= 0.13.0
23+
version = "0.24.1" # requires Terraform >= 0.13.0
2424

2525
enabled = var.enabled
2626
namespace = var.namespace
@@ -43,22 +43,7 @@ module "this" {
4343
# Copy contents of cloudposse/terraform-null-label/variables.tf here
4444

4545
variable "context" {
46-
type = object({
47-
enabled = bool
48-
namespace = string
49-
environment = string
50-
stage = string
51-
name = string
52-
delimiter = string
53-
attributes = list(string)
54-
tags = map(string)
55-
additional_tag_map = map(string)
56-
regex_replace_chars = string
57-
label_order = list(string)
58-
id_length_limit = number
59-
label_key_case = string
60-
label_value_case = string
61-
})
46+
type = any
6247
default = {
6348
enabled = true
6449
namespace = null
@@ -84,12 +69,12 @@ variable "context" {
8469
EOT
8570

8671
validation {
87-
condition = var.context["label_key_case"] == null ? true : contains(["lower", "title", "upper"], var.context["label_key_case"])
72+
condition = lookup(var.context, "label_key_case", null) == null ? true : contains(["lower", "title", "upper"], var.context["label_key_case"])
8873
error_message = "Allowed values: `lower`, `title`, `upper`."
8974
}
9075

9176
validation {
92-
condition = var.context["label_value_case"] == null ? true : contains(["lower", "title", "upper", "none"], var.context["label_value_case"])
77+
condition = lookup(var.context, "label_value_case", null) == null ? true : contains(["lower", "title", "upper", "none"], var.context["label_value_case"])
9378
error_message = "Allowed values: `lower`, `title`, `upper`, `none`."
9479
}
9580
}

variables.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,15 @@ variable "id_length_limit" {
115115
type = number
116116
default = null
117117
description = <<-EOT
118-
Limit `id` to this many characters.
118+
Limit `id` to this many characters (minimum 6).
119119
Set to `0` for unlimited length.
120120
Set to `null` for default, which is `0`.
121121
Does not affect `id_full`.
122122
EOT
123+
validation {
124+
condition = var.id_length_limit == null ? true : var.id_length_limit >= 6 || var.id_length_limit == 0
125+
error_message = "The id_length_limit must be >= 6 if supplied (not null), or 0 for unlimited length."
126+
}
123127
}
124128

125129
variable "label_key_case" {

0 commit comments

Comments
 (0)