vendredi 16 juillet 2021

If-else condition in terraform data source

My question is very simple but unable to find any example or solution on the entire internet. I want to use the if-else condition in the data source of terraform and based on the value it should search the result. We have 2 different VPCs in our AWS account: 1. Prod VPC, 2. RDS VPC

Filter should work based on boolean variable var.rds_vpc

Pseudocode:

data "aws_vpc" "vpc" {
  if var.rds_vpc == true:
    tags = {
      Name = "rds_vpc"
      Type = "database"
    }
  else:
    tags = {
      Cluster     = "live_vpc"
      Enviornment = "production"
    }

}

If both VPCs could have similar tags, I could simply pass the values via variables. But in the above case, the tags are also different.

I would highly appreciate it if someone can help.

Aucun commentaire:

Enregistrer un commentaire