All Projects β†’ antonbabenko β†’ Terraform Cost Estimation

antonbabenko / Terraform Cost Estimation

Licence: apache-2.0
Anonymized, secure, and free Terraform cost estimation based on Terraform plan (0.12+) or Terraform state (any version)

Projects that are alternatives of or similar to Terraform Cost Estimation

Terracognita
Reads from existing Cloud Providers (reverse Terraform) and generates your infrastructure as code on Terraform configuration
Stars: ✭ 452 (+10.51%)
Mutual labels:  terraform, devops-tools
Terraboard
🌍 πŸ“‹ A web dashboard to inspect Terraform States
Stars: ✭ 1,192 (+191.44%)
Mutual labels:  terraform, devops-tools
Kapitan
Generic templated configuration management for Kubernetes, Terraform and other things
Stars: ✭ 1,383 (+238.14%)
Mutual labels:  terraform, devops-tools
Terraform Provider Alicloud
Terraform AliCloud provider
Stars: ✭ 340 (-16.87%)
Mutual labels:  terraform
Pipe
Continuous Delivery for Declarative Kubernetes, Serverless and Infrastructure Applications
Stars: ✭ 341 (-16.63%)
Mutual labels:  terraform
Visidata
A terminal spreadsheet multitool for discovering and arranging data
Stars: ✭ 4,606 (+1026.16%)
Mutual labels:  devops-tools
Terraform Provider Oci
Terraform Oracle Cloud Infrastructure provider
Stars: ✭ 400 (-2.2%)
Mutual labels:  terraform
Terraform Aws Github Runner
Terraform module for scalable GitHub action runners on AWS
Stars: ✭ 326 (-20.29%)
Mutual labels:  terraform
Race The Web
Tests for race conditions in web applications. Includes a RESTful API to integrate into a continuous integration pipeline.
Stars: ✭ 385 (-5.87%)
Mutual labels:  devops-tools
Vscodethemes
Preview themes from the VSCode marketplace.
Stars: ✭ 374 (-8.56%)
Mutual labels:  terraform
Jql
A JSON Query Language CLI tool
Stars: ✭ 368 (-10.02%)
Mutual labels:  devops-tools
Yq
yq is a portable command-line YAML processor
Stars: ✭ 4,726 (+1055.5%)
Mutual labels:  devops-tools
Terraform Provider Vsphere
Terraform VMware vSphere provider
Stars: ✭ 380 (-7.09%)
Mutual labels:  terraform
Atlantis
Terraform Pull Request Automation
Stars: ✭ 4,236 (+935.7%)
Mutual labels:  terraform
Terraform Ls
Terraform Language Server
Stars: ✭ 389 (-4.89%)
Mutual labels:  terraform
Caf Terraform Landingzones
Cloud Adoption Framework for Azure - Terraform landing zones
Stars: ✭ 335 (-18.09%)
Mutual labels:  terraform
Terratag
Terratag is a CLI tool that enables users of Terraform to automatically create and maintain tags across their entire set of AWS, Azure, and GCP resources
Stars: ✭ 385 (-5.87%)
Mutual labels:  terraform
Magic Modules
Automatically generate Google Cloud Platform support for OSS IaaC Projects
Stars: ✭ 358 (-12.47%)
Mutual labels:  terraform
Tfnotify
A CLI command to parse Terraform execution result and notify it to GitHub
Stars: ✭ 353 (-13.69%)
Mutual labels:  terraform
Utask
Β΅Task is an automation engine that models and executes business processes declared in yaml. βœοΈπŸ“‹
Stars: ✭ 374 (-8.56%)
Mutual labels:  devops-tools

Anonymized, secure and free Terraform Cost Estimation

cost.modules.tf is entirely free cost estimation service, which is part of modules.tf that is currently in active development.

Join the mailing list on modules.tf to stay updated!

This is not an official HashiCorp product.

tldr; Post your Terraform state or plan-file (as JSON) and get cost estimation:

$ terraform state pull | curl -s -X POST -H "Content-Type: application/json" -d @- https://cost.modules.tf/

{"hourly": 0.01, "monthly": 9.07}

NB: Cost estimation uses official AWS pricing data and does not include estimates for items not specified in Terraform configurations (e.g., usage patterns, amount of API calls, bandwidth, disk I/O, spot prices, AWS discounts, etc.).

It is sometimes impossible to extract all information required for cost estimations from the Terraform plan provided, and it is more accurate to get estimates from the Terraform state file after the infrastructure is created.

See the list of supported resources.

Secrets and sensitive information

