user2368632
user2368632

Reputation: 1073

How to pass named params to powershell script using Terraform local-exec?

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

Upvotes: 1

Views: 6189

Answers (1)

Charles Xu
Charles Xu

Reputation: 31414

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.

Upvotes: 3

Related Questions