Comments (5)
Thanks @kaykhan, yeah this seems like something that could be accounted for in the Infracost CLI itself. We don't have a solution for that just now, but it's something we should probably consider.
from actions.
@kaykhan thanks for reporting. In the pipeline what are you passing in as inputs.TF_ROOT
?
from actions.
@kaykhan thanks for reporting. In the pipeline what are you passing in as
inputs.TF_ROOT
?
To be clear terraform-ci.yaml
is a reusable workflow (updated original post to show that). This reusable workflow is triggered via the below workflow.
TF_ROOT is applications/prod/msk
msk-prod-tf-ci.yaml
name: msk-prod-tf-ci
on:
pull_request:
paths: ['applications/prod/msk/**']
concurrency:
group: terraform
jobs:
ci:
uses: ./.github/workflows/terraform-ci.yaml
with:
TF_ROOT: applications/prod/msk
TF_APP_NAME: msk-prod
secrets: inherit
from actions.
Thanks @kaykhan. My initial thoughts are since you are passing in applications/prod/msk
as the path to Infracost, then when it runs against the base branch it is actually erroring, instead of producing an empty output since that dir doesn't exist in that branch. Since the base branch is erroring for that project then the diff command will fail as well for that project.
One way to resolve this would be to use an Infracost config file to dynamically find the project directories that exist on each given branch.
Something like this infracost.yml.tmpl
might work for your case:
version: 0.1
projects:
{{- range $project := matchPaths "applications/:env/:name" }}
- path: {{ $project._path }}
name: {{ $project.env }}/{{ $project.name }}
{{- end }}
And then updating your pipeline to generate the config.
For the base run:
infracost generate config --repo-path=. \
--template-path=infracost.yml.tmpl \
--out-file=infracost.yml
infracost breakdown --config-file=infracost.yml \
--format=json \
--out-file=/tmp/infracost-base.json
For the diff run:
infracost generate config --repo-path=. \
--template-path=infracost.yml.tmpl \
--out-file=infracost.yml
infracost diff --config-file=infracost.yml \
--format=json \
--compare-to=/tmp/infracost-base.json \
--out-file=/tmp/infracost.json
Another option that might be simpler to test initially is just to ensure the directory exists when you run the base branch, i.e.:
mkdir -p ${{ inputs.TF_ROOT }}
infracost breakdown --path=${{ inputs.TF_ROOT }} \
--format=json \
--out-file=/tmp/infracost-base.json
from actions.
Alright i'll have to try the infracost config file
another time.
Another option that might be simpler to test initially is just to ensure the directory exists when you run the base branch, i.e.:
Tested this just now and of course there is an additional error. No valid Terraform files found at path applications/prod/msk
(main branch is emtpy)
What i am thinking of doing is checking for the presence of the folder inputs.TF_ROOT
in an initial step.
- name: Check baseline exists
run: |
Based on the result of that step i can either continue to run the baseline + diff or just run the breakdown directly.
Maybe i was hoping for an extra flag that could be added to infracost diff
(ignore any errors that are in infracost-base.json and run the breakdown) to do this but i dont know if this would introduce some unforeseen conflicts.
from actions.
Related Issues (18)
- NodeJS12 actions are deprecated HOT 5
- No valid Terraform files found at the given path, try a different directory | Github action HOT 2
- github action infracost/actions/setup@v2 failing because node12 is blocked by github HOT 5
- Infracost
- Trouble with infracost diff HOT 2
- Error: No INFRACOST_API_KEY environment variable is set. HOT 10
- Running infracost action using `working-directory` HOT 6
- feature: support multi api-key HOT 2
- Increment to Node 20 HOT 2
- Error: json: cannot unmarshal number 2176460725 into Go value of type githubv4.Int HOT 2
- Action not working with Terraform Cloud HOT 12
- Infracost comment github --tag HOT 5
- GITHUB_TOKEN permissions used by this action
- Empty Infracost output HOT 8
- Not able to download modules from private hosting HOT 25
- Usage of PR_NUMBER while using reusable workflow . HOT 3
- post_condition seems to have disapeared from new GH Action HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from actions.