forked from infracost/actions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
67 lines (60 loc) · 3.15 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# This is a placeholder action, see https://github.com/infracost/actions/ for the Infracost actions and examples of how to use them.
name: Infracost Actions
description: See cloud cost estimates for Terraform in pull requests.
author: infracost
branding:
icon: trending-up
color: yellow
inputs:
api-key:
description: Your Infracost API key. It can be retrieved by running `infracost configure get api_key`. We recommend using your same API key in all environments. If you don't have one, download Infracost (https://www.infracost.io/docs/#quick-start) and run `infracost auth login` to get a free API key.
required: true
path:
description: The path that will be passed to `infracost breakdown`. This may be a path to a Terraform plan JSON or a Terraform project.
required: true
behavior:
description: The behavior to use when posting cost estimate comments. Must be one of 'update' | 'delete-and-new' | 'hide-and-new' | 'new'.
required: false
default: update
runs:
using: "composite"
steps:
# Checkout the branch you want Infracost to compare costs against, most commonly the target branch.
- name: Checkout base branch
uses: actions/checkout@v3
with:
ref: '${{ github.event.pull_request.base.ref }}'
# Install the Infracost CLI, see https://github.com/infracost/actions/tree/master/setup
# for other inputs such as version, and pricing-api-endpoint (for self-hosted users).
- name: Setup Infracost
uses: infracost/actions/setup@v2
with:
api-key: ${{ inputs.api_key }}
# Generate an Infracost output JSON from the comparison branch, so that Infracost can compare the cost difference.
- name: Generate Infracost cost estimate baseline
run: |
infracost breakdown --path=examples/terraform-directory/code \
--format=json \
--out-file=/tmp/infracost-base.json
# Checkout the PR branch with your infrastructure changes.
- uses: actions/checkout@v3
- name: Run Infracost
run: |
infracost breakdown --path=examples/terraform-directory/code \
--format=json \
--compare-to=/tmp/infracost-base.json \
--out-file=/tmp/infracost.json
- name: Post Infracost comment
run: |
# Posts a comment to the PR using the 'update' behavior.
# This creates a single comment and updates it. The "quietest" option.
# The other valid behaviors are:
# delete-and-new - Delete previous comments and create a new one.
# hide-and-new - Minimize previous comments and create a new one.
# new - Create a new cost estimate comment on every push.
# See https://www.infracost.io/docs/features/cli_commands/#comment-on-pull-requests for other options.
infracost comment github --path=/tmp/infracost.json \
--repo=$GITHUB_REPOSITORY \
--github-token=${{github.token}} \
--pull-request=${{github.event.pull_request.number}} \
--behavior=${{inputs.behavior}}