using the infracost CLI, is there a way to view th...
# help
f
using the infracost CLI, is there a way to view the estimated cost using the
terraform.tfstate
file instead of the plan? basically, if a user changes values in the params file and saves, but doesn't deploy, we don't want an updated cost based on the params. we just want to know the estimated cost based on what's listed in the state file 🤞
c
Hi, you can pass a state JSON to the CLI. So use the terraform show command with the
-json
flagto convert your .tfstate to a state JSON, then call
infracost breakdown -path=tfstate.json
Have you tried the HCL parsing though? In general we don’t recommend using plan.json files anymore. You can pass the terraform project directory as
--path
and we’ll generate an estimate directly from the .tf files, i.e.
infracost breakdown --path=./my/terraform_project
. It tends to be much faster than generating a plan json.
f
so what we're doing on our backend for our platform is storing params set by customers in the UI. we don't want to run the estimator based on the params because customers can save params without deploying them
to be as accurate as possible for the costs our customers may see on their bill, we just want infracost to read the customer's statefile (stored in our s3 bucket) and generate the estimated cost from what's actually deployed
@crooked-daybreak-55253 I was able to get this working. how can i convert the breakdown into a scrapable file like JSON or something?
c
add a
--format=json
flag to the breakdown command. You can also set
--out-file=infracost.json
to put it in a file
w
@faint-oyster-21329 if you’re building an integration with Infracost, please follow these guidelines.