As you probably know, Terraform state and plan files may contain secrets and sensitive information which you don't want to send anywhere to get cost estimates. There is a solution that is supported, secure, and easy to put in your continuous automation process.

All you need to do is to process the Terraform state or plan file with terraform.jq file which is available in this repository.

Make sure that JQ version 1.6 is installed. Many Linux distributions install older version by default, and you need to update it as described in the official documentation.

terraform.jq creates anonymized cost keys sufficient to perform cost estimation.

For example, cost keys for a single EC2 instance and an Application Load Balancer in eu-west-1 region look like this:

{
  "keys": [
    "ec2#eu-west-1#t3.nano#shared#linux",
    "ec2#eu-west-1#alb"
  ]
}

The whole process looks like this:

# Download terraform.jq file
$ curl -sLO https://raw.githubusercontent.com/antonbabenko/terraform-cost-estimation/master/terraform.jq

# Get terraform state (or plan), extract cost keys, send them to cost estimation service
$ terraform state pull | jq -cf terraform.jq | curl -s -X POST -H "Content-Type: application/json" -d @- https://cost.modules.tf/

{"hourly": 0.01, "monthly": 9.07}

Sweet, isn't it?

Things you should know about infrastructure costs:

  • [x] How much does my infrastructure is going to cost before create?
  • [x] How much does my infrastructure cost after it is created (based on Terraform state)?
  • [x] What is the difference in the price comparing to the current infrastructure (based on Terraform plan)?
  • [x] Can I have cost estimation based on Terraform 0.7 state files? Yes, any version of Terraform state files is supported!

Example - Get cost estimates during terraform plan

The flow is like this:

  1. Plan Terraform changes into a plan-file
  2. Convert the plan-file into JSON-file
  3. Extract anonymized cost keys from the JSON-file (optional, but recommended)
  4. Send cost keys to cost.modules.tf
  5. Process response

Step 3 recommended if you don't want to send the whole JSON-file, which may contain sensitive information.

The whole command looks like this:

# Install jq and download `terraform.jq` file as described in "secrets and sensitive information" section

$ terraform plan -out=plan.tfplan > /dev/null && terraform show -json plan.tfplan | jq -cf terraform.jq | curl -s -X POST -H "Content-Type: application/json" -d @- https://cost.modules.tf/

Alternatively, you can send the whole Terraform plan-file without modification as json, too:

$ terraform plan -out=plan.tfplan > /dev/null && terraform show -json plan.tfplan | curl -s -X POST -H "Content-Type: application/json" -d @- https://cost.modules.tf/

Helpers

# Get Terraform plan as json
$ terraform plan -out=plan.tfplan > /dev/null && terraform show -json plan.tfplan > plan.json

# Get Terraform state as json (option 1)
$ terraform state pull > plan.json

# Get Terraform state as json (option 2)
$ terraform show -json > plan.json

# Do something is monthly cost is too high
$ ... | curl -s -X POST -H "Content-Type: application/json" -d @- https://cost.modules.tf/ > costs.json
$ jq 'if .monthly|tonumber > 10 then "$" else "$$$" end' costs.json

Supported resources

  1. EC2 instances (on-demand) and Autoscaling Groups (Launch Configurations and Launch Templates):
  • [x] aws_instance
  • [x] aws_autoscaling_group
  • [x] aws_launch_configuration
  • [x] aws_launch_template
  1. EC2 Fleets (on-demand)
  • [x] aws_ec2_fleet
  1. EBS Volumes, Snapshots, Snapshot Copies
  • [x] aws_ebs_volume
  • [x] aws_ebs_snapshot
  • [x] aws_ebs_snapshot_copy
  1. Elastic Load Balancing (ELB, ALB, NLB)
  • [x] aws_elb
  • [x] aws_alb / aws_lb
  1. NAT Gateways
  • [x] aws_nat_gateway

Please suggest other resources worth covering by upvoting existing issue or opening new issue.

As AWS Community Hero, I work a lot with AWS, but I am equally interested in covering other popular Terraform Providers with decent pricing API.

Like this? Please follow me and share it with your network!

@antonbabenko @antonbabenko

Consider support my work on GitHub Sponsors, Buy me a coffee, or PayPal.

Disclaimer

cost.modules.tf runs by Betajob. We don't save, publish, share with anyone data submitted to the service. No identifiable customer information used to query pricing systems (check source code of terraform.jq).

terraform-cost-estimation project managed by Anton Babenko.

This is not an official HashiCorp product. You may want to look into Terraform Cloud where similar feature exists.

License

This code is released under the Apache 2.0 License. Please see LICENSE for more details.

Copyright Β© 2020 Anton Babenko (Betajob AS)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].