How do you do simple string concatenation in Terraform?

Solution 1:

I know this was already answered, but I wanted to share my favorite:

format("%s/%s",var.string,"string2")

Real world example:

locals {
 documents_path = "${var.documents_path == "" ? format("%s/%s",path.module,"documents") : var.documents_path}" 
}

More info:
https://www.terraform.io/docs/configuration/functions/format.html

Solution 2:

Try Below data resource :

data "null_data_source" "api_gw_url" {
    inputs = {
      main_api_gw = "app.api${var.env_name == "prod" ? "." : ".${var.env_name}."}mydomain.com"
    }
}