Skip to content

Commit 7e4fa06

Browse files
authored
build: bump null-label to 0.25 (#9)
1 parent 5333436 commit 7e4fa06

File tree

8 files changed

+243
-38
lines changed

8 files changed

+243
-38
lines changed

.github/workflows/docs.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
# blocked by https://github.com/terraform-docs/gh-actions/pull/46
3+
# name: Generate terraform docs
4+
# on:
5+
# pull_request:
6+
7+
# jobs:
8+
# docs:
9+
# runs-on: ubuntu-latest
10+
# steps:
11+
# - uses: actions/checkout@v2
12+
# with:
13+
# ref: ${{ github.event.pull_request.head.ref }}
14+
15+
# - name: Render terraform docs inside the examples/basic/README.md
16+
# uses: terraform-docs/[email protected]
17+
# with:
18+
# working-dir: ./examples/basic/
19+
# git-push: "false"
20+
# config-file: ".terraform-docs.yml"
21+
22+
# - name: Render terraform docs inside the README.md
23+
# uses: terraform-docs/[email protected]
24+
# with:
25+
# working-dir: .
26+
# git-push: "true"
27+
# config-file: ".terraform-docs.yml"
28+

.github/workflows/pr-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
pull_request_target:
55

66
jobs:
7-
main:
7+
lint-pr:
88
runs-on: ubuntu-latest
99

1010
steps:

.terraform-docs.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
formatter: markdown
2+
3+
output:
4+
file: README.md
5+
mode: replace
6+
template: |-
7+
## Usage
8+
9+
```hcl
10+
module "your_aweasome_resource" {
11+
source = ""
12+
namespace = "sweetops"
13+
stage = "production"
14+
name = "aweasome"
15+
}
16+
```
17+
18+
<!-- BEGIN_TF_DOCS -->
19+
{{ .Content }}
20+
<!-- END_TF_DOCS -->
21+
22+
## License
23+
The Apache-2.0 license
24+
25+
sort:
26+
enabled: true
27+
by: required
28+
29+
settings:
30+
anchor: true
31+
color: true
32+
default: true
33+
description: false
34+
escape: true
35+
hide-empty: false
36+
html: true
37+
indent: 2
38+
lockfile: true
39+
required: true
40+
sensitive: true
41+
type: true

README.md

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
# terraform-module-template
2-
![](https://github.com/actions/hello-world/workflows/.github/workflows/main.yml/badge.svg)
3-
4-
Terraform module for creation **CHAMGE_ME** with normalized name and tags.
5-
61
## Usage
72

83
```hcl
@@ -14,10 +9,54 @@ module "your_aweasome_resource" {
149
}
1510
```
1611

17-
<!--- BEGIN_TF_DOCS --->
18-
Error: no lines in file
12+
<!-- BEGIN_TF_DOCS -->
13+
## Requirements
14+
15+
| Name | Version |
16+
|------|---------|
17+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
18+
19+
## Providers
20+
21+
No providers.
22+
23+
## Modules
24+
25+
| Name | Source | Version |
26+
|------|--------|---------|
27+
| <a name="module_this"></a> [this](#module\_this) | cloudposse/label/null | 0.25.0 |
28+
29+
## Resources
30+
31+
No resources.
32+
33+
## Inputs
34+
35+
| Name | Description | Type | Default | Required |
36+
|------|-------------|------|---------|:--------:|
37+
| <a name="input_additional_tag_map"></a> [additional\_tag\_map](#input\_additional\_tag\_map) | Additional key-value pairs to add to each map in `tags_as_list_of_maps`. Not added to `tags` or `id`.<br>This is for some rare cases where resources want additional configuration of tags<br>and therefore take a list of maps with tag key, value, and additional configuration. | `map(string)` | `{}` | no |
38+
| <a name="input_attributes"></a> [attributes](#input\_attributes) | ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,<br>in the order they appear in the list. New attributes are appended to the<br>end of the list. The elements of the list are joined by the `delimiter`<br>and treated as a single ID element. | `list(string)` | `[]` | no |
39+
| <a name="input_context"></a> [context](#input\_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. | `any` | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "descriptor_formats": {},<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> "labels_as_tags": [<br> "unset"<br> ],<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {},<br> "tenant": null<br>}</pre> | no |
40+
| <a name="input_delimiter"></a> [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.<br>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
41+
| <a name="input_descriptor_formats"></a> [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.<br>Map of maps. Keys are names of descriptors. Values are maps of the form<br>`{<br> format = string<br> labels = list(string)<br>}`<br>(Type is `any` so the map values can later be enhanced to provide additional options.)<br>`format` is a Terraform format string to be passed to the `format()` function.<br>`labels` is a list of labels, in order, to pass to `format()` function.<br>Label values will be normalized before being passed to `format()` so they will be<br>identical to how they appear in `id`.<br>Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no |
42+
| <a name="input_enabled"></a> [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
43+
| <a name="input_environment"></a> [environment](#input\_environment) | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |
44+
| <a name="input_id_length_limit"></a> [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6).<br>Set to `0` for unlimited length.<br>Set to `null` for keep the existing setting, which defaults to `0`.<br>Does not affect `id_full`. | `number` | `null` | no |
45+
| <a name="input_label_key_case"></a> [label\_key\_case](#input\_label\_key\_case) | Controls the letter case of the `tags` keys (label names) for tags generated by this module.<br>Does not affect keys of tags passed in via the `tags` input.<br>Possible values: `lower`, `title`, `upper`.<br>Default value: `title`. | `string` | `null` | no |
46+
| <a name="input_label_order"></a> [label\_order](#input\_label\_order) | The order in which the labels (ID elements) appear in the `id`.<br>Defaults to ["namespace", "environment", "stage", "name", "attributes"].<br>You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present. | `list(string)` | `null` | no |
47+
| <a name="input_label_value_case"></a> [label\_value\_case](#input\_label\_value\_case) | Controls the letter case of ID elements (labels) as included in `id`,<br>set as tag values, and output by this module individually.<br>Does not affect values of tags passed in via the `tags` input.<br>Possible values: `lower`, `title`, `upper` and `none` (no transformation).<br>Set this to `title` and set `delimiter` to `""` to yield Pascal Case IDs.<br>Default value: `lower`. | `string` | `null` | no |
48+
| <a name="input_labels_as_tags"></a> [labels\_as\_tags](#input\_labels\_as\_tags) | Set of labels (ID elements) to include as tags in the `tags` output.<br>Default is to include all labels.<br>Tags with empty values will not be included in the `tags` output.<br>Set to `[]` to suppress all generated tags.<br>**Notes:**<br> The value of the `name` tag, if included, will be the `id`, not the `name`.<br> Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be<br> changed in later chained modules. Attempts to change it will be silently ignored. | `set(string)` | <pre>[<br> "default"<br>]</pre> | no |
49+
| <a name="input_name"></a> [name](#input\_name) | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.<br>This is the only ID element not also included as a `tag`.<br>The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input. | `string` | `null` | no |
50+
| <a name="input_namespace"></a> [namespace](#input\_namespace) | ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique | `string` | `null` | no |
51+
| <a name="input_regex_replace_chars"></a> [regex\_replace\_chars](#input\_regex\_replace\_chars) | Terraform regular expression (regex) string.<br>Characters matching the regex will be removed from the ID elements.<br>If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no |
52+
| <a name="input_stage"></a> [stage](#input\_stage) | ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no |
53+
| <a name="input_tags"></a> [tags](#input\_tags) | Additional tags (e.g. `{'BusinessUnit': 'XYZ'}`).<br>Neither the tag keys nor the tag values will be modified by this module. | `map(string)` | `{}` | no |
54+
| <a name="input_tenant"></a> [tenant](#input\_tenant) | ID element \_(Rarely used, not included by default)\_. A customer identifier, indicating who this instance of a resource is for | `string` | `null` | no |
55+
56+
## Outputs
1957

20-
<!--- END_TF_DOCS --->
58+
No outputs.
59+
<!-- END_TF_DOCS -->
2160

2261
## License
23-
The Apache-2.0 license
62+
The Apache-2.0 license

context.tf

Lines changed: 94 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
# Cloud Posse's standard configuration inputs suitable for passing
99
# to Cloud Posse modules.
1010
#
11+
# curl -sL https://raw.githubusercontent.com/cloudposse/terraform-null-label/master/exports/context.tf -o context.tf
12+
#
1113
# Modules should access the whole context as `module.this.context`
1214
# to get the input variables with nulls for defaults,
1315
# for example `context = module.this.context`,
@@ -20,10 +22,11 @@
2022

2123
module "this" {
2224
source = "cloudposse/label/null"
23-
version = "0.24.1" # requires Terraform >= 0.13.0
25+
version = "0.25.0" # requires Terraform >= 0.13.0
2426

2527
enabled = var.enabled
2628
namespace = var.namespace
29+
tenant = var.tenant
2730
environment = var.environment
2831
stage = var.stage
2932
name = var.name
@@ -36,6 +39,8 @@ module "this" {
3639
id_length_limit = var.id_length_limit
3740
label_key_case = var.label_key_case
3841
label_value_case = var.label_value_case
42+
descriptor_formats = var.descriptor_formats
43+
labels_as_tags = var.labels_as_tags
3944

4045
context = var.context
4146
}
@@ -47,6 +52,7 @@ variable "context" {
4752
default = {
4853
enabled = true
4954
namespace = null
55+
tenant = null
5056
environment = null
5157
stage = null
5258
name = null
@@ -59,6 +65,15 @@ variable "context" {
5965
id_length_limit = null
6066
label_key_case = null
6167
label_value_case = null
68+
descriptor_formats = {}
69+
# Note: we have to use [] instead of null for unset lists due to
70+
# https://github.com/hashicorp/terraform/issues/28137
71+
# which was not fixed until Terraform 1.0.0,
72+
# but we want the default to be all the labels in `label_order`
73+
# and we want users to be able to prevent all tag generation
74+
# by setting `labels_as_tags` to `[]`, so we need
75+
# a different sentinel to indicate "default"
76+
labels_as_tags = ["unset"]
6277
}
6378
description = <<-EOT
6479
Single object for setting entire context at once.
@@ -88,69 +103,107 @@ variable "enabled" {
88103
variable "namespace" {
89104
type = string
90105
default = null
91-
description = "Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp'"
106+
description = "ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique"
107+
}
108+
109+
variable "tenant" {
110+
type = string
111+
default = null
112+
description = "ID element _(Rarely used, not included by default)_. A customer identifier, indicating who this instance of a resource is for"
92113
}
93114

94115
variable "environment" {
95116
type = string
96117
default = null
97-
description = "Environment, e.g. 'uw2', 'us-west-2', OR 'prod', 'staging', 'dev', 'UAT'"
118+
description = "ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT'"
98119
}
99120

100121
variable "stage" {
101122
type = string
102123
default = null
103-
description = "Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release'"
124+
description = "ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release'"
104125
}
105126

106127
variable "name" {
107128
type = string
108129
default = null
109-
description = "Solution name, e.g. 'app' or 'jenkins'"
130+
description = <<-EOT
131+
ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.
132+
This is the only ID element not also included as a `tag`.
133+
The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input.
134+
EOT
110135
}
111136

112137
variable "delimiter" {
113138
type = string
114139
default = null
115140
description = <<-EOT
116-
Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`.
141+
Delimiter to be used between ID elements.
117142
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all.
118143
EOT
119144
}
120145

121146
variable "attributes" {
122147
type = list(string)
123148
default = []
124-
description = "Additional attributes (e.g. `1`)"
149+
description = <<-EOT
150+
ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,
151+
in the order they appear in the list. New attributes are appended to the
152+
end of the list. The elements of the list are joined by the `delimiter`
153+
and treated as a single ID element.
154+
EOT
155+
}
156+
157+
variable "labels_as_tags" {
158+
type = set(string)
159+
default = ["default"]
160+
description = <<-EOT
161+
Set of labels (ID elements) to include as tags in the `tags` output.
162+
Default is to include all labels.
163+
Tags with empty values will not be included in the `tags` output.
164+
Set to `[]` to suppress all generated tags.
165+
**Notes:**
166+
The value of the `name` tag, if included, will be the `id`, not the `name`.
167+
Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be
168+
changed in later chained modules. Attempts to change it will be silently ignored.
169+
EOT
125170
}
126171

127172
variable "tags" {
128173
type = map(string)
129174
default = {}
130-
description = "Additional tags (e.g. `map('BusinessUnit','XYZ')`"
175+
description = <<-EOT
176+
Additional tags (e.g. `{'BusinessUnit': 'XYZ'}`).
177+
Neither the tag keys nor the tag values will be modified by this module.
178+
EOT
131179
}
132180

133181
variable "additional_tag_map" {
134182
type = map(string)
135183
default = {}
136-
description = "Additional tags for appending to tags_as_list_of_maps. Not added to `tags`."
184+
description = <<-EOT
185+
Additional key-value pairs to add to each map in `tags_as_list_of_maps`. Not added to `tags` or `id`.
186+
This is for some rare cases where resources want additional configuration of tags
187+
and therefore take a list of maps with tag key, value, and additional configuration.
188+
EOT
137189
}
138190

139191
variable "label_order" {
140192
type = list(string)
141193
default = null
142194
description = <<-EOT
143-
The naming order of the id output and Name tag.
195+
The order in which the labels (ID elements) appear in the `id`.
144196
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
145-
You can omit any of the 5 elements, but at least one must be present.
146-
EOT
197+
You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present.
198+
EOT
147199
}
148200

149201
variable "regex_replace_chars" {
150202
type = string
151203
default = null
152204
description = <<-EOT
153-
Regex to replace chars with empty string in `namespace`, `environment`, `stage` and `name`.
205+
Terraform regular expression (regex) string.
206+
Characters matching the regex will be removed from the ID elements.
154207
If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits.
155208
EOT
156209
}
@@ -161,7 +214,7 @@ variable "id_length_limit" {
161214
description = <<-EOT
162215
Limit `id` to this many characters (minimum 6).
163216
Set to `0` for unlimited length.
164-
Set to `null` for default, which is `0`.
217+
Set to `null` for keep the existing setting, which defaults to `0`.
165218
Does not affect `id_full`.
166219
EOT
167220
validation {
@@ -172,9 +225,10 @@ variable "id_length_limit" {
172225

173226
variable "label_key_case" {
174227
type = string
175-
default = "lower"
228+
default = null
176229
description = <<-EOT
177-
The letter case of label keys (`tag` names) (i.e. `name`, `namespace`, `environment`, `stage`, `attributes`) to use in `tags`.
230+
Controls the letter case of the `tags` keys (label names) for tags generated by this module.
231+
Does not affect keys of tags passed in via the `tags` input.
178232
Possible values: `lower`, `title`, `upper`.
179233
Default value: `title`.
180234
EOT
@@ -189,8 +243,11 @@ variable "label_value_case" {
189243
type = string
190244
default = null
191245
description = <<-EOT
192-
The letter case of output label values (also used in `tags` and `id`).
246+
Controls the letter case of ID elements (labels) as included in `id`,
247+
set as tag values, and output by this module individually.
248+
Does not affect values of tags passed in via the `tags` input.
193249
Possible values: `lower`, `title`, `upper` and `none` (no transformation).
250+
Set this to `title` and set `delimiter` to `""` to yield Pascal Case IDs.
194251
Default value: `lower`.
195252
EOT
196253

@@ -199,4 +256,24 @@ variable "label_value_case" {
199256
error_message = "Allowed values: `lower`, `title`, `upper`, `none`."
200257
}
201258
}
259+
260+
variable "descriptor_formats" {
261+
type = any
262+
default = {}
263+
description = <<-EOT
264+
Describe additional descriptors to be output in the `descriptors` output map.
265+
Map of maps. Keys are names of descriptors. Values are maps of the form
266+
`{
267+
format = string
268+
labels = list(string)
269+
}`
270+
(Type is `any` so the map values can later be enhanced to provide additional options.)
271+
`format` is a Terraform format string to be passed to the `format()` function.
272+
`labels` is a list of labels, in order, to pass to `format()` function.
273+
Label values will be normalized before being passed to `format()` so they will be
274+
identical to how they appear in `id`.
275+
Default is `{}` (`descriptors` output will be empty).
276+
EOT
277+
}
278+
202279
#### End of copy of cloudposse/terraform-null-label/variables.tf

0 commit comments

Comments
 (0)