This message was deleted.
# general
b
This message was deleted.
w
Hi @loud-optician-49310 - would something like this work? 1. Create an infracost config file, called infracost.yml, with the AWS profiles that should be used for each dir (this can have any required envs too, for example in CI/CD we don’t use PROFILES so we have other envs to set creds in this file too, but those are ignored in dev on my machine):
Copy code
# infracost.yml
version: 0.1
projects:
  - path: dev
    env:
      AWS_PROFILE: infracost-dev
  - path: prod
    env:
      AWS_PROFILE: infracost-prod
2. Run with `--config-file`:
Copy code
- id: infracost_breakdown
  args:
    - --args=--config-file=/path/to/infracost.yml
l
ahh very much so. Let me give that a go. Thanks
👍 1
ok so I'd basically have to define every workspace it looks like
Copy code
# infracost.yml
version: 0.1
projects:
  - path: workspace/ops/stg/
    env:
      AWS_PROFILE: stg
  - path: workspace/ops/prod/
    env:
      AWS_PROFILE: prod
unless I can figure out a better way to pass in the changed files only into the call
plus it then will run on any workspace change (which isn't quite what we want)
Trying to figure out how to pass the file changed path as a list to pro-commit I think
Copy code
- id: infracost_breakdown
  args:
    - --args=--path=./env/dev
  verbose: true # Always show costs
then we could just have a config file in each <WORKSPACE>/<ENV>
w
I’m not sure if it was clear from the CLI/docs, but Infracost currently needs a Terraform plan JSON file, so I suppose the challenge is how to detect a workspace that has changed and only generate the plan for that? otherwise, is it too slow to run on your machine? (this isn’t an issue in CI/CD - which is what most users do)
l
yea, sort of makes sense to just use it as a CICD thing. Was trying to get it into the pre-commit for visabililty but no big deal
w
Looking at the pre-commit readme, I wonder if you can have 1 infracost.yml per terraform dir/workspace: stg:
Copy code
# workspace/ops/stg/infracost.yml
version: 0.1
projects:
  - path: .
    env:
      AWS_PROFILE: stg
prod:
Copy code
# workspace/ops/prod/infracost.yml
version: 0.1
projects:
  - path: .
    env:
      AWS_PROFILE: prod
Then in pre-commit, you can then use their magic
__GIT_WORKING_DIR__
option:
Copy code
- --args=--config-file=__GIT_WORKING_DIR__/infracost.yml
Would that be any better?
l
ohh let me try that. I was having a hard time tracking down the macros
I'm wondering if that macro just hasn't been added to the infracost hook yet https://github.com/antonbabenko/pre-commit-terraform/pull/264
Thanks for pointing me in the right direction 🙂 https://github.com/antonbabenko/pre-commit-terraform/issues/334
w
Awesome! Anton and Maksym from pre-commit-terraform are cool guys, hopefully they can unblock that. @crooked-daybreak-55253 ^ is an interesting discussion as it a use-case for having per-project/dir/workspace config files vs a repo-level config file (similar ideas to what we discussed in this issue).