'How to get an error code from Terraform Apply

I need to know how to get an error code and possibly the error from a terraform apply task into a powershell variable - i am sure this is possible but I cannot work out how to do it

Here is my Terraform Apply block in Azure Devops YAML.

- script: |
              terraform apply -input=false -auto-approve ${{ parameters.environment }}.plan
            workingDirectory: $(Pipeline.Workspace)/Terraform_${{ parameters.environmentDisplayName }}
            name : terraformApply
            displayName: Terraform Apply

so how do i get a result out of that to store in a variable ?

Many thanks.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source