-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv_vars.tf
More file actions
57 lines (51 loc) · 2.34 KB
/
env_vars.tf
File metadata and controls
57 lines (51 loc) · 2.34 KB
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
variable "env_vars" {
type = map(string)
default = {}
description = <<EOF
The environment variables to inject into the service.
These are typically used to configure a service per environment.
It is dangerous to put sensitive information in this variable because they are not protected and could be unintentionally exposed.
EOF
}
variable "secrets" {
type = map(string)
default = {}
sensitive = true
description = <<EOF
The sensitive environment variables to inject into the service.
These are typically used to configure a service per environment.
EOF
}
locals {
standard_env_vars = tomap({
NULLSTONE_STACK = data.ns_workspace.this.stack_name
NULLSTONE_APP = data.ns_workspace.this.block_name
NULLSTONE_ENV = data.ns_workspace.this.env_name
NULLSTONE_VERSION = data.ns_app_env.this.version
NULLSTONE_COMMIT_SHA = data.ns_app_env.this.commit_sha
NULLSTONE_PUBLIC_HOSTS = join(",", local.public_hosts)
NULLSTONE_PRIVATE_HOSTS = join(",", local.private_hosts)
})
input_env_vars = merge(local.standard_env_vars, local.cap_env_vars, var.env_vars)
input_secrets = merge(local.cap_secrets, var.secrets)
input_secret_keys = nonsensitive(concat(keys(local.cap_secrets), keys(var.secrets)))
}
data "ns_env_variables" "this" {
input_env_variables = local.input_env_vars
input_secrets = local.input_secrets
}
// ns_secret_keys.this is used to calculate a set of secrets to add to aws secrets manager
// The resulting "secret_keys" attribute must be known at plan time
// This doesn't need to do a full interpolation because we only care about which inputs need to be added to aws secrets manager
// ns_secret_keys.input_env_variables should contain only var.env_vars since they could contain interpolation that promotes them to sensitive
// We exclude "local.cap_env_vars" because capabilities must use "cap_secrets" to create secrets
data "ns_secret_keys" "this" {
input_env_variables = var.env_vars
input_secret_keys = local.input_secret_keys
}
locals {
secret_keys = data.ns_secret_keys.this.secret_keys
all_secrets = data.ns_env_variables.this.secrets
existing_secret_refs = data.ns_env_variables.this.secret_refs
all_env_vars = merge(data.ns_env_variables.this.env_variables, local.app_secret_ids, local.existing_secret_refs)
}