Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escaping special characters in a string using terraform

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

like image 611
Sireesha Prasanth Avatar asked Oct 26 '25 15:10

Sireesha Prasanth


1 Answers

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
like image 163
Marcin Avatar answered Oct 29 '25 07:10

Marcin