aws-toolkit-azure-devops icon indicating copy to clipboard operation
aws-toolkit-azure-devops copied to clipboard

Running Terraform output command returns no result

Open AshOfSpades opened this issue 2 years ago • 1 comments

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

  • On-prem or cloud based?: AWS cloud
  • AWS Toolkit for Azure DevOps version: 1.13.0

AshOfSpades avatar Apr 27 '23 07:04 AshOfSpades

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 }}

AshOfSpades avatar Apr 28 '23 07:04 AshOfSpades