2
votes

Can you please help me to achieve the below scenario using terraform? I need to prefix every special character in a string value with //.

Example : mysplchr="test O'riel*abc" this has to be changed as "test O//'riel//*abc"

Thanks

1

1 Answers

4
votes

Not sure what is the issue here, but you can write it directly or change the original string automatically if you want:

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")
}

the outcome is:

test1 = test O//'riel//*abc
test2 = test O//'riel//*abc