generated from clouddrove/terraform-module-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
39 lines (32 loc) · 1.77 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
##-----------------------------------------------------------------------------
## 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 = ["name", "environment"]
}
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]
id = lower(join(var.delimiter, local.id_labels, var.attributes))
name = var.enabled == true ? lower(format("%v", var.name)) : ""
environment = var.enabled == true ? lower(format("%v", var.environment)) : ""
managedby = var.enabled == true ? lower(format("%v", var.managedby)) : ""
repository = var.enabled == true ? lower(format("%v", var.repository)) : ""
business_unit = var.enabled == true ? lower(format("%v", var.business_unit)) : ""
attributes = var.enabled == true ? lower(format("%v", join(var.delimiter, compact(var.attributes)))) : ""
tags_context = {
# For Azure we need `Name` to be disambiguated sine it has a special meaning
name = local.id
environment = local.environment
managedby = local.managedby
repository = local.repository
business_unit = local.business_unit
}
generated_tags = { for l in keys(local.tags_context) : title(l) => local.tags_context[l] if length(local.tags_context[l]) > 0 }
tags = merge(local.generated_tags, var.extra_tags)
}