azure-pipelines-tasks-terraform
azure-pipelines-tasks-terraform copied to clipboard
terraform output does not support object type
Current implementation only supports string, number and bool.
https://github.com/jason-johnson/azure-pipelines-tasks-terraform/blob/6c5d1b5653d5977f2eca16d54e7ea1d7bd929825/tasks/terraform-cli/src/commands/tf-output.ts#L26
Ideally object values should also be able to be extracted (probably preserving the JSON structure for the value).
Indeed that would be very helpful. @jason-johnson are there any plans to support this?
What is the use case for this @flcdrg and @brany09 ? You can't pass an object as a variable in Azure Devops, but only strings. For what you want to do, couldn't you call e.g. jsonencode in terraform to turn the object into a string which you then pass via the output?
I suppose you could, but it does seem a bit odd that you need to force Terraform to convert the output type for you, rather than let it stay as an object.
If I use terraform output
directly (not via the extension) then the data does come through and is a JSON value that I can deal with however I like (with PowerShell or jq etc). eg.
$json = terraform output -no-color --json | ConvertFrom-Json
$database = $json.sql_server_database.value.dev
That's what I had to resort to as a workaround, but it would be nice for consistency to use the extension for this.
Ok, I see in your command that you call terraform output, which produces a string that ConvertFrom-Json turns into an object. So are you wanting the terraformCli task to return this string so you can do the same steps but without having to manually call terraform output? That doesn’t work right now?
If it didn't filter out object
type then that was what I was hoping. I'd then get an individual TF_OUT_ env var corresponding to the Terraform output
variable that I could do with what I wanted (eg. call ConvertFrom-Json or pass on to something else that was expecting JSON data).
Ok, I'll have to have a look at this. The code worked this way from the earliest history I have so I'm not sure how it got this way. In Azure Devops, variables can only be strings so it could be that just trying to export it failed.