Skip to main content

terraform escape percentual character [Resolved]

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?

Question Credit: Henry TheKing
Question Reference
Asked January 11, 2019
Tags: terraform
Posted Under: Network
1 Answers

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

credit: bodgit
Answered January 11, 2019
Your Answer