I have been in DevOps related jobs for past 6 years dealing mainly with Kubernetes in AWS and on-premise as well. I spent quite a lot …
![post image](/images/blog/linux-1_hu928a111b75a731678aae189a5163bdac_17752_eedd5336be16616ed0b2dcda96bc315e.webp)
How to conditionally add key value to Terraform map
This code will conditionally add or ommit netapp-cleaner
block based on prefix
local variable.
locals {
prefix = "deaut"
raj = merge({
netapp-admin = {
member = "serviceAccount:raj",
role = "roles/netapp.admin"
},
netapp-user = {
member = "serviceAccount:jan",
role = "roles/netapp.user"
},
},
local.prefix == "xdeaut" ? {
netapp-cleaner = {
member = "serviceAccount:cleaner",
role = "roles/blaaaa"
}
}: {}
)
}
output "debug" {
value = local.raj
description = "debug"
}
Links:
202406191306