|
| 1 | +name: "Terraform Checks" |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - develop |
| 8 | + - release/* |
| 9 | + pull_request: |
| 10 | + branches: [main, develop, release/*] |
| 11 | + types: [opened, labeled, synchronize] |
| 12 | + workflow_dispatch: |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: write |
| 16 | + pull-requests: write |
| 17 | + |
| 18 | +concurrency: |
| 19 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 20 | + cancel-in-progress: false |
| 21 | + |
| 22 | +jobs: |
| 23 | + terraform-format: |
| 24 | + name: "Terraform Code Format Checks" |
| 25 | + runs-on: large-ubuntu-latest |
| 26 | + timeout-minutes: 1 |
| 27 | + defaults: |
| 28 | + run: |
| 29 | + working-directory: ${{ inputs.working-directory }} |
| 30 | + |
| 31 | + steps: |
| 32 | + - name: Check out the repo |
| 33 | + uses: actions/checkout@v4 |
| 34 | + with: |
| 35 | + fetch-depth: 0 |
| 36 | + |
| 37 | + - name: Setup Terraform |
| 38 | + uses: hashicorp/setup-terraform@v3 |
| 39 | + with: |
| 40 | + terraform_version: ${{ vars.TF_VERSION }} |
| 41 | + terraform_wrapper: false |
| 42 | + |
| 43 | + - name: Terraform Format |
| 44 | + id: fmt |
| 45 | + run: terraform fmt -check |
| 46 | + |
| 47 | + terrascan: |
| 48 | + name: "Terrascan" |
| 49 | + runs-on: large-ubuntu-latest |
| 50 | + timeout-minutes: 2 |
| 51 | + |
| 52 | + steps: |
| 53 | + - name: Check out the repo |
| 54 | + uses: actions/checkout@v4 |
| 55 | + with: |
| 56 | + fetch-depth: 0 |
| 57 | + |
| 58 | + - name: Run Terrascan |
| 59 | + id: terrascan |
| 60 | + uses: tenable/terrascan-action@main |
| 61 | + with: |
| 62 | + iac_dir: ${{ inputs.working-directory }} |
| 63 | + iac_type: "terraform" |
| 64 | + iac_version: "v14" |
| 65 | + policy_type: "aws" |
| 66 | + only_warn: true |
| 67 | + sarif_upload: true |
| 68 | + #scm_token: ${{ secrets.ACCESS_TOKEN }} |
| 69 | + #verbose: true |
| 70 | + #non_recursive: |
| 71 | + #policy_path: |
| 72 | + #skip_rules: |
| 73 | + #config_path: |
| 74 | + #find_vulnerabilities: |
| 75 | + #webhook_url: |
| 76 | + #webhook_token: |
| 77 | + |
| 78 | + checkov: |
| 79 | + name: "Checkov" |
| 80 | + runs-on: large-ubuntu-latest |
| 81 | + timeout-minutes: 2 |
| 82 | + |
| 83 | + steps: |
| 84 | + - name: Check out the repo |
| 85 | + uses: actions/checkout@v4 |
| 86 | + with: |
| 87 | + fetch-depth: 0 |
| 88 | + |
| 89 | + - name: Run Checkov action |
| 90 | + id: checkov |
| 91 | + uses: bridgecrewio/checkov-action@master |
| 92 | + with: |
| 93 | + directory: ${{ inputs.working-directory }} |
| 94 | + quiet: true # optional: display only failed checks |
| 95 | + soft_fail: true # optional: do not return an error code if there are failed checks |
| 96 | + framework: terraform # optional: run only on a specific infrastructure {cloudformation,terraform,kubernetes,all} |
| 97 | + output_format: sarif # optional: the output format, one of: cli, json, junitxml, github_failed_only, or sarif. Default: sarif |
| 98 | + download_external_modules: true # optional: download external terraform modules from public git repositories and terraform registry |
| 99 | + log_level: DEBUG # optional: set log level. Default WARNING |
| 100 | + container_user: 1000 # optional: Define what UID and / or what GID to run the container under to prevent permission issues |
| 101 | + skip_check: CKV_TF_1,CKV2_AWS_5 # optional: skip a specific check_id. can be comma separated list |
| 102 | + #file: example/tfplan.json # optional: provide the path for resource to be scanned. This will override the directory if both are provided. |
| 103 | + #check: CKV_AWS_1 # optional: run only a specific check_id. can be comma separated list |
| 104 | + #config_file: path/this_file |
| 105 | + #baseline: cloudformation/.checkov.baseline # optional: Path to a generated baseline file. Will only report results not in the baseline. |
| 106 | + |
| 107 | + docs: |
| 108 | + runs-on: large-ubuntu-latest |
| 109 | + if: contains(github.ref, 'pull') |
| 110 | + steps: |
| 111 | + - name: Checkout |
| 112 | + uses: actions/checkout@v4 |
| 113 | + with: |
| 114 | + ref: ${{ github.event.pull_request.head.ref }} |
| 115 | + |
| 116 | + - name: Render terraform docs inside the README.md and push changes back to PR branch |
| 117 | + uses: terraform-docs/gh-actions@v1 |
| 118 | + with: |
| 119 | + working-dir: ${{ inputs.working-directory }} |
| 120 | + git-push: "true" |
| 121 | + git-commit-message: "[skip ci] terraform-docs: Update READMEs" |
| 122 | + git-push-sign-off: true |
| 123 | + |
0 commit comments