-
Notifications
You must be signed in to change notification settings - Fork 5
/
locals.tf
133 lines (119 loc) · 3.06 KB
/
locals.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
locals {
# This whole block is dedicated to converting an input variable of map (same type as other resources) into asg
# compatible format, which is a list of maps with the propagate_at_launch variable set at true.
# Split the full_tags variable (map) into 2 lists in same order as the map
tag_keys = "${keys(var.additional_tags)}"
tag_values = "${values(var.additional_tags)}"
list_blank = "${list()}"
# Define a structure for the keys of the dicts that the asg block requires.
key_list = "${list(
"key",
"value",
"propagate_at_launch")}"
# 10 lists containing values that will be zipmapped to the above structure later.
list0 = "${list(
element(concat(local.tag_keys, list("")), 0),
element(concat(local.tag_values, list("")), 0),
"true"
)
}"
list1 = "${list(
element(concat(local.tag_keys, list("")), 1),
element(concat(local.tag_values, list("")), 1),
"true"
)
}"
list2 = "${list(
element(concat(local.tag_keys, list("")), 2),
element(concat(local.tag_values, list("")), 2),
"true"
)
}"
list3 = "${list(
element(concat(local.tag_keys, list("")), 3),
element(concat(local.tag_values, list("")), 3),
"true"
)
}"
list4 = "${list(
element(concat(local.tag_keys, list("")), 4),
element(concat(local.tag_values, list("")), 4),
"true"
)
}"
list5 = "${list(
element(concat(local.tag_keys, list("")), 5),
element(concat(local.tag_values, list("")), 5),
"true"
)
}"
list6 = "${list(
element(concat(local.tag_keys, list("")), 6),
element(concat(local.tag_values, list("")), 6),
"true"
)
}"
list7 = "${list(
element(concat(local.tag_keys, list("")), 7),
element(concat(local.tag_values, list("")), 7),
"true"
)
}"
list8 = "${list(
element(concat(local.tag_keys, list("")), 8),
element(concat(local.tag_values, list("")), 8),
"true"
)
}"
list9 = "${list(
element(concat(local.tag_keys, list("")), 9),
element(concat(local.tag_values, list("")), 9),
"true"
)
}"
# Construct list of dicts in required format by zipmapping the value lists with the standard key list
# Slicing to the length of the map of tags so we dont get blank or repeating tags starting from first non-default value
tags_asg_format = "${slice(list(
zipmap(
local.key_list,
local.list0
),
zipmap(
local.key_list,
local.list1
),
zipmap(
local.key_list,
local.list2
),
zipmap(
local.key_list,
local.list3
),
zipmap(
local.key_list,
local.list4
),
zipmap(
local.key_list,
local.list5
),
zipmap(
local.key_list,
local.list6
),
zipmap(
local.key_list,
local.list7
),
zipmap(
local.key_list,
local.list8
),
zipmap(
local.key_list,
local.list9
)
), 0, min(length(local.tag_keys), 10))
}"
}