-
Notifications
You must be signed in to change notification settings - Fork 236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Raw output when using wrapper with $()
in bash
#20
Comments
Same It renders |
Came to this comment since I am dealing with the same issue. I was a little confused by @allejo's comment on wrapper, but was able to figure it out: If you want to be able to use - name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_wrapper: false |
If disabling the wrapper is not good for your case you can use this horrible workaround:
|
Run into this too. And I need the wrapper so disabling it is not an option. setup-terraform/lib/setup-terraform.js Lines 122 to 128 in 4c5048f
So another workaround will be changing terraform to terraform-bin to use the terraform binary directly.
In the context of @allejo 's issue, it should be |
This ate up a good chunk of time for me. IMO this is surprising/unexpected behavior, and I'd love it if we disabled the wrapper by default. That said, it sounds like plenty of folks do derive value from the wrapper, though if you just throw |
I have a workflow with some steps that leverage the features of the wrapper but I also needed the clean JSON plan output to use with infracost. This is the workaround that I used: - name: Terraform show
id: show-json
if: github.ref != 'refs/heads/main'
# terraform_wrapper adds GH-related text to stdout (debug, outputs, etc.)
# the wrapper is required for other steps (fmt, init, validate) so it cannot be disabled
# use sed to pull the second line of the file which, for this command, is the only line that is valid
run: terraform show -json terraform.plan | sed -n 2p > terraform.plan.json This will have to be adjust if the wrapper ever changes but this is good enough for now. |
I also ran into this issue, but for some reason doing the An example of what I had to do: - name: Extract SDK layer arn
id: extract-arn
run: terraform output -raw arn
- name: Set SDK layer version output
# NOTE: If I try to do this and the above step in the same step,
# I get garbage wrapper text in my variable!
run: |
arn_version=$(echo "${{ steps.extract-arn.outputs.stdout }}" | cut -d : -f 8)
echo $arn_version |
I ran into this issue too, disabled the wrapper to work around it. I don't use the wrapper so wasn't an issue. Posting to help keep this issue alive as this was unexpected behavior that took a bit to sort out. My vote would be to disable terraform_wrapper by default. If not a good option for most, next best thing would be a flag to the wrapper that disables the stdout capture/mod. Example:
|
When handling expected failures with |
I think it's rather incredible that this isn't mentioned in the Readme at all as well. Generating Terraform Outputs for use in later steps is a very likely use case in a CICD situation. Dumping an entire stdout and filtering through that to get your Output value is not really practical. |
FYI, to temporarily disable - unwrap - the wrapper, I use this Bash script fragment: if type -p terraform-bin ; then
echo "Unwrapping terraform wrapper :-)"
shopt -s expand_aliases
unalias -a
alias terraform=terraform-bin
fi |
terraform-bin output instance_id |
- refer to hashicorp/setup-terraform#20 Signed-off-by: ishuar <ishansharma887@gmail.com>
- refer to hashicorp/setup-terraform#20 Signed-off-by: ishuar <ishansharma887@gmail.com>
Presently using a command such as `terraform output -json | jq` does not work with the wrapper enabled, as it is by default. In order to consume terraform's output having set it up with this Action, it is necessary either to disable the wrapper (`with: terraform_wrapper: false`) or run it in its own Actions step with an explicit `id` (e.g. `id: foo`) so that it can be referred to and consumed (`${{steps.foo.outputs.stdout}}` et al.) in later steps. This seems to be the result of much confusion (issues passim) and is not at all easy (hashicorp#338) to debug/diagnose and come to the realisation that it's due to the wrapper, or even that such a thing exists. This commit aims to address the issue by passing through stdout & stderr, so that they're available in Unix pipelines and variable assignment etc. as expected within a single step, while still retaining the wrapper's listening behaviour to provide them as Actions outputs. Closes hashicorp#20, hashicorp#80, hashicorp#85, hashicorp#149, hashicorp#338, and probably more.
Presently using a command such as `terraform output -json | jq` does not work with the wrapper enabled, as it is by default. In order to consume terraform's output having set it up with this Action, it is necessary either to disable the wrapper (`with: terraform_wrapper: false`) or run it in its own Actions step with an explicit `id` (e.g. `id: foo`) so that it can be referred to and consumed (`${{steps.foo.outputs.stdout}}` et al.) in later steps. This seems to be the result of much confusion (issues passim) and is not at all easy (hashicorp#338) to debug/diagnose and come to the realisation that it's due to the wrapper, or even that such a thing exists. This commit aims to address the issue by passing through stdout & stderr, so that they're available in Unix pipelines and variable assignment etc. as expected within a single step, while still retaining the wrapper's listening behaviour to provide them as Actions outputs. Closes hashicorp#20, hashicorp#80, hashicorp#85, hashicorp#149, hashicorp#338, and probably more.
Presently using a command such as `terraform output -json | jq` does not work with the wrapper enabled, as it is by default. In order to consume terraform's output having set it up with this Action, it is necessary either to disable the wrapper (`with: terraform_wrapper: false`) or run it in its own Actions step with an explicit `id` (e.g. `id: foo`) so that it can be referred to and consumed (`${{steps.foo.outputs.stdout}}` et al.) in later steps. This seems to be the result of much confusion (issues passim) and is not at all easy (hashicorp#338) to debug/diagnose and come to the realisation that it's due to the wrapper, or even that such a thing exists. @austinvalle identified the issue as being due to the `@actions/exec` package writing the spawned command to stdout (along with then its actual stdout). This has previously been reported upstream in actions/toolkit#649; I've proposed actions/toolkit#1573 to fix it. This commit aims to address the issue for `setup-terraform` in the meantime by silencing `@actions/exec` and then writing out to stdout & stderr from the listener buffers, which it writes to without this additional logging. Closes hashicorp#20, hashicorp#80, hashicorp#85, hashicorp#149, hashicorp#338, and probably more.
Presently using a command such as `terraform output -json | jq` does not work with the wrapper enabled, as it is by default. In order to consume terraform's output having set it up with this Action, it is necessary either to disable the wrapper (`with: terraform_wrapper: false`) or run it in its own Actions step with an explicit `id` (e.g. `id: foo`) so that it can be referred to and consumed (`${{steps.foo.outputs.stdout}}` et al.) in later steps. This seems to be the result of much confusion (issues passim) and is not at all easy (hashicorp#338) to debug/diagnose and come to the realisation that it's due to the wrapper, or even that such a thing exists. @austinvalle identified the issue as being due to the `@actions/exec` package writing the spawned command to stdout (along with then its actual stdout). This has previously been reported upstream in actions/toolkit#649; I've proposed actions/toolkit#1573 to fix it. This commit aims to address the issue for `setup-terraform` in the meantime by silencing `@actions/exec` and then writing out to stdout & stderr from the listener buffers, which it writes to without this additional logging. Closes hashicorp#20, hashicorp#80, hashicorp#85, hashicorp#149, hashicorp#338, and probably more.
Presently using a command such as `terraform output -json | jq` does not work with the wrapper enabled, as it is by default. In order to consume terraform's output having set it up with this Action, it is necessary either to disable the wrapper (`with: terraform_wrapper: false`) or run it in its own Actions step with an explicit `id` (e.g. `id: foo`) so that it can be referred to and consumed (`${{steps.foo.outputs.stdout}}` et al.) in later steps. This seems to be the result of much confusion (issues passim) and is not at all easy (hashicorp#338) to debug/diagnose and come to the realisation that it's due to the wrapper, or even that such a thing exists. @austinvalle identified the issue as being due to the `@actions/exec` package writing the spawned command to stdout (along with then its actual stdout). This has previously been reported upstream in actions/toolkit#649; I've proposed actions/toolkit#1573 to fix it. This commit aims to address the issue for `setup-terraform` in the meantime by silencing `@actions/exec` and then writing out to stdout & stderr from the listener buffers, which it writes to without this additional logging. Closes hashicorp#20, hashicorp#80, hashicorp#85, hashicorp#149, hashicorp#338, and probably more.
* Fix output malformed when wrapper enabled Presently using a command such as `terraform output -json | jq` does not work with the wrapper enabled, as it is by default. In order to consume terraform's output having set it up with this Action, it is necessary either to disable the wrapper (`with: terraform_wrapper: false`) or run it in its own Actions step with an explicit `id` (e.g. `id: foo`) so that it can be referred to and consumed (`${{steps.foo.outputs.stdout}}` et al.) in later steps. This seems to be the result of much confusion (issues passim) and is not at all easy (#338) to debug/diagnose and come to the realisation that it's due to the wrapper, or even that such a thing exists. @austinvalle identified the issue as being due to the `@actions/exec` package writing the spawned command to stdout (along with then its actual stdout). This has previously been reported upstream in actions/toolkit#649; I've proposed actions/toolkit#1573 to fix it. This commit aims to address the issue for `setup-terraform` in the meantime by silencing `@actions/exec` and then writing out to stdout & stderr from the listener buffers, which it writes to without this additional logging. Closes #20, #80, #85, #149, #338, and probably more. * add test for stdout with jq * update test name * remove debug lines and add changelog * add additional note about the bug fix to wrapper --------- Co-authored-by: Austin Valle <austinvalle@gmail.com>
This issue will be fixed in an upcoming |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
I was in the process of migrating our workflows to use this new action for setting up terraform when I ran into this... behavior? bug? I'm not sure what to call it.
When
terraform_wrapper
is set totrue
(the default behavior) in this action, it breaks what would be considered normal behavior in bash.Take the following example from a step in a workflow:
The contents of the file created would be this:
Instead of the expected:
The only way to fix this problem is to set
terraform_wrapper
to false. I'm not sure if this is something that can be fixed/changed? Otherwise, I think it would be a good idea to put this somewhere in the README./cc @petersin0422
The text was updated successfully, but these errors were encountered: