Loading...
Loading...
### Terraform Version ``` Terraform v0.15.0 on linux_amd64 + provider registry.terraform.io/hashicorp/null v3.1.0 ``` Hi, I would like to set my remote-exec provisioner configuration like this: ``` inline = [<<EOF powershell -f "C:\Users\${var.my_user}\file.ps1" ` -VAR1 "${var.string1}" ` -VAR2 "${var.string2}" ` -VAR3 "${var.string3}" ` -VAR4 "${var.string4}" EOF ] ``` I'm provisioning a PowerShell script named `file.ps1` with a `null_resource` and using the `remote-exec` provisioner in order to run the script with the parameters (which get values defined from my `terraform.tfvars` file) as above to a Windows Server VM. Executing directly in the powershell terminal in the VM of course works. But as done many attemps to do it from Terraform configuration, there seems to be no way to achieve this. My configuration file is like the following: **main.tf** ``` resource "null_resource" "remote-exec-win-provision" { provisioner "file" { connection { type = "winrm" ... } source = "file.ps1" destination = "C:\\Users\\{var.my_user}\\file.ps1 } provisioner "remote-exec" { connection { type = "winrm" ... } inline = [<<-EOT powershell -f "C:\Users\${var.my_user}\file.ps1" -VAR1 "${var.string1}" -VAR2 "${var.string2}" -VAR3 "${var.string3}" -EXECUTE "init" EOT ] } } ``` OUTPUT: ``` ... null_resource.remote-exec-win-provision (remote-exec): C:\Users\Administrator>powershell -f "C:\Users\Administrator\file.ps1" -VAR1 "String1" -VAR2 "String2" -VAR3 "String3" null_resource.remote-exec-win-provision: Still creating... [20s elapsed] null_resource.remote-exec-win-provision: Still creating... [30s elapsed] null_resource.remote-exec-win-provision: Still creating... [40s elapsed] null_resource.remote-exec-win-provision: Still creating... [50s elapsed] ... ``` Whereas if I add the backtick in the string: ``` inline = [<<-EOT powershell -f "C:\Users\${var.my_user}\file.ps1" -VAR1 "${var.string1}" -VAR2 "${var.string2}" -VAR3 "${var.string3}" ` -VAR4 "${var.string4}" EOT ] ``` OUTPUT: ``` ... null_resource.remote-exec-windows (remote-exec): '-VAR4' is not recognized as an internal or external command, null_resource.remote-exec-windows (remote-exec): operable program or batch file. null_resource.remote-exec-win-provision (remote-exec): C:\Users\Administrator>powershell -f "C:\Users\Administrator\file.ps1" -VAR1 "String1" -VAR2 "String2" -VAR3 "String3" ` Error: "C:/Temp/terraform_406381075.cmd" exit status: 1 ``` It executes the script before the backtick (it executes correctly since my script won't show or do anything if not all variables are passed to it) and then tries to execute the final param `VAR4` as a new command. Expectected: Be able to execute the Terraform plan correctly by setting a multi-line command using a backtick with heredoc string.
Click on a version to see all relevant bugs
Terraform Integration
Learn more about where this data comes from
Bug Scrub Advisor
Streamline upgrades with automated vendor bug scrubs
BugZero Enterprise
Wish you caught this bug sooner? Get proactive today.