1

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.

0

1 Answer 1

4

For this issue ,it can be done with a simple output and powershell script:

1.Specify the output variable from terraform task

enter image description here

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:

enter image description here

Here is the reference you can refer to.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the answer @Hugh Lin - MSFT - what will the variables names be in this case ?
The variable name is $($prop.Name), which is defined in setvariable.
@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 :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.