【问题标题】:Escaping special characters in a string using terraform使用 terraform 转义字符串中的特殊字符
【发布时间】:2021-01-09 04:39:48
【问题描述】:
您能帮我使用 terraform 实现以下场景吗?
我需要为字符串值中的每个特殊字符添加前缀//。
示例:mysplchr="test O'riel*abc" 这必须更改为 "test O//'riel//*abc"
谢谢
【问题讨论】:
标签:
terraform
terraform-provider-aws
terraform-provider-azure
terraform-provider-gcp
terraform0.12+
【解决方案1】:
不知道这里有什么问题,但是你可以直接写,或者如果你愿意,可以自动更改原始字符串:
variable "mysplchr" {
default = "test O//'riel//*abc"
}
output "test1" {
value = var.mysplchr
}
# or to do it automatically for
# the original string
output "test2" {
value = replace("test O'riel*abc", "/(['\\*])/", "//$1")
}
结果是:
test1 = test O//'riel//*abc
test2 = test O//'riel//*abc