-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcapabilities.tf.tmpl
61 lines (55 loc) · 1.41 KB
/
capabilities.tf.tmpl
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
{{ range . -}}
provider "ns" {
capability_id = {{ .Id }}
alias = "cap_{{ .Id }}"
}
module "{{ .TfModuleName }}" {
source = "{{ .Source }}/any"
{{- if (ne .SourceVersion "latest") }}
version = "{{ .SourceVersion }}"
{{- end }}
app_metadata = local.app_metadata
{{ range $key, $value := .Variables -}}
{{ if $value.HasValue -}}
{{ $key }} = jsondecode({{ $value.Value | to_json_string }})
{{- end }}
{{ end }}
providers = {
ns = ns.cap_{{ .Id}}
}
}
{{ end }}
module "caps" {
source = "nullstone-modules/cap-merge/ns"
modules = local.modules
}
locals {
modules = [
{{- range $index, $element := .ExceptNeedsDestroyed.TfModuleAddrs -}}
{{ if $index }}, {{ end }}{{ $element }}
{{- end -}}
]
capabilities = module.caps.outputs
cap_modules = [
{{- range $index, $element := .ExceptNeedsDestroyed }}
{{ if $index }}, {{ end }}{
id = {{ $element.Id }}
namespace = "{{ $element.Namespace }}"
env_prefix = "{{ $element.EnvPrefix }}"
outputs = {{ $element.TfModuleAddr }}
}
{{- end }}
]
}
locals {
cap_env_vars = merge([
for mod in local.cap_modules : {
for item in lookup(mod.outputs, "env", []) : "${mod.env_prefix}${item.name}" => item.value
}
]...)
cap_secrets = merge([
for mod in local.cap_modules : {
for item in lookup(mod.outputs, "secrets", []) : "${mod.env_prefix}${item.name}" => item.value
}
]...)
}