Skip to content

Commit

Permalink
updated with both Infracost scan runs using INFRACOST_SCAN_TYPE
Browse files Browse the repository at this point in the history
  • Loading branch information
kunduso committed Jul 31, 2023
1 parent f415c4e commit 09568ae
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions .github/workflows/terraform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ on:
- '**/README.md'

permissions: read-all

#--------------------------
#
# PLEASE READ: Add a GitHub Actions variable 'INFRACOST_SCAN_TYPE' and set the value to either 'hcl_code' or 'tf_plan' depending on what type of Infracost scan desired.
#
#--------------------------
jobs:
terraform:
name: 'continuous-integration'
Expand Down Expand Up @@ -51,6 +55,35 @@ jobs:
api-key: ${{ secrets.INFRACOST_API_KEY }}
if: github.event_name == 'pull_request'

# Checkout the base branch of the pull request (e.g. main/master).
- name: Checkout base branch
if: ${{ (github.event_name == 'pull_request') && (vars.INFRACOST_SCAN_TYPE == 'hcl_code') }}
uses: actions/checkout@v3
with:
ref: '${{ github.event.pull_request.base.ref }}'

# Generate Infracost JSON file as the baseline.
- name: Generate Infracost cost estimate baseline
if: ${{ (github.event_name == 'pull_request') && (vars.INFRACOST_SCAN_TYPE == 'hcl_code') }}
run: |
infracost breakdown --path=. \
--format=json \
--out-file=/tmp/infracost-base.json
# Checkout the current PR branch so we can create a diff.
- name: Checkout PR branch
if: ${{ (github.event_name == 'pull_request') && (vars.INFRACOST_SCAN_TYPE == 'hcl_code') }}
uses: actions/checkout@v3

# Generate an Infracost diff and save it to a JSON file.
- name: Generate Infracost diff
if: ${{ (github.event_name == 'pull_request') && (vars.INFRACOST_SCAN_TYPE == 'hcl_code') }}
run: |
infracost diff --path=. \
--format=json \
--compare-to=/tmp/infracost-base.json \
--out-file=/tmp/infracost.json
# Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc.
- name: Terraform Init
id: init
Expand All @@ -75,7 +108,7 @@ jobs:

# Generate an Infracost diff and save it to a JSON file.
- name: Generate Infracost diff
if: github.event_name == 'pull_request'
if: ${{ (github.event_name == 'pull_request') && (vars.INFRACOST_SCAN_TYPE == 'tf_plan') }}
run: |
infracost diff --path=TFplan.JSON \
--format=json \
Expand Down

0 comments on commit 09568ae

Please sign in to comment.