forked from PinSpace-Org/GistPin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcost-estimation.yml
More file actions
84 lines (71 loc) 路 2.32 KB
/
Copy pathcost-estimation.yml
File metadata and controls
84 lines (71 loc) 路 2.32 KB
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
name: Terraform Cost Estimation
on:
pull_request:
paths:
- 'infrastructure/terraform/**'
workflow_dispatch:
permissions:
contents: read
pull-requests: write
env:
INFRACOST_API_KEY: ${{ secrets.INFRACOST_API_KEY }}
AWS_REGION: us-east-1
jobs:
estimate-costs:
name: Estimate Infrastructure Costs
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Infracost
uses: infracost/actions/setup@v3
with:
api-key: ${{ secrets.INFRACOST_API_KEY }}
- name: Generate Infracost cost estimate
id: infracost
run: |
infracost breakdown \
--path infrastructure/terraform \
--format json \
--out-file /tmp/infracost.json
# Generate human-readable summary
infracost breakdown \
--path infrastructure/terraform \
--format table \
--out-file /tmp/infracost-table.txt
- name: Post cost diff as PR comment
if: github.event_name == 'pull_request'
uses: infracost/actions/comment@v3
with:
path: /tmp/infracost.json
behavior: update
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Check budget thresholds
run: |
bash infrastructure/scripts/estimate-costs.sh \
--infracost-json /tmp/infracost.json \
--thresholds infrastructure/terraform/infracost.yml \
--github-token ${{ secrets.GITHUB_TOKEN }} \
--repo ${{ github.repository }} \
--pr ${{ github.event.pull_request.number }}
- name: Upload cost report artifact
uses: actions/upload-artifact@v4
with:
name: cost-estimate
path: |
/tmp/infracost.json
/tmp/infracost-table.txt
retention-days: 30
- name: Archive historical cost data
if: success()
run: |
mkdir -p /tmp/cost-history
TIMESTAMP=$(date -u +%Y%m%d-%H%M%S)
cp /tmp/infracost.json "/tmp/cost-history/cost-${TIMESTAMP}.json"
echo "Cost data archived for historical tracking"
- name: Upload historical archive
if: success()
uses: actions/upload-artifact@v4
with:
name: cost-history
path: /tmp/cost-history/