-
Notifications
You must be signed in to change notification settings - Fork 0
107 lines (105 loc) · 3.77 KB
/
infracost.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
name: project-costs
on:
push:
branches:
- main
pull_request:
branches:
- main
env:
PULUMI_CONFIG_PASSPHRASE: 'infracost'
jobs:
check:
name: Check resources
runs-on: ubuntu-latest
steps:
- name: Checkout source code so we can install the action locally
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.base.ref }}
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-2 # region doesn't matter for the cmd, just needs to be set
- name: Install Pulumi CLI
uses: pulumi/action-install-pulumi-cli@v2
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: v16.15.0
registry-url: https://registry.npmjs.org
- name: Setup Infracost
uses: infracost/actions/setup@v2
with:
api-key: ${{ secrets.INFRACOST_API_KEY }}
- name: Run NPM Install
working-directory: infrastructure
run: |
npm install
- name: Pulumi Preview
uses: pulumi/actions@v3
with:
command: preview
stack-name: dev
comment-on-pr: true
github-token: ${{github.token}}
work-dir: infrastructure
cloud-url: --local
upsert: true
env:
PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_ACCESS_TOKEN }}
- name: Generate Infracost cost estimate baseline
id: infracost-commands
run: |
cd infrastructure
echo $PWD
npm install
pulumi login --local
pulumi stack init dev
pulumi stack select dev
pulumi preview --show-sames
echo "pulumi preview json"
pulumi preview --show-sames -j > /tmp/preview-existing.json
echo "infracost"
../bin/infracost configure set enable_dashboard true
../bin/infracost breakdown --path /tmp/preview-existing.json \
--format=json \
--out-file=/tmp/infracost-base.json
echo "::set-output name=totalMonthlyCost::$(jq '(.totalMonthlyCost // 0) | tonumber' < /tmp/infracost-base.json)"
echo "::set-output name=shareUrl::$(jq '.shareUrl' < /tmp/infracost-base.json)"
- name: Create Awesome Badge
uses: schneegans/dynamic-badges-action@v1.2.0
with:
auth: ${{ secrets.GIST_SECRET }}
gistID: ac7574d29a44bd14994f60dd3e954247
filename: infracost-badge.json
label: Infracost Monthly Cost
message: ${{ steps.infracost-commands.outputs.totalMonthlyCost }}
color: blue
# Checkout the current PR branch so we can create a diff.
- name: Checkout PR branch
uses: actions/checkout@v2
# Generate an Infracost diff and save it to a JSON file.
- name: Generate Infracost diff
run: |
cd infrastructure
export PULUMI_CONFIG_PASSPHRASE='infracost'
pulumi login --local
npm install
pulumi preview --show-sames
echo "pulumi preview json"
pulumi preview --show-sames -j > /tmp/preview-new.json
echo "infracost"
../bin/infracost diff --path=/tmp/preview-new.json \
--format=json \
--compare-to=/tmp/infracost-base.json \
--out-file=/tmp/infracost.json
- name: Post Infracost comment
run: |
./bin/infracost comment github --path=/tmp/infracost.json \
--repo=$GITHUB_REPOSITORY \
--github-token=${{github.token}} \
--pull-request=${{github.event.pull_request.number}} \
--behavior=update