→ Back to Home
Terraform

Cost your Terraform plan JSON directly with Infracost CLI v2.4.2

Infracost has introduced a significant enhancement to its Command Line Interface (CLI), with the release of version 2.4.2. This update fundamentally changes how users can obtain cost estimates for infrastructure managed by Terraform and OpenTofu. The core of this new functionality allows users to feed the JSON output generated by the `terraform show -json` command directly into the `infracost scan` command. This process then yields a comprehensive and accurate cost breakdown of the planned infrastructure changes. This capability is particularly advantageous for development teams and organizations that already have established CI/CD pipelines producing Terraform plans. Rather than necessitating the introduction of new, dedicated cost estimation steps or re-execution of Terraform commands, Infracost can now efficiently leverage these existing plan artifacts. This means that the resulting cost estimation is based on the fully resolved state of the plan, meticulously accounting for values that only become concrete during the plan generation phase, such as those derived from data sources or dynamic lookups. The integration is designed for maximum simplicity and efficiency. Infracost operates by directly reading the plan JSON file, identifying its structure through internal keys like `format_version` and `planned_values`, irrespective of the file's name. Crucially, Infracost does not interact with the Terraform binary itself, nor does it need to download modules independently. This approach ensures that the cost analysis is consistently based on the exact resources and configurations that Terraform intends to provision, providing a high degree of accuracy and reliability. For platform teams, this feature offers a streamlined method to embed cost insights directly into the development workflow. Developers can now receive immediate financial feedback on their pull requests, ensuring that cost considerations are addressed early in the development cycle. The ability to reuse an already generated plan artifact minimizes operational overhead and guarantees that the presented cost figures align precisely with the actual deployment plan, while also incorporating any defined FinOps and tagging policies. Users are encouraged to upgrade to Infracost CLI v2.4.2 or a later version to take advantage of this powerful new functionality.
#terraform#infracost#cost management#ci/cd#infrastructure as code#finops
Read original source