Search code examples
terraformhcl

how to escape double quotation in terraform?


I am using the remote-exec provider in my terraform v0.9.11 template like this:

... 
 provisioner "remote-exec" {
     inline = [
       "Set-ExecutionPolicy Bypass -force",
       "./C:\ProgramData\Amazon\EC2-Windows\Launch\Config\Replace-FileString.ps1 -Pattern '""' -Replacement '"${var.admin_password}"' -Path LauchConfig.json"
     ]
...

But I get an illegal char escape error at -Pattern '""'.

The command I want to execute on the remote machine is: "... FileString.ps1 -Pattern '""' -Replacement '"xyz"' "

PS: escaping with \ like "... FileString.ps1 -Pattern '\"\"' -Replacement '\"xyz\"' " does not work either.

... represents omitted irrelevant text here.


Solution

  • It turned out that the error message was misleading when pointing to -Pattern '""' as the actual error turned to be in another location in the template where the backslash in a windows file path was not properly escaped (i.e. C:\filename when it should have been C:\\filename

    The error message need to point at the right error location!