In your try() block, when the attribute doesn't exist, it correctly returns . However, when the attribute does exist, it returns the whole nested object (e.g., { host = ..., name = ... }). In Terraform, comparing a complex object/map to an empty string ({...} != ) is technically invalid or doesn't evaluate cleanly to a false check, causing the filter to let it slip through or crash when it expects a string.

This commit is contained in:
pi-ux-ce@ARES
2026-10-13 18:47:57 +01:00
parent aef087cfe1
commit c9ade2f851
2 changed files with 8 additions and 8 deletions
+1 -1
View File
@@ -160,7 +160,7 @@ resource "bitwarden-secrets_secret" "automatic_bitwarden_secret_db_name" {
locals { locals {
database_secrets_to_import = { database_secrets_to_import = {
for key, value in var.kubernetes : key => value for key, value in var.kubernetes : key => value
if value.database != null && value.enabled == true && try(value.import_database_secret, "") != "" if value.database != null && value.enabled == true && can(value.import_database_secret.host)
} }
} }
+7 -7
View File
@@ -2,11 +2,11 @@ kubernetes = {
gluetun = { gluetun = {
#enabled = false #enabled = false
dns_nameservers = "1.1.1.1" dns_nameservers = "1.1.1.1"
replicas = 01 replicas = 01
image = "qmcgaw/gluetun:latest" image = "qmcgaw/gluetun:latest"
exposed = false exposed = false
service_port = [8888] service_port = [8888]
secret_import = ["5527ba11-07e3-415b-8d1f-b3ee0154eb56", "b0d22160-d81a-4702-a3dd-b40e0168d617", "643dbe99-ace0-4ef5-8a2e-b44f014dccb0"] secret_import = ["5527ba11-07e3-415b-8d1f-b3ee0154eb56", "b0d22160-d81a-4702-a3dd-b40e0168d617", "643dbe99-ace0-4ef5-8a2e-b44f014dccb0"]
security_context = true security_context = true
@@ -68,8 +68,8 @@ kubernetes = {
username = "django_username" username = "django_username"
mountPath = "/var/lib/postgresql/data" mountPath = "/var/lib/postgresql/data"
} }
secret_ref = ["django-bitwarden-credentials"] secret_ref = ["django-bitwarden-credentials"]
secret_import = ["9fc5a725-75f5-4bab-b595-b474017146c3"] #secret_import = ["9fc5a725-75f5-4bab-b595-b474017146c3"]
requirements = { requirements = {
limits-cpu = "800m" limits-cpu = "800m"
limits-memory = "800Mi" limits-memory = "800Mi"