Started by Danielle LawrieSep 10, 2021

Open
How do you do simple string concatenation in Terraform?

0 VIEWES 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 0 VIEWES SHARE

I must be being incredibly stupid but I can't figure out how to do simple string concatenation in Terraform.

I have the following data null_data_source:

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

So when env_name="prod" I want the output app.api.mydomain.com and for anything else - let's say env_name="staging" I want app.api.staging.mydomain.com.

But the above will output app.api.stagingmydomain.com <-- notice the missing dot after staging.

I tried concating the "." if the env_name was anything but "prod" but Terraform errors:

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

The error is __builtin_StringToInt: strconv.ParseInt: parsing ""

The concat() function in TF appears to be for lists not strings.

So as the title says: How do you do simple string concatenation in Terraform?

0 Replies

You must be Logged in to reply
Techiio

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

facebooklinkdeintwitter

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Copyright techiio.com @2020 Kolkata, India
made with by Abhishek & Priyanka Jalan
Copyright techiio.com @2020
made with by Abhishek & Priyanka Jalan