microsoft / azure-pipelines-terraform

Azure Pipelines tasks for installing Terraform and running Terraform commands in a build or release pipeline.
MIT License
107 stars 66 forks source link

In V3 output variables are no longer there. #83

Closed Apholisha closed 2 years ago

Apholisha commented 2 years ago

In V3 output variables are no longer there.

example:

          - task: TerraformTaskV1@3
            displayName: 'Terraform Apply'
            name: 'TerraformApply'
            inputs:
              provider: 'azurerm'
              command: 'apply'
              workingDirectory: '$(System.DefaultWorkingDirectory)/Infrastructure/'
              environmentServiceNameAzureRM: '${{ parameters.azureSubscription }}'

          - task: PowerShell@2
            name: VarDeclaration
            displayName: Declare Terraform outputs as variables
            inputs:
              targetType: 'inline'
              script: |
                Write-Host "Declaring all Terraform outputs as variables"
                Write-Host "$(TerraformApply.jsonOutputVariablesPath)"

This fails with

+ Write-Host "$(TerraformApply.jsonOutputVariablesPath)"
+               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (TerraformApply.jsonOutputVariablesPath:String) [], ParentContainsErrorR 
   ecordException
    + FullyQualifiedErrorId : CommandNotFoundException

I've tested with V2 of the apply task and that worked

mericstam commented 2 years ago

You should use V3@3 not V1@3 br Manuel

Apholisha commented 2 years ago

Ok. Thanks.

ctvanzandt42 commented 2 years ago

This is still not working - I'm using V3@3 and getting the same error.

mericstam commented 2 years ago

Sorry I misunderstood, in V3, Apply no longer set the 'jsonOutputVariablesPath' variable. You need to use the output command for that. The reason for this is we wanted Apply to be clean and not hide functionality like executing terraform output command without showing it in the log. look at: https://github.com/microsoft/azure-pipelines-terraform/tree/main/Tasks/TerraformTask/TerraformTaskV3#output-variables

So if you wish to have it the old way, V2 is your option.

Br Manuel

Apholisha commented 2 years ago

Thanks!

jlmelis commented 1 year ago

Glad I found this issue as this took me way longer to figure out than it should of. The tool tip still leads one to believe the variables are only set with Apply so that may be something to address in a future release:

image