Skip to content

Commit c4e0de3

Browse files
r-divakaran-hrsaknysh
authored andcommitted
To allow special characters in module id (#48)
* To allow special characters in module id * Adjusting spacing * Adjustments as per review comments * More meaningful variable name
1 parent 322898a commit c4e0de3

File tree

4 files changed

+23
-16
lines changed

4 files changed

+23
-16
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,6 @@ Available targets:
396396
lint Lint terraform code
397397
398398
```
399-
400399
## Inputs
401400

402401
| Name | Description | Type | Default | Required |
@@ -410,6 +409,7 @@ Available targets:
410409
| label_order | The naming order of the id output and Name tag | list | `<list>` | no |
411410
| name | Solution name, e.g. 'app' or 'jenkins' | string | `` | no |
412411
| namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | string | `` | no |
412+
| regex_replace_chars | By default only letters and digits are allowed in `namespace`, `environment`, `stage` and `name`. All other chars are removed | string | `[^a-zA-Z0-9]` | no |
413413
| stage | Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release' | string | `` | no |
414414
| tags | Additional tags (e.g. `map('BusinessUnit','XYZ')` | map | `<map>` | no |
415415

@@ -509,7 +509,7 @@ In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow.
509509

510510
## Copyright
511511

512-
Copyright © 2017-2018 [Cloud Posse, LLC](https://cpco.io/copyright)
512+
Copyright © 2017-2019 [Cloud Posse, LLC](https://cpco.io/copyright)
513513

514514

515515

docs/terraform.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
## Inputs
32

43
| Name | Description | Type | Default | Required |
@@ -12,6 +11,7 @@
1211
| label_order | The naming order of the id output and Name tag | list | `<list>` | no |
1312
| name | Solution name, e.g. 'app' or 'jenkins' | string | `` | no |
1413
| namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | string | `` | no |
14+
| regex_replace_chars | By default only letters and digits are allowed in `namespace`, `environment`, `stage` and `name`. All other chars are removed | string | `[^a-zA-Z0-9]` | no |
1515
| stage | Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release' | string | `` | no |
1616
| tags | Additional tags (e.g. `map('BusinessUnit','XYZ')` | map | `<map>` | no |
1717

main.tf

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ locals {
33

44
# Only maps that contain all the same attribute types can be merged, so the values have been set to list
55
context_struct = {
6-
name = []
7-
namespace = []
8-
environment = []
9-
stage = []
10-
attributes = []
11-
tags_keys = []
12-
tags_values = []
13-
delimiter = []
14-
label_order = []
6+
name = []
7+
namespace = []
8+
environment = []
9+
stage = []
10+
attributes = []
11+
tags_keys = []
12+
tags_values = []
13+
delimiter = []
14+
label_order = []
15+
regex_replace_chars = []
1516
}
1617

1718
# Merge the map of empty values, with the variable context, so that context_local always contains all map keys
@@ -26,19 +27,19 @@ locals {
2627
names = "${concat(local.context_local["name"], list(""))}"
2728
name_context_or_default = "${length(local.names[0]) > 0 ? local.names[0] : var.name}"
2829
name_or_context = "${var.name != ""? var.name : local.name_context_or_default}"
29-
name = "${lower(replace(local.name_or_context, "/[^a-zA-Z0-9]/", ""))}"
30+
name = "${lower(replace(local.name_or_context, "/var.regex_replace_chars/", ""))}"
3031
namespaces = "${concat(local.context_local["namespace"], list(""))}"
3132
namespace_context_or_default = "${length(local.namespaces[0]) > 0 ? local.namespaces[0] : var.namespace}"
3233
namespace_or_context = "${var.namespace != "" ? var.namespace : local.namespace_context_or_default}"
33-
namespace = "${lower(replace(local.namespace_or_context, "/[^a-zA-Z0-9]/", ""))}"
34+
namespace = "${lower(replace(local.namespace_or_context, "/var.regex_replace_chars/", ""))}"
3435
environments = "${concat(local.context_local["environment"], list(""))}"
3536
environment_context_or_default = "${length(local.environments[0]) > 0 ? local.environments[0] : var.environment}"
3637
environment_or_context = "${var.environment != "" ? var.environment : local.environment_context_or_default}"
37-
environment = "${lower(replace(local.environment_or_context, "/[^a-zA-Z0-9]/", ""))}"
38+
environment = "${lower(replace(local.environment_or_context, "/var.regex_replace_chars/", ""))}"
3839
stages = "${concat(local.context_local["stage"], list(""))}"
3940
stage_context_or_default = "${length(local.stages[0]) > 0 ? local.stages[0] : var.stage}"
4041
stage_or_context = "${var.stage != "" ? var.stage : local.stage_context_or_default}"
41-
stage = "${lower(replace(local.stage_or_context, "/[^a-zA-Z0-9]/", ""))}"
42+
stage = "${lower(replace(local.stage_or_context, "/var.regex_replace_chars/", ""))}"
4243
delimiters = "${concat(local.context_local["delimiter"], list(""))}"
4344
delimiter_context_or_default = "${length(local.delimiters[0]) > 0 ? local.delimiters[0] : var.delimiter}"
4445
delimiter = "${var.delimiter != "-" ? var.delimiter : local.delimiter_context_or_default}"

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,9 @@ variable "label_order" {
6363
default = []
6464
description = "The naming order of the id output and Name tag"
6565
}
66+
67+
variable "regex_replace_chars" {
68+
type = "string"
69+
default = "[^a-zA-Z0-9]"
70+
description = "By default only letters and digits are allowed in `namespace`, `environment`, `stage` and `name`. All other chars are removed"
71+
}

0 commit comments

Comments
 (0)