main.tf
data “external” “extDateTime” {
program = [“Powershell.exe”, “${path.module}/getDateTime.ps1”]
}
output “value” {
value = “${data.external.extDateTime.result.dateTime}”
}
Powershell file getDateTime.ps1 code
$DateTime = Get-Date -Format “yyyyMMddHHmmss”
Write-Output “{”“dateTime”": $DateTime}"
Run: terraform plan
Error: Unexpected External Program Results
│ with data.external.extDateTime,
│ on main.tf line 26, in data “external” “extDateTime”:
│ 26: program = [“Powershell.exe”, “${path.module}/getDateTime.ps1”]
│ The data source received unexpected results after executing the program.
│ Program output must be a JSON encoded map of string keys and string values.
Program: C:\WINDOWS\System32\WindowsPowerShell\v1.0\Powershell.exe
│ Result Error: invalid character ‘{’ after top-level value
My understanding is the PS script has to return JSON but I keep getting the Result Error