To save output to json file you should use custom
settings:
- task: TerraformTaskV4@4
inputs:
provider: 'azurerm'
command: 'custom'
customCommand: 'output'
outputTo: 'file'
fileName: 'output.json'
environmentServiceNameAzureRM: 'rg-the-code-manual'
Then you could use this bash snippet:
output=$(jq 'to_entries|map([.key] + [.value.value] + [.value.sensitive])' output.json | jq -c '.[]')
for row in $(echo "${output}" ); do
variable=$(echo "${row}" | jq -r '.[0]')
value=$(echo "${row}" | jq -r '.[1]')
isSecret=$(echo "${row}" | jq -r '.[2]')
echo "Creating variable ${variable}"
echo "##vso[task.setvariable variable=${variable};isSecret=${isSecret}]${value}"
done
It will create variable and secret variable based on outputs you have.