-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.tf
36 lines (32 loc) · 1.23 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
locals {
vars = {
namespace = var.namespace
account = var.account
env = var.env
name = var.name
}
non_empty_vars = [for k, v in local.vars : k if v != null]
non_empty_vars_map = { for k in local.non_empty_vars : k => local.vars[k] }
# using the order from var.id_order, create the delmitied id from vars that are actually passed
ordered_id = join(var.delimiter, compact(concat([for k in var.id_order : contains(local.non_empty_vars, k) ? lookup(local.vars, k) : null], var.attributes)))
generated_tags_awscc = [
for k, v in local.non_empty_vars_map :
{
key : k,
value : v
}
]
generated_tags_aws = { for tag in local.generated_tags_awscc : tag["key"] => tag["value"] }
tags = try(
# Tags are already in awscc format
concat(local.generated_tags_awscc, var.tags),
# Tags are in aws format. Convert to awscc format
concat(local.generated_tags_awscc, [for k, v in var.tags : { key : k, value : v }])
)
tags_aws = try(
# Assuming tags are already in aws format
merge(local.generated_tags_aws, var.tags),
# Tags are in awscc format. Converting to aws format
merge(local.generated_tags_aws, { for tag in var.tags : tag["key"] => tag["value"] })
)
}