This message was deleted.
# general
b
This message was deleted.
m
hey @kind-angle-62935 👋
👋 1
so there are a couple of different ways to do this. 1.
infracost breakdown
has a
--terraform-workspace
flag to let you specify a workspace. So in your case it would be something like:
Copy code
infracost breakdown --path path/to/code --terraform-workspace dev --out-file past.json --format json

// checkout pr branch
infracost diff --path path/to/code --terraform-workspace dev --compare-to past.json
2. you can define a config file which allows you to specify all your workspaces for a given project, e.g:
Copy code
version: 0.1

projects:
  - path: path/to/code
    terraform_workspace: dev
  - path: path/to/code
    terraform_workspace: prod
you’d then run this as follows:
Copy code
infracost breakdown --config-file infracost.yml --out-file past.json --format json

// checkout pr branch
infracost diff --config-file infracost.yml --compare-to past.json
you can find out more about config files here
k
Oh great, thank you. I think the
--terraform-workspace
flag probably works best for my usecase
m
👍
k
and to clarify, no
terraform init
is necessary prior to doing any infracost operation?
m
If you don’t mind me asking - why are you interested in doing this, if you already have a plan available?
and to clarify, no
terraform init
is necessary prior to doing any infracost operation?
correct
k
In our output, I'd like to show the total cost before this change. My understanding is i need to do a breakdown and compare-to for that, is that not correct?
(total cost before and after)
m
yes that’s correct, but if you already have a plan available, that should give you all the information you require without having to do a
compare-to
, e.g:
Copy code
terraform plan -out tfplan.binary
terraform show -json tfplan.binary > plan.json

# will show you the snapshot of costs introduced in this change
infracost breakdown --path plan.json 

# will show you the diff in costs that this change introduces
infracost diff --path plan.json
🙌 1
k
Ahhhh OK. I was confused. Thanks a lot for your help!
c
Thanks Hugo!
m
no problem lads
k
@mysterious-teacher-68276 Out of curiosity, why does the GitHub Action integration have two checkout steps?
m
It’s how we do a shallow checkout of the two branches we need (master and the PR branch)
k
Oh is this because the github action integration is not using the plan?
m
yeah
k
I getcha, thank you.
m
not using the plan is way faster, and doesn’t require credentials, so we favour that for VCS systems
k
I see I see. I missed it in the docs when it was explaining these different ways to accomplish these steps.
👍 1