1

Trying to figure out the proper way to pass named arguments to my powershell script using terraform local-exec.

Do I need to quote delimit params in this case like so?

provisioner "local-exec" {
    command = "powershell -file ../BindCert.ps1 -certString '${var.cert_string_b64}' -certPassword '${var.cert_password}' -certThumbprint '${var.cert_thumbprint}' -certName '${var.cert_name}'"
  }

Windows 10 Powershell 5.1

1 Answer 1

3

For your issue, you can change the code like below:

provisioner "local-exec" {
        command = "powershell -file ../BindCert.ps1 -certString ${var.cert_string_b64} -certPassword ${var.cert_password} -certThumbprint ${var.cert_thumbprint} -certName ${var.cert_name}"
    }

I will show you the test which I did on my side.

PowerShell script:

param([String]$rgName = "rgName")
Get-AzResourceGroup -Name $rgName

Terraform code:

variable "test" {
    type = "string"
    default = "charles"
}

resource "null_resource" "test" {
    provisioner "local-exec" {
        command = "PowerShell -file ./test.ps1 -rgName ${var.test}"
    }
}

The screenshot of the result:

enter image description here

For more details, see Terraform local-exec Provisioner.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks ... That works well until a string param value has embedded space like 'West US' for arm location.
@user2368632 you can use "westus"
@user2368632 You can specified as -region 'West US' which is fined

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.