I use terraform to deploy to GCP and there’s bunch of resources that I want to deploy to all my projects hence I have a set of maps to collate information about each project:
echo "local.projects" | terraform console
toset([
{
"environment" = "dev"
"project_id" = "ourorg-cdm-dev"
"stem" = "cdm"
},
{
"environment" = "dev"
"project_id" = "ourorg-tabboardpoc-dev"
"stem" = "tabboardpoc"
},
{
"environment" = "prod"
"project_id" = "ourorg-cdm-prod"
"stem" = "cdm"
},
{
"environment" = "test"
"project_id" = "ourorg-cdm-test"
"stem" = "cdm"
},
])
and I then pass that set to my resources and use for_each
to deploy stuff to all my projects - works great!
I now want to deploy a GKE cluster to some of those projects, but not to all of them. Hence I want to add a boolean element to each map stating whether or not a GKE cluster should be deployed or not and the logic is
if stem == “cdm”, then gke_cluster = true else false
In other words I want to end up with this:
toset([
{
"environment" = "dev"
"project_id" = "ourorg-cdm-dev"
"stem" = "cdm"
"gke_cluster" = true
},
{
"environment" = "dev"
"project_id" = "ourorg-tabboardpoc-dev"
"stem" = "tabboardpoc"
"gke_cluster" = false
},
{
"environment" = "prod"
"project_id" = "ourorg-cdm-prod"
"stem" = "cdm"
"gke_cluster" = true
},
{
"environment" = "test"
"project_id" = "ourorg-cdm-test"
"stem" = "cdm"
"gke_cluster" = true
},
])
I’ve fiddled around with for
expressions but can’t figure out the correct syntax in order to construct what I need. Can anyone here figure it out given I’m not having much luck?