Search code examples
terraformstring-formattingterraform0.12+

format string with multiple values in terraform


Terraform version = .12+

I'm wondering if there's a way to format a single string with multiple values.

I've tried using the terraform format function like so:

bucket = format("%-%", 'dev', "test")
bucket = format("%-%", ['dev', "test"])

which both output the error:

Call to function "format" failed: unrecognized format character '%' at offset
2.

The expected formatted value would be dev-test


Solution

  • The code should be:

    bucket = format("%s-%s", "dev", "test")
    

    It uses %s as well as double quotes for dev.

    The formatting marks available are detailed here.