I have a locals variable defined as so:
locals {
subnets = {
# AWS Account:
"222222222222" = {
# Environment name:
"prod" = {
"us-west-2" : ["subnet-11111111111", "subnet-22222222", "subnet-3333333", "subnet-333333"]
}
"default" = {
"us-east-2" : split(",", data.terraform_remote_state.vpc.outputs.private_subnets)
}
}
}
}
# and I can reference it like so:
subnet_ids = local.subnets[var.aws_account_id][var.environment][var.region]
Unfortunately, the only two possible keys for var.enviroment
is “prod” or “default”.
What I really want to do is: (pseudo code):
if var.environment is not a key in local.subnets[var.aws_account_id], then use the "default" value for var.environment.
Is this possible in terraform?