aws / aws-toolkit-azure-devops

AWS Toolkit for Azure DevOps
Other
235 stars 100 forks source link

Running Terraform output command returns no result #517

Open AshOfSpades opened 1 year ago

AshOfSpades commented 1 year ago

Describe the bug

When I run terraform output command in the AWSShellScript task (after a successfult terraform apply task) it returns {}, However if I group it with terraform apply it provides all the outputs without any problem.

So basically this returns just {} with no outputs whatsoever -

  - task: AWSShellScript@1
    displayName: 'display output variables'
    name: TerraformOutput
    inputs:
      workingDirectory: $(Pipeline.Workspace)/terraform
      scriptType: 'inline'
      inlineScript: |
        terraform output -json
      awsCredentials: ${{ parameters.awsCreds }}

But if instead of having a separate task for terraform apply, if I include terraform apply in the same task, it works perfectly fine.

  - task: AWSShellScript@1
    displayName: 'display output variables'
    name: TerraformOutput
    inputs:
      workingDirectory: $(Pipeline.Workspace)/terraform
      scriptType: 'inline'
      inlineScript: |
        terraform apply --auto-approve
        terraform output -json
      awsCredentials: ${{ parameters.awsCreds }}

Expected behavior

Running just terraform output should return the output as result in logs

Your Environment

AshOfSpades commented 1 year ago

Another thing which I noticed is if I add change directory command it works -

- task: AWSShellScript@1
    displayName: 'display output variables'
    name: TerraformOutput
    inputs:
      workingDirectory: $(Pipeline.Workspace)/terraform
      scriptType: 'inline'
      inlineScript: |
        cd $(Pipeline.Workspace)/terraform
        terraform output -json
      awsCredentials: ${{ parameters.awsCreds }}