tenable / terrascan-action

Terrascan GitHub action. Scan infrastructure as code including Terraform, Kubernetes, Helm, and Kustomize file for security best practices.
Apache License 2.0
52 stars 31 forks source link

Add outputs to show result in pull requests #31

Open robermp opened 3 years ago

robermp commented 3 years ago

The stdout of the action is empty, so to see the results in PR some lines are needed:

## Gererate action outputs
echo "::set-output name=err::$res"
command="terrascan scan ${args}"
result=$( $command 2>&1)
result="${result//'%'/'%25'}"
result="${result//$'\n'/'%0A'}"
result="${result//$'\r'/'%0D'}"

echo "::set-output name=result::$result"

With this the in the PR the output of the terrascan can be read like this:

        terrascan_log: "${{ steps.terrascan.outputs.result }}"
        terrascan_err: "${{ steps.terrascan.outputs.err }}"

Using stdout: 2021-10-21 17_13_12-add key rotation by robermp · Pull Request #29 · grupoasv_alz_aws_network and 15

Using log output: 2021-10-21 17_12_22-add key rotation by robermp · Pull Request #29 · grupoasv_alz_aws_network and 15

elijah commented 3 years ago

Hey @robermp we're trying to do something very similar - where did you insert the above code to get the output you wanted? Do you have a PR against this repo that you could make available?

robermp commented 3 years ago

Hi I insert the code just before these lines inside entrypoint.sh file:

Executing terrascan

echo "Executing terrascan as follows:" echo "terrascan scan ${args}" terrascan scan ${args} res=$?

I cant' do a PR because i'm not contributor

elijah commented 2 years ago

This worked for me. Thank you!

I was also able to use unsplash/comment-on-pr@v1.3.0 to return output to our CI system. Very cool!

cesar-rodriguez commented 2 years ago

Hi @robermp,

A PR would be much appreciated. You should be able to fork the repo and issue a PR from your fork. I'll create the PR if you can't get to it.

@elijah, do you have an example of how you're using unsplash/comment-on-pr@v1.3.0 with the terrascan-action that you could share?

elijah commented 2 years ago

Like this, to push a comment back to the PR:

  • name: comment PR for results id: results uses: unsplash/comment-on-pr@v1.3.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: msg: "${{ steps.terrascan.outputs.result }}"
robermp commented 2 years ago

Hi @cesar-rodriguez, i generate the PR: https://github.com/accurics/terrascan-action/pull/39