Hi,
I’m using Powershell code to trigger a workspace run using /runs API reference for HCP Terraform | Terraform | HashiCorp Developer which works without issues.
As part of that i’m trying to send a variables JSON parameter through data.attributes.variables and for some reason i’m getting
invalid HCL for variable “TF_CLI_ARGS_plan” at 1,9: Invalid character
It’s clear to me that this issue comes from the fact that the JSON value contains special characters and there is something about the conversion from Powershell to JSON which messes up the structure although when i’m printing the JSON before it looks ok.
The code i’m using to create the JSON is:
$runVariablesJSON = @(
@{
key = “TF_CLI_ARGS_plan”
value = “-target='aws_appautoscaling_policy.kafka_broker_scaling_policy[0]
'”
}
)
$runVariablesJSON = ConvertTo-Json -InputObject $runVariablesJSON |
ForEach-Object {
[System.Text.RegularExpressions.Regex]::Unescape($_) }
And the result is :
[
{
“key”: “TF_CLI_ARGS_plan”,
“value”: “-target=‘aws_appautoscaling_policy.kafka_broker_scaling_policy[0]’”
}
]
I tried many different ways to format the value but nothing seems to work.
I also didn’t find any working example for such usage so i’ll appreciate your help here.
Thanks