I am trying to escape percentual character in my terraform script:

"${join("\n",formatlist("%s ansible_host=%s ansible_ssh_common_args='-o ProxyCommand="ssh -W %h:%p -q cloud-user@%s"'","${module.compute.ops_master_names}","${module.compute.ops_master_priv_ips}","${module.ips.bastion_fips[0]}"))}"

How do I print the string "%h:%p" as plain text?


Using %% generally works to print a literal % character in printf-like functions. For example:

locals {
  test = ["foo", "bar"]

output "test" {
  value = "${formatlist("%s %%h:%%p", local.test)}"

Yields the following:

$ terraform apply

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.


test = [
    foo %h:%p,
    bar %h:%p

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.