2

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.

Sami
  • 7,797
  • 18
  • 45
  • 69
  • From everything I can see, it looks like escaping with a backslash should work. What actually happens when you try it - assume it's some sort of parser error? If so, I wonder if this is a regression in terraform and should be logged as a new bug. In the meantime, could you use the `script` option rather than `inline`? – James Thorpe Aug 24 '17 at 15:15
  • @JamesThorpe when I have the backslash used, I still get `illegal char escape` .. I will try `script` and see if the problem persists – Sami Aug 24 '17 at 15:26
  • 1
    Was just looking at that - you might need to use the [`file` and `inline` since you've got an argument to pass in](https://www.terraform.io/docs/provisioners/remote-exec.html#script-arguments) (`admin_password`) – James Thorpe Aug 24 '17 at 15:27

1 Answers1

1

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!

Sami
  • 7,797
  • 18
  • 45
  • 69