Config file
An Infracost config file can be created in each of your Terraform project repos to specify how Infracost should be run. This has three main advantages over CLI flags:
- Not having to remember or specify flags for each run.
- Ability to run Infracost with multiple Terraform projects or workspaces, and combine them into the same breakdown or diff output.
- Enable multi-project or workspace runs in CI/CD integrations.
#
UsageCreate an
infracost.yml
file in each of your Terraform project repos. Each project can have the parameters mentioned in the table below; you might find the following examples helpful.Pass the file to the
infracost breakdown
orinfracost diff
using the--config-file
option. This flag should not be confused with the--usage-file
option that is used to define resource usage estimates.
Parameter | Description | Notes |
---|---|---|
path | Path to the Terraform directory or JSON/plan file | Required |
usage_file | Path to Infracost usage file that specifies values for usage-based resources | Not required |
terraform_binary | Used to change the path to the terraform binary | Not required, e.g. can be set to terragrunt or another path |
terraform_plan_flags | Flags to pass to terraform plan with Terraform directory paths | Not required. Can be space delimited, e.g. -var-file=prod.tfvars -var-file=us-east.tfvars |
terraform_workspace | Used to set the Terraform workspace | Not required. Only set this for multi-workspace deployments, otherwise it might result in the Terraform error "workspaces not supported" |
terraform_use_state | Use Terraform state instead of generating a plan, useful if you want to see the breakdown of the current Terraform state. | Not required. Applicable when path is a Terraform directory. Can't be used with the diff command. |
terraform_cloud_host | For Terraform Enterprise users, used to override the default app.terraform.io backend host | Not required |
terraform_cloud_token | For Terraform Cloud/Enterprise users, set this to a Team API Token or User API Token so Infracost can use it to access the plan | Not required. If this environment variable is set, that'll be used for all projects instead of this parameter |
#
Examples- Multi-workspaces
- Multi-projects
- Terragrunt
If your requirements cannot be satisfied with a config file, please create an issue so we can understand the use-case. Also consider using these bash scripts that demonstrate how Infracost commands can be combined.
#
PrecedenceInfracost configuration values are chosen in this order:
- CLI flags (run
infracost --help
to see them) - Environment variables
- Config file