diff --git a/LICENSE b/LICENSE index 808ecf3..a6e3b3e 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2017-2018 Cloud Posse, LLC + Copyright 2017-2019 Cloud Posse, LLC Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/README.md b/README.md index 0b5684d..26cabf4 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Terraform module designed to generate consistent label names and tags for resources. Use `terraform-null-label` to implement a strict naming convention. A label follows the following convention: `{namespace}-{environment}-{stage}-{name}-{attributes}`. The delimiter (e.g. `-`) is interchangeable. -The label items are all optional. So if you perfer the term `stage` to `environment` you can exclude environment and the label `id` will look like `{namespace}-{stage}-{name}-{attributes}`. +The label items are all optional. So if you prefer the term `stage` to `environment` you can exclude environment and the label `id` will look like `{namespace}-{stage}-{name}-{attributes}`. If attributes are excluded but `stage` and `environment` are included, `id` will look like `{namespace}-{environment}-{stage}-{name}` It's recommended to use one `terraform-null-label` module for every unique resource of a given resource type. diff --git a/README.yaml b/README.yaml index 4095088..20452f0 100644 --- a/README.yaml +++ b/README.yaml @@ -52,7 +52,7 @@ description: |- Terraform module designed to generate consistent label names and tags for resources. Use `terraform-null-label` to implement a strict naming convention. A label follows the following convention: `{namespace}-{environment}-{stage}-{name}-{attributes}`. The delimiter (e.g. `-`) is interchangeable. - The label items are all optional. So if you perfer the term `stage` to `environment` you can exclude environment and the label `id` will look like `{namespace}-{stage}-{name}-{attributes}`. + The label items are all optional. So if you prefer the term `stage` to `environment` you can exclude environment and the label `id` will look like `{namespace}-{stage}-{name}-{attributes}`. If attributes are excluded but `stage` and `environment` are included, `id` will look like `{namespace}-{environment}-{stage}-{name}` It's recommended to use one `terraform-null-label` module for every unique resource of a given resource type. diff --git a/main.tf b/main.tf index 477acde..483bb90 100644 --- a/main.tf +++ b/main.tf @@ -24,25 +24,28 @@ locals { # else # thing - 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, 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, 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, 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, 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}" + regex_replace_chars_context = "${concat(local.context_local["regex_replace_chars"], list(""))}" + regex_replace_chars_context_or_default = "${length(local.regex_replace_chars_context[0]) > 0 ? local.regex_replace_chars_context[0] : var.regex_replace_chars}" + regex_replace_chars = "${var.regex_replace_chars != "" ? var.regex_replace_chars : local.regex_replace_chars_context_or_default}" + 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, local.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, local.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, local.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, local.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}" # Merge attributes attributes = ["${distinct(compact(concat(var.attributes, local.context_local["attributes"])))}"] # Generate tags (don't include tags with empty values) @@ -58,15 +61,16 @@ locals { label_order_length = "${(length(local.label_order_final_list))}" # Context of this label to pass to other label modules output_context = { - name = ["${local.name}"] - namespace = ["${local.namespace}"] - environment = ["${local.environment}"] - stage = ["${local.stage}"] - attributes = ["${local.attributes}"] - tags_keys = ["${keys(local.tags)}"] - tags_values = ["${values(local.tags)}"] - delimiter = ["${local.delimiter}"] - label_order = ["${local.label_order_final_list}"] + name = ["${local.name}"] + namespace = ["${local.namespace}"] + environment = ["${local.environment}"] + stage = ["${local.stage}"] + attributes = ["${local.attributes}"] + tags_keys = ["${keys(local.tags)}"] + tags_values = ["${values(local.tags)}"] + delimiter = ["${local.delimiter}"] + label_order = ["${local.label_order_final_list}"] + regex_replace_chars = ["${local.regex_replace_chars}"] } id_context = { name = "${local.name}"