Skip to main content

Cost estimation

Cost estimation is a feature that enables the estimation of any Terraform-defined infrastructure. This allows organizations to keep track of any impact that a change to infrastructure could have on finances. It is leveraging Cycloid's open-source project Terracost, contributed to, and quickly integrated with any form or pipeline that uses Terraform.

Introduction

This feature relies on an internal platform task: Pricing Ingestion: Internal jobs are scheduled (e.g., weekly) to fetch pricing data from cloud providers (AWS, GCP, Azure) via API or pricing CSV files. The relevant pricing elements (e.g., instance types per region) are extracted and stored in Cycloid's database.

The cost estimation is based on our open-source tool Terracost, which reads either tfstate or HCL files. It then matches each Terraform resource with the pricing data in the database based on the parameters specified in the resource.

Prerequisites

Only if you are running your own dedicated Cycloid platform, ensure the cost estimation feature is enabled. Here

Quickstart

Testing with CLI

Using the Cycloid CLI is the easiest way to get started. The costs of any valid Terraform plan can be estimated using the terracost estimate subcommand:

$ terraform plan -out=./plan; terraform show -json ./plan > plan.json
$ cy terracost estimate --plan-path plan.json

PLANNEDCOST PRIORCOST RESOURCEESTIMATES
71.71 53.24 3

While configuring a project

When using stackforms you are able to access an estimation of the current stack you are configuring. To do so, fill all the required variables and click "Estimate cost" on the right side.

Click-Estimation

If any estimation was possible, it will then give you its output: Click-Estimation

Here you will also be able to dig into the details of that estimation, to see which parts represent each component or which got ignored: Click-Estimation

If you happened to change anything related to the project, you'll have to refresh the estimation just like you did the initial one: Click-Estimation

At the end of the configuration, you will also have access to a summary of the overall estimation/change. Click-Estimation

In Cycloid pipeline

In the context of the pipeline, you can use the Cycloid Concourse Resource that can be easily plugged in right after a terraform plan step and just before a notification mechanism. After configuring the resource, the cost estimation can be performed by specifying feature: terracost as parameter, for example:

resource_types:
- name: cycloid-resource
type: docker-image
source:
repository: cycloid/cycloid-resource
tag: latest

resources:
# Terracost resource
- name: terracost
type: cycloid-resource
source:
feature: terracost
api_key: <api-key>
env: ((env))
org: ((org))
project: ((project))

Then in your jobs section:

- put: tfstate
get_params:
output_planfile: true

- put: terracost
params:
tfplan_path: tfstate/plan.json

Example of output

Estimation