{"id":13505596,"url":"https://github.com/antonbabenko/terraform-cost-estimation","last_synced_at":"2025-04-04T15:10:29.665Z","repository":{"id":40583665,"uuid":"260142643","full_name":"antonbabenko/terraform-cost-estimation","owner":"antonbabenko","description":"Anonymized, secure, and free Terraform cost estimation based on Terraform plan (0.12+) or Terraform state (any version)","archived":false,"fork":false,"pushed_at":"2023-06-01T13:14:47.000Z","size":426,"stargazers_count":703,"open_issues_count":10,"forks_count":65,"subscribers_count":23,"default_branch":"master","last_synced_at":"2025-03-28T14:11:09.619Z","etag":null,"topics":["cost-control","cost-estimation","devops-tools","infrastructure-costs","terraform","terraform-plans","terraform-state"],"latest_commit_sha":null,"homepage":"https://terraform-cost-estimation.com/","language":"jq","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/antonbabenko.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-04-30T07:28:17.000Z","updated_at":"2025-03-20T09:17:35.000Z","dependencies_parsed_at":"2024-01-03T02:25:49.062Z","dependency_job_id":"ea31b7b4-625d-4bde-becf-7e20bb237e11","html_url":"https://github.com/antonbabenko/terraform-cost-estimation","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonbabenko%2Fterraform-cost-estimation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonbabenko%2Fterraform-cost-estimation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonbabenko%2Fterraform-cost-estimation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonbabenko%2Fterraform-cost-estimation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/antonbabenko","download_url":"https://codeload.github.com/antonbabenko/terraform-cost-estimation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247198463,"owners_count":20900080,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cost-control","cost-estimation","devops-tools","infrastructure-costs","terraform","terraform-plans","terraform-state"],"created_at":"2024-08-01T00:01:10.417Z","updated_at":"2025-04-04T15:10:29.645Z","avatar_url":"https://github.com/antonbabenko.png","language":"jq","funding_links":["https://github.com/sponsors/antonbabenko","https://www.buymeacoffee.com/antonbabenko","https://www.paypal.me/antonbabenko"],"categories":["jq","Tutorials and Blog Posts"],"sub_categories":["Miscellaneous"],"readme":"#  Anonymized, secure and free Terraform Cost Estimation\n\n`cost.modules.tf` is entirely free cost estimation service, which is part of [modules.tf](https://modules.tf) that is currently in active development.\n\nJoin the mailing list on [modules.tf](https://modules.tf) to stay updated!\n\nThis is not an official HashiCorp product.\n\n## tldr; Post your Terraform state or plan-file (as JSON) and get cost estimation:\n\n```\n$ terraform state pull | curl -s -X POST -H \"Content-Type: application/json\" -d @- https://cost.modules.tf/\n\n{\"hourly\": 0.01, \"monthly\": 9.07}\n```\n\nNB: Cost estimation uses official [AWS pricing data](https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/price-changes.html) 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.).\n\nIt 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.\n\nSee the list of [supported resources](#supported-resources).\n\n\n## Secrets and sensitive information\n\nAs 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.\n\nAll you need to do is to process the Terraform state or plan file with [terraform.jq file](https://github.com/antonbabenko/terraform-cost-estimation/blob/master/terraform.jq) which is available in this repository.\n\n\u003e 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](https://stedolan.github.io/jq/download/).\n\n`terraform.jq` creates **anonymized cost keys** sufficient to perform cost estimation.\n \nFor example, cost keys for a single EC2 instance and an Application Load Balancer in `eu-west-1` region look like this:\n```\n{\n  \"keys\": [\n    \"ec2#eu-west-1#t3.nano#shared#linux\",\n    \"ec2#eu-west-1#alb\"\n  ]\n}\n```\n\nThe whole process looks like this:\n\n```\n# Download terraform.jq file\n$ curl -sLO https://raw.githubusercontent.com/antonbabenko/terraform-cost-estimation/master/terraform.jq\n\n# Get terraform state (or plan), extract cost keys, send them to cost estimation service\n$ terraform state pull | jq -cf terraform.jq | curl -s -X POST -H \"Content-Type: application/json\" -d @- https://cost.modules.tf/\n\n{\"hourly\": 0.01, \"monthly\": 9.07}\n```\n\nSweet, isn't it?\n\n\n## Things you should know about infrastructure costs:\n\n- [x] How much does my infrastructure is going to cost **before**  create?\n- [x] How much does my infrastructure cost **after** it is created (based on Terraform state)?\n- [x] What is the **difference in the price** comparing to the current infrastructure (based on Terraform plan)?\n- [x] Can I have cost estimation based on Terraform 0.7 state files? Yes, any version of Terraform state files is supported!\n\n\n## Example - Get cost estimates during `terraform plan`\n\nThe flow is like this:\n\n1. Plan Terraform changes into a plan-file\n2. Convert the plan-file into JSON-file\n3. Extract anonymized cost keys from the JSON-file (optional, but recommended)\n4. Send cost keys to cost.modules.tf\n5. Process response\n\nStep 3 recommended if you don't want to send the whole JSON-file, which may contain sensitive information.\n\nThe whole command looks like this:\n\n```\n# Install jq and download `terraform.jq` file as described in \"secrets and sensitive information\" section\n\n$ terraform plan -out=plan.tfplan \u003e /dev/null \u0026\u0026 terraform show -json plan.tfplan | jq -cf terraform.jq | curl -s -X POST -H \"Content-Type: application/json\" -d @- https://cost.modules.tf/\n```\n\nAlternatively, you can send the whole Terraform plan-file without modification as json, too:\n\n```\n$ terraform plan -out=plan.tfplan \u003e /dev/null \u0026\u0026 terraform show -json plan.tfplan | curl -s -X POST -H \"Content-Type: application/json\" -d @- https://cost.modules.tf/\n```\n\n\n### Helpers\n\n```\n# Get Terraform plan as json\n$ terraform plan -out=plan.tfplan \u003e /dev/null \u0026\u0026 terraform show -json plan.tfplan \u003e plan.json\n\n# Get Terraform state as json (option 1)\n$ terraform state pull \u003e plan.json\n\n# Get Terraform state as json (option 2)\n$ terraform show -json \u003e plan.json\n\n# Do something is monthly cost is too high\n$ ... | curl -s -X POST -H \"Content-Type: application/json\" -d @- https://cost.modules.tf/ \u003e costs.json\n$ jq 'if .monthly|tonumber \u003e 10 then \"$\" else \"$$$\" end' costs.json\n```\n\n\n## Supported resources\n\n1. EC2 instances (on-demand) and Autoscaling Groups (Launch Configurations and Launch Templates):\n- [x] aws_instance\n- [x] aws_autoscaling_group\n- [x] aws_launch_configuration\n- [x] aws_launch_template\n\n2. EC2 Fleets (on-demand)\n- [x] aws_ec2_fleet\n\n3. EBS Volumes, Snapshots, Snapshot Copies\n- [x] aws_ebs_volume\n- [x] aws_ebs_snapshot\n- [x] aws_ebs_snapshot_copy\n\n4. Elastic Load Balancing (ELB, ALB, NLB)\n- [x] aws_elb\n- [x] aws_alb / aws_lb\n\n5. NAT Gateways\n- [x] aws_nat_gateway\n\n\nPlease suggest other resources worth covering by upvoting existing issue or opening new issue.\n\nAs [AWS Community Hero](https://aws.amazon.com/developer/community/heroes/anton-babenko/), I work a lot with AWS, but I am equally interested in covering other popular [Terraform Providers](https://www.terraform.io/docs/providers/) with decent pricing API.\n\n\n## Like this? Please follow me and share it with your network!\n\n[![@antonbabenko](https://img.shields.io/twitter/follow/antonbabenko.svg?style=flat\u0026label=Follow%20@antonbabenko%20on%20Twitter)](https://twitter.com/antonbabenko)\n[![@antonbabenko](https://img.shields.io/github/followers/antonbabenko?style=flat\u0026label=Follow%20@antonbabenko%20on%20Github)](https://github.com/antonbabenko)\n\nConsider support my work on [GitHub Sponsors](https://github.com/sponsors/antonbabenko), [Buy me a coffee](https://www.buymeacoffee.com/antonbabenko), or [PayPal](https://www.paypal.me/antonbabenko).\n\n\n## Disclaimer\n\n`cost.modules.tf` runs by [Betajob](https://www.betajob.com). We don't save, publish, share with anyone data submitted to the service.\nNo identifiable customer information used to query pricing systems (check source code of [terraform.jq](https://github.com/antonbabenko/terraform-cost-estimation/blob/master/terraform.jq)).\n\n`terraform-cost-estimation` project managed by [Anton Babenko](https://github.com/antonbabenko).\n\nThis is not an official HashiCorp product. You may want to look into [Terraform Cloud](https://www.terraform.io/docs/cloud/) where similar feature exists.\n\n\n## License\n\nThis code is released under the Apache 2.0 License. Please see LICENSE for more details.\n\nCopyright © 2020 Anton Babenko (Betajob AS)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantonbabenko%2Fterraform-cost-estimation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantonbabenko%2Fterraform-cost-estimation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantonbabenko%2Fterraform-cost-estimation/lists"}