我正在尝试在我的 Terraform 脚本中转义百分号字符:
"${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]}"))}"
如何将字符串“%h:%p”打印为纯文本?
答案1
使用%%
通常可以%
在printf
类似函数中打印文字字符。例如:
locals {
test = ["foo", "bar"]
}
output "test" {
value = "${formatlist("%s %%h:%%p", local.test)}"
}
得出以下结论:
$ terraform apply
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Outputs:
test = [
foo %h:%p,
bar %h:%p
]