How to output Terraform output file in Azure DevOps in release pipeline. I am using Run Terraform task in Release pipeline. I have a output file in Repo which outputs public IPs. I want to store it as Variable which can be used in further tasks.
1 Answer
For this issue ,it can be done with a simple output and powershell script:
1.Specify the output variable from terraform task
2.Create a PowerShell step in your release and insert the following script:
$json = Get-Content $env:jsonPath | Out-String | ConvertFrom-Json
foreach($prop in $json.psobject.properties) {
Write-Host("##vso[task.setvariable variable=$($prop.Name);]$($prop.Value.value)")
}
This will automatically create a variable for every output provided by the terraform script.
Make sure you have provided the environment variable jsonPath like this:
Here is the reference you can refer to.
3 Comments
Renm
Thanks for the answer @Hugh Lin - MSFT - what will the variables names be in this case ?
Hugh Lin
The variable name is
$($prop.Name), which is defined in setvariable.Hugh Lin
@Abhishek Singh If this solution is helpful to you,could you accept it as an answer? To accept an answer, please click the "check mark" button underneath the vote buttons. Please view this image. This will help other members who get the same issue to find the solution easily . Have a nice day :)

