Closed GregoryOrciuch closed 8 months ago
May I know which CICD you use ? Also, how terraform is installed ?
If you are using hashicorp/setup-terraform
github action to setup terraform, ensure terraform_wrapper is set to false. Because without it, each terraform output will some extra lines. Example
Check if there is similar thing happen in your CICD setup.
@dineshba it's a just a installation of latest terraform into the amazonlinux official docker image. It's something like FROM amazonlinux2 RUN wget terraform_zip, unzip and copy to /usr/bin/ nothing there about wrapper.
I run in GitLab CI.
Could you try this once?
terraform show -json tfplan > output.json
tf-summarize output.json
# if we still get the json parse error,
# cat output.json # see if the output.json is valid json
https://docs.gitlab.com/runner/shells/
echo 'tf-summarize -tree tfplan.json' | bash
error when parsing input: unexpected end of JSON input
Temporary workaround 🏄♂️:
echo 'cat tfplan.json | tf-summarize' | bash
+--------+------+
| CHANGE | NAME |
+--------+------+
+--------+------+
cat tfplan.json | tf-summarize
Glad that we have a workaround.
I will try to reproduce this issue and understand the reason behind it. This will help me to fix this issue.
I had the same problem. But I figured out that I used a non-existing file calling tf-summarize
. Would be better to see file not found
in case the file doesn't exist.
Hi @kayman-mk. Thanks for confirming the issue.
For the non-existing file, I am getting below error
$ tf-summarize invalid.json
error reading from input: error when opening file invalid.json: open invalid.json: no such file or directory
and I am in 0.2.6
version (latest version). Could you please confirm the version once ?
@dineshba I am seeing a similar error using the latest version tag v0.3.2 installed via go.
yes, still same with 0.3.2, however point above workaround works pretty well. So you output a json plan from terraform then pipe it to tf-summarize, e.g.:
cat tfplan.json | tf-summarize -tree'
@GregoryOrciuch Yeah workaround is now working for me now. I was doing something wrong with terraform show step.
Got the same error with error when parsing input: unexpected end of JSON input
when running in GitLab CI.
When i download the exact plan file from the pipeline and run it locally using the same tf-summarize version, it works though. Seems to be either about the CI Environment or the .deb installation method.
I'm seeing this same issue on a GitHub actions runner, I've fixed it with jq '.' "${json_file_path}" | tf-summarize
.
I will try to reproduce this issue and understand the reason behind it. This will help me to fix this issue.
As a data point, I am unable to reproduce this locally on Mac OS (Sonoma 14.2.1) using tf-summarize
v0.3.6:
$ make summarize WORKSPACE=default
terraform show \
-json \
default.plan > default-plan.json
tf-summarize -v
Version: 0.3.6
tf-summarize \
-out default-summary.md \
-md \
default-plan.json
Written plan summary to default-summary.md
However, the same command(s) and plan
result in the following error when run from GitHub Actions's Ubuntu runner:
make summarize WORKSPACE=default
terraform show \
-json \
default.plan > default-plan.json
tf-summarize -v
Version: 0.3.6
tf-summarize \
-out default-summary.md \
-md \
default-plan.json
error when parsing input: unexpected end of JSON input
However, passing raw JSON via STDIN works as expected both locally on Mac OS and in GitHub Actions's Ubuntu runner:
make summarize WORKSPACE=default
terraform show \
-json \
default.plan > default-plan.json
tf-summarize -v
Version: 0.3.6
jq '.' "default-plan.json" | tf-summarize \
-md > default-summary.md
This suggests to me the possibility of an OS-specific bug/inconsistently related to how tf-summarize
reads the plan JSON file if/when it's passed a plan JSON file (as opposed to when it's passed raw JSON via STDIN). Or am I barking up the wrong tree?
👋 @dineshba I've created a quick fix for this bug via PR #64.
I've also managed to create a reproducible demo for you over in https://github.com/dineshba/tf-summarize/pull/63, whose GitHub Actions runs encounter the error when parsing input: unexpected end of JSON input
error:
https://github.com/dineshba/tf-summarize/actions/runs/7514179482/job/20456763616#step:9:6
@dineshba This issue was addressed in PR #64 (now merged), but never included in a tf-summarize GitHub release (tf-summarize
0.3.7 is currently the latest release). Would you be willing to publish a 0.3.8 release that includes the PR #64 fix to this issue, then closing this issue? Thanks!
let me release it tomorrow with another PR merged https://github.com/dineshba/tf-summarize/pull/70
let me release it tomorrow with another PR merged https://github.com/dineshba/tf-summarize/pull/70
@dineshba 👋 😄 Gentle nudge: A 0.3.8 release including PR #64 and #70 would be great!
Created the new release v0.3.8 @mdb. Thanks for ur PRs. Really appreciated.
I'm trying to fire it from CICD where I install version 0.2.2 (and tried 0.2.5 with same effect). I took the one for linux_amd64 release build, but it fail to kind of run:
but that is very legit tf.plan file.
If I run it locally (when tf-summarize is installed by macos brew it works well), so it has to be something with a release thing.
Any suggestions?