Skip to content

Commit 9c39ea5

Browse files
committed
Make it possible to mount secrets as volumes
Use `mount_secrets` within service definition: mount_secrets = { secret-name = "/destination/path" } Every key in `data` in secret become a file in the destination path.
1 parent 2df4f31 commit 9c39ea5

3 files changed

Lines changed: 31 additions & 0 deletions

File tree

k8s/basic/cluster/cluster.tf

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ resource "kubernetes_deployment" "deployment" {
119119
}
120120
}
121121
}
122+
123+
dynamic "volume_mount" {
124+
for_each = each.value.mount_secrets
125+
content {
126+
name = volume_mount.key
127+
mount_path = volume_mount.value
128+
}
129+
}
122130
}
123131

124132
dynamic "init_container" {
@@ -158,6 +166,25 @@ resource "kubernetes_deployment" "deployment" {
158166
}
159167
}
160168
}
169+
170+
dynamic "volume_mount" {
171+
for_each = init_container.value.mount_secrets
172+
content {
173+
name = volume_mount.key
174+
mount_path = volume_mount.value
175+
}
176+
}
177+
}
178+
}
179+
180+
dynamic "volume" {
181+
for_each = each.value.mount_secrets
182+
183+
content {
184+
name = volume.key
185+
secret {
186+
secret_name = volume.key
187+
}
161188
}
162189
}
163190
}

k8s/basic/cluster/variables.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ variable "services" {
2828
env_from_secrets = optional(list(string))
2929
env_from_field = optional(map(string))
3030
env = optional(map(string))
31+
mount_secrets = optional(map(string))
3132
init_container = optional(object({
3233
image = optional(string)
3334
command = list(string)
3435
env_from_secrets = optional(list(string))
3536
env_from_field = optional(map(string))
3637
env = optional(map(string))
38+
mount_secrets = optional(map(string))
3739
}))
3840
})
3941
)

k8s/basic/variables.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ variable "services" {
3434
env_from_secrets = optional(list(string))
3535
env_from_field = optional(map(string))
3636
env = optional(map(string))
37+
mount_secrets = optional(map(string))
3738
init_container = optional(object({
3839
image = optional(string)
3940
command = list(string)
4041
env_from_secrets = optional(list(string))
4142
env_from_field = optional(map(string))
4243
env = optional(map(string))
44+
mount_secrets = optional(map(string))
4345
}))
4446
})
4547
)

0 commit comments

Comments
 (0)