-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathmain.tf
39 lines (31 loc) · 1.59 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
## Managed By : CloudDrove
## Copyright @ CloudDrove. All Right Reserved.
#Module : locals
#Description : This terraform module is designed to generate consistent label names and tags for resources. You can use terraform-labels to implement a strict naming convention.
locals {
label_order_defaults = {
label_order = ["environment", "name"]
}
id_context = {
name = var.name
environment = var.environment
}
label_order = length(var.label_order) > 0 ? var.label_order : local.label_order_defaults.label_order
# run loop for label order and set in value.
id_labels = [for l in local.label_order : local.id_context[l] if length(local.id_context[l]) > 0 && var.enabled]
id = var.enabled ? lower(join(var.delimiter, local.id_labels, var.attributes)) : ""
name = var.enabled ? lower(format("%v", var.name)) : ""
environment = var.enabled ? lower(format("%v", var.environment)) : ""
managedby = var.enabled ? lower(format("%v", var.managedby)) : ""
repository = var.enabled ? lower(format("%v", var.repository)) : ""
attributes = var.enabled ? lower(format("%v", join(var.delimiter, compact(var.attributes)))) : ""
tags_context = {
# For AWS we need `Name` to be disambiguated sine it has a special meaning
name = local.id
environment = local.environment
managedby = local.managedby
repository = local.repository
}
generated_tags = { for l in keys(local.tags_context) : title(l) => local.tags_context[l] if length(local.tags_context[l]) > 0 }
tags = var.enabled ? merge(local.generated_tags, var.extra_tags) : null
}