I am trying to use Terraform's external provider to run a PowerShell script.
I am not able to pass parameters to the script from Terraform.
I am using the following code to run the script:
variable "file_path" {
type = "string"
description = "Enter the powershell file path"
default = "../../Services/azurerm_iam_role/Powershell_Scripts/test.ps1"
}
data "external" "powershell_test" {
program = ["Powershell.exe", "${var.file_path}"]
query = {
foo = "asdf"
bar = "Hardcoded"
}
}
The following is my PowerShell script file code:
# Read stdin as string
$jsonpayload = [Console]::In.ReadLine()
# Convert to JSON
$json = ConvertFrom-Json $jsonpayload
# Access JSON values
$foo = $json.foo
$bar = $json.bar
while executing terraform apply
I got the following error:
command "Powershell.exe" produced invalid JSON: unexpected end of JSON input
Is there a fix or alternate solution?