-
Notifications
You must be signed in to change notification settings - Fork 9
/
env.tf
62 lines (55 loc) · 1.59 KB
/
env.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
locals {
# flatten() ensures that this local value is a flat list of objects, rather
# than a list of lists of objects.
# Generate workspace variables pairs to create resources, both (non-)sensistive
work_vars = flatten([
for work, path in var.workspaces : [
for var_key, var in var.vars : {
work = work
var_key = var_key
path = path
var = var
}
]
])
work_sec_vars = flatten([
for work, path in var.workspaces : [
for var_key, var in var.sec_vars : {
work = work
var_key = var_key
path = path
var = var
}
]
])
}
resource "tfe_variable" "vars" {
# Project back into a map
for_each = {
for i in local.work_vars : "${i.work}.${i.var_key}" => i
}
category = "env"
key = each.value.var_key
value = each.value.var
workspace_id = tfe_workspace.workspace[each.value.work].id
description = "${each.value.var_key} for TerraformCloud"
sensitive = false
lifecycle {
create_before_destroy = false # To avoid having two variables with the same key
}
}
resource "tfe_variable" "sec_vars" {
# Project back into a map
for_each = {
for i in local.work_sec_vars : "${i.work}.${i.var_key}" => i
}
category = "env"
key = each.value.var_key
value = each.value.var
workspace_id = tfe_workspace.workspace[each.value.work].id
description = "${each.value.var_key} for TerraformCloud"
sensitive = true
lifecycle {
create_before_destroy = false # To avoid having two variables with the same key
}
}