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.
infracost.ymlfile 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.version: 0.1projects:- path: path/to/my_terraform# other params- path: another/project
Pass the file to the
infracost diffusing the
--config-fileoption. This flag should not be confused with the
--usage-fileoption that is used to define resource usage estimates.
|Path to the Terraform directory or JSON/plan file||Required|
|Path to Infracost usage file that specifies values for usage-based resources||Not required|
|Used to change the path to the ||Not required, e.g. can be set to |
|Flags to pass to ||Not required. Can be space delimited, e.g. |
|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"|
|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 |
|For Terraform Enterprise users, used to override the default ||Not required|
|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|
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.
Infracost configuration values are chosen in this order:
- CLI flags (run
infracost --helpto see them)
- Environment variables
- Config file