Skip to content
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

terraform-compliance prints one extra line of command which makes json invalid in githib actions. How to turn this command off? #366

Closed
rupeshphuyal opened this issue Sep 3, 2020 · 13 comments
Assignees
Labels
enhancement waiting for confirmation Workaround/Fix applied, waiting for confirmation

Comments

@rupeshphuyal
Copy link

rupeshphuyal commented Sep 3, 2020

error:
`terraform-compliance -p plan.out.json -f .
terraform-compliance v1.3.3 initiated

ERROR: plan.out.json is not a valid JSON file
##[error]Process completed with exit code 1.`

`cat plan.out.json |head -1

[command]/home/ec2-user/actions-runner/_work/_temp/terraform-bin show -json plan.out`

@eerkunt
Copy link
Member

eerkunt commented Sep 4, 2020

Well, this is interesting. terraform-compliance just uses terraform to convert plan.out to plan.out.json.

Let me try to reproduce this problem

@eerkunt
Copy link
Member

eerkunt commented Sep 4, 2020

What is /home/ec2-user/actions-runner/_work/_temp/terraform-bin exactly ? I have a feeling this is a wrapper function that is written in your local ec2 instance that echo the command that it is running to STDOUT. Since terraform-compliance redirects all the output of terraform-bin show -json plan.out to plan.out.json, my guess would be that echo command within terraform-bin is also redirected with the plan.out.json as well.

@eerkunt eerkunt added waiting for confirmation Workaround/Fix applied, waiting for confirmation and removed bug labels Sep 4, 2020
@rupeshphuyal
Copy link
Author

@eerkunt @tr00p86 it works for me with the following command. /home/ec2-user/actions-runner/_work/_temp/terraform-bin is the github actions wrapper that comes automatically while using terraform libraries. Issue seems like from Github Actions it executes one extra line of [command] which redirects it out to a plan.out.json file and makes it an invalid json. if I try from cli, it doesn't generate that extra line.

terraform plan -out=plan.out
terraform show -json plan.out > plan.out.json
cat plan.out.json |head -2 |tail -1 > plan.out.json
terraform-compliance -p plan.out.json -f .

@eerkunt
Copy link
Member

eerkunt commented Sep 7, 2020

Hello @rupeshphuyal,

Thanks for trying this out, it looks like Github Action's terraform wrapper is dumping that out to STDOUT, it wouldn't be a problem it was redirected to STDERR, instead of STDOUT. 🤷‍♂️

I will have a look at this one, assuming terraform will always generate a one line json, then we might just fix this within terraform-compliance.

@eerkunt eerkunt added enhancement and removed waiting for confirmation Workaround/Fix applied, waiting for confirmation labels Sep 8, 2020
@eerkunt
Copy link
Member

eerkunt commented Oct 14, 2020

Hi @rupeshphuyal,

Please use https://github.com/marketplace/actions/terraform-compliance for github actions :)

Let me know if you have any problems.

@eerkunt eerkunt added the waiting for confirmation Workaround/Fix applied, waiting for confirmation label Oct 14, 2020
@rupeshphuyal
Copy link
Author

rupeshphuyal commented Oct 16, 2020

thank you @eerkunt. There is one problem I see

PARAMETERS="/home/runner/.local/bin/terraform-compliance"

I am using a selfhosted runner and my path is /home/ubuntu/../../terraform-compliance user and I got the following error:

line 32: /home/runner/.local/bin/terraform-compliance: No such file or directory

@eerkunt
Copy link
Member

eerkunt commented Oct 19, 2020

Thanks @rupeshphuyal. Let me also add installed_path parameter to the action as well.

Will update here soon.

terraform-compliance/github_action#3

@eerkunt
Copy link
Member

eerkunt commented Oct 19, 2020

@rupeshphuyal, can you have a try with installed_path parameter with standalone-run branch for testing ?

e.g. an example step definition ;

    steps:
      - uses: actions/checkout@v2
      - uses: hashicorp/setup-terraform@v1
      - uses: terraform-compliance/github_action@standalone-run
        with:
          installed_path: /home/ubuntu/../../terraform-compliance # or wherever it is installed

will merge to main branch and release a new version of the github action whenever you confirm.

Thanks a lot 🎉

@rupeshphuyal
Copy link
Author

rupeshphuyal commented Oct 19, 2020

@eerkunt its failing while linking if the file already exists, Could you add a line to check if the file already exists then skip creating link again?

ln: failed to create symbolic link '/usr/local/bin/terraform-compliance': File exists

if [ ! -f /usr/local/bin/terraform-compliance ]
then
sudo ln -s ~/.local/bin/terraform-compliance /usr/local/bin
fi 

or just change the following no need of the link.

PARAMETERS="/home/`id -u -n`/.local/bin/terraform-compliance"

@eerkunt
Copy link
Member

eerkunt commented Oct 21, 2020

That is a bit weird, since we are already checking if the file exists with ;

if [ ! -f /usr/local/bin/terraform-compliance ]

there. It looks like a racing condition. I will add -sf on the ln.

@eerkunt
Copy link
Member

eerkunt commented Oct 21, 2020

Sorry, looks like I misunderstood :) You were suggesting that to be added.

Would be nice it that was a PR :D

Releasing a new version of github action

@eerkunt
Copy link
Member

eerkunt commented Oct 21, 2020

Released https://github.com/terraform-compliance/github_action/releases/tag/0.3.0

You can also use main branch for the latest version.

@eerkunt
Copy link
Member

eerkunt commented Nov 5, 2020

Closing this issue since it has been waiting for a while. Please do not hesitate to create a new issue if the problem still persists. 🎉

@eerkunt eerkunt closed this as completed Nov 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement waiting for confirmation Workaround/Fix applied, waiting for confirmation
Projects
None yet
Development

No branches or pull requests

2 participants