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

[CLI] - Infracost Workflow #199

Merged
merged 1 commit into from Jul 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions pkg/cmd/tnctl/workflow/assets/github/ci.yaml.tpl
Expand Up @@ -2,8 +2,6 @@
name: Review

on:
push:
branches: [master, main]
pull_request:
types: [opened, reopened, synchronize]

Expand Down
26 changes: 18 additions & 8 deletions pkg/cmd/tnctl/workflow/assets/github/main.yaml.tpl
Expand Up @@ -148,12 +148,10 @@ jobs:
code-costs:
name: Cost Review
needs: cost-token
if: needs.cost-token.outputs.enable_infracost == 'true'
if: needs.cost-token.outputs.enable_infracost == 'true' && github.event_name == 'pull_request'
runs-on: ubuntu-latest
env:
TF_ROOT: .
outputs:
security: {{ "${{" }} steps.costs.outcome {{ "}}" }}
steps:
- name: Clone repo
uses: actions/checkout@v3
Expand All @@ -163,25 +161,37 @@ jobs:
api-key: {{ "${{" }} secrets.ORG_INFRACOST_API_KEY {{ "}}" }}
- name: Checkout base branch
uses: actions/checkout@v3
if: github.event_name == 'pull_request'
with:
ref: '{{ "${{" }} github.event.pull_request.base.ref {{ "}}" }}'
- name: Generate Infracost cost estimate baseline
if: github.event_name == 'pull_request'
- name: Checking for baseline files
id: baseline
run: |
if ls *.tf 2>/dev/null; then
echo "::set-output name=exists::true"
else
echo "::set-output name=exists::false"
fi
- name: Generate cost estimate baseline
if: steps.baseline.outputs.exists == 'true'
run: |
infracost breakdown --path=${TF_ROOT} \
--format=json \
--out-file=/tmp/infracost-base.json
- name: Checkout PR branch
if: github.event_name == 'pull_request'
uses: actions/checkout@v3
- name: Generate Infracost diff
id: costs
if: steps.baseline.outputs.exists == 'true'
run: |
infracost diff --path=${TF_ROOT} \
--format=json \
--compare-to=/tmp/infracost-base.json \
--out-file=/tmp/infracost.json
- name: Generate Infracost Cost
if: steps.baseline.outputs.exists == 'false'
run: |
infracost breakdown --path=${TF_ROOT} \
--format=json \
--out-file=/tmp/infracost.json
- name: Post Infracost comment
run: |
infracost comment github \
Expand Down