1

What I want to achieve? Store terraform output value (ip address) as env variable in git hub actions and use it during updating network security group. What I have done? Based on: Github Actions, how to share a calculated value between job steps?:

- name: Setup Terraform
  uses: hashicorp/setup-terraform@v1
- name: Extract gateway ip
  run: |
    terraform init    
    echo "IP_GAT=$(terraform output -json gatewayStaticIp | jq -r .)" >> $GITHUB_ENV
  working-directory: ${{ env.my_dir }}
- name: Update security group
  run: |   
    ip=${{ env.IP_GAT }}
    az network nsg rule update -g myGroup --nsg-name myName -n myRuleName --source-address-prefix $ip

Apparently there is some problem with jq even it seems to be exactly like in example(https://www.terraform.io/docs/commands/output.html):

Error: write EPIPE

Any ideas? Thanks in advance

Kamil Będkowski
  • 1,092
  • 4
  • 16
  • 36
  • What happens if you just run `terraform output -json gatewayStaticIp` and don't pipe it to jq? Also does your GitHub action environment have `jq` available to it? Your snippet only shows it using the `hashicorp/setup-terraform@v1` action which will only install the Terraform core binary and the GitHub Actions wrapper. – ydaetskcoR Dec 07 '20 at 16:49

1 Answers1

2

The hashicorp/setup-terraform@v1 uses a wrapper to execute terraform and messes up the output when using redirection (like you do with shell pipe). There's an issue describing the problem in their repo.

Disabling the wrapper will make it work but you'll lose some functionalities to reuse stdout, stderr and exit code from the github integration.

 - name: Terraform setup
   uses: hashicorp/setup-terraform@v1
   with:
    terraform_version: 0.13.5
    terraform_wrapper: false
fstephany
  • 2,254
  • 3
  • 25
  • 32
  • For me I can't disable the terraform_wrapper, so had to use another solution, that was suggested in the github issue. Just call the terraform output command in an intermediate step, and use the stdout in the next step, which will be clean/without any additional garbage – Vini.g.fer Apr 27 '23 at 02:23