Skip to content

Commit

Permalink
To allow special characters in module id (#48)
Browse files Browse the repository at this point in the history
* To allow special characters in module id

* Adjusting spacing

* Adjustments as per review comments

* More meaningful variable name
  • Loading branch information
r-divakaran-hrs authored and aknysh committed Feb 13, 2019
1 parent 322898a commit c4e0de3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,6 @@ Available targets:
lint Lint terraform code
```

## Inputs

| Name | Description | Type | Default | Required |
Expand All @@ -410,6 +409,7 @@ Available targets:
| label_order | The naming order of the id output and Name tag | list | `<list>` | no |
| name | Solution name, e.g. 'app' or 'jenkins' | string | `` | no |
| namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | string | `` | no |
| 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 |
| stage | Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release' | string | `` | no |
| tags | Additional tags (e.g. `map('BusinessUnit','XYZ')` | map | `<map>` | no |

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

## Copyright

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



Expand Down
2 changes: 1 addition & 1 deletion docs/terraform.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

## Inputs

| Name | Description | Type | Default | Required |
Expand All @@ -12,6 +11,7 @@
| label_order | The naming order of the id output and Name tag | list | `<list>` | no |
| name | Solution name, e.g. 'app' or 'jenkins' | string | `` | no |
| namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | string | `` | no |
| 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 |
| stage | Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release' | string | `` | no |
| tags | Additional tags (e.g. `map('BusinessUnit','XYZ')` | map | `<map>` | no |

Expand Down
27 changes: 14 additions & 13 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ locals {

# Only maps that contain all the same attribute types can be merged, so the values have been set to list
context_struct = {
name = []
namespace = []
environment = []
stage = []
attributes = []
tags_keys = []
tags_values = []
delimiter = []
label_order = []
name = []
namespace = []
environment = []
stage = []
attributes = []
tags_keys = []
tags_values = []
delimiter = []
label_order = []
regex_replace_chars = []
}

# Merge the map of empty values, with the variable context, so that context_local always contains all map keys
Expand All @@ -26,19 +27,19 @@ locals {
names = "${concat(local.context_local["name"], list(""))}"
name_context_or_default = "${length(local.names[0]) > 0 ? local.names[0] : var.name}"
name_or_context = "${var.name != ""? var.name : local.name_context_or_default}"
name = "${lower(replace(local.name_or_context, "/[^a-zA-Z0-9]/", ""))}"
name = "${lower(replace(local.name_or_context, "/var.regex_replace_chars/", ""))}"
namespaces = "${concat(local.context_local["namespace"], list(""))}"
namespace_context_or_default = "${length(local.namespaces[0]) > 0 ? local.namespaces[0] : var.namespace}"
namespace_or_context = "${var.namespace != "" ? var.namespace : local.namespace_context_or_default}"
namespace = "${lower(replace(local.namespace_or_context, "/[^a-zA-Z0-9]/", ""))}"
namespace = "${lower(replace(local.namespace_or_context, "/var.regex_replace_chars/", ""))}"
environments = "${concat(local.context_local["environment"], list(""))}"
environment_context_or_default = "${length(local.environments[0]) > 0 ? local.environments[0] : var.environment}"
environment_or_context = "${var.environment != "" ? var.environment : local.environment_context_or_default}"
environment = "${lower(replace(local.environment_or_context, "/[^a-zA-Z0-9]/", ""))}"
environment = "${lower(replace(local.environment_or_context, "/var.regex_replace_chars/", ""))}"
stages = "${concat(local.context_local["stage"], list(""))}"
stage_context_or_default = "${length(local.stages[0]) > 0 ? local.stages[0] : var.stage}"
stage_or_context = "${var.stage != "" ? var.stage : local.stage_context_or_default}"
stage = "${lower(replace(local.stage_or_context, "/[^a-zA-Z0-9]/", ""))}"
stage = "${lower(replace(local.stage_or_context, "/var.regex_replace_chars/", ""))}"
delimiters = "${concat(local.context_local["delimiter"], list(""))}"
delimiter_context_or_default = "${length(local.delimiters[0]) > 0 ? local.delimiters[0] : var.delimiter}"
delimiter = "${var.delimiter != "-" ? var.delimiter : local.delimiter_context_or_default}"
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,9 @@ variable "label_order" {
default = []
description = "The naming order of the id output and Name tag"
}

variable "regex_replace_chars" {
type = "string"
default = "[^a-zA-Z0-9]"
description = "By default only letters and digits are allowed in `namespace`, `environment`, `stage` and `name`. All other chars are removed"
}

0 comments on commit c4e0de3

Please sign in to comment.