{"id":13505830,"url":"https://github.com/cycloidio/terracost","last_synced_at":"2025-04-08T04:10:35.738Z","repository":{"id":37082195,"uuid":"301734306","full_name":"cycloidio/terracost","owner":"cycloidio","description":"Cloud cost estimation for Terraform in your CLI","archived":false,"fork":false,"pushed_at":"2024-10-24T09:36:15.000Z","size":15485,"stargazers_count":293,"open_issues_count":23,"forks_count":31,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-10-25T05:29:57.030Z","etag":null,"topics":["aws","azure","cloud","cost-estimation","cost-management","cost-optimization","gcp","infrastructure-as-code","terraform","terraform-cost-estimation"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cycloidio.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-06T13:22:24.000Z","updated_at":"2024-10-17T14:11:51.000Z","dependencies_parsed_at":"2024-01-07T10:51:06.950Z","dependency_job_id":"deb26e90-1ade-40dc-b324-2210b4232baa","html_url":"https://github.com/cycloidio/terracost","commit_stats":null,"previous_names":["cycloidio/cost-estimation"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cycloidio%2Fterracost","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cycloidio%2Fterracost/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cycloidio%2Fterracost/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cycloidio%2Fterracost/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cycloidio","download_url":"https://codeload.github.com/cycloidio/terracost/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247773719,"owners_count":20993639,"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":["aws","azure","cloud","cost-estimation","cost-management","cost-optimization","gcp","infrastructure-as-code","terraform","terraform-cost-estimation"],"created_at":"2024-08-01T00:01:14.893Z","updated_at":"2025-04-08T04:10:35.716Z","avatar_url":"https://github.com/cycloidio.png","language":"Go","funding_links":[],"categories":["Go","Tools","Cloud cost management","Repositories"],"sub_categories":["Community providers","Threat modelling"],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"docs/terracost-logo_icon-color.png\" width=\"150\" alt=\"TerraCost logo\"\u003e\n\u003c/p\u003e\n\n# TerraCost\n\n[![PkgGoDev](https://pkg.go.dev/badge/github.com/cycloidio/terracost)](https://pkg.go.dev/github.com/cycloidio/terracost)\n\nGo library for estimating Terraform costs using ingested cloud vendor prices. It is meant to be imported and used by programs (API's or standalone) with access to a MySQL-compatible database and the Internet.\n\n## Installation\n\n```shell\ngo mod edit -replace github.com/hashicorp/terraform=github.com/cycloidio/terraform@v1.4.6-cy \u0026\u0026 go get github.com/cycloidio/terracost\n```\n\nWe need to do a `-replace` because of https://github.com/golang/go/issues/30354#issuecomment-466557015. We have a custom fork of Terraform and in order\nto use TerraCost it needs to be replaced when importing also.\n\n## Requirements\n\n- Go 1.22 or newer\n- MySQL database\n\n## Provider support\n\nCurrently Terracost supports the following providers and with an specific subset of resources from them:\n* [AWS](./docs/aws.md#list-of-supported-resources-and-attributes)\n* [Google](./docs/google.md#list-of-supported-resources-and-attributes)\n* [AzureRM](./docs/azurerm.md#list-of-supported-resources-and-attributes)\n\n### Google Credentials\n\nTo be able to ingest the pricing data from Google the credentials needed have to have access to [Compute Engine API](https://console.cloud.google.com/apis/library/compute.googleapis.com) and have also billing enabled. This is needed to be able to fetch the Machine Types, for the SKUs we would only need an normal set of credentials (or even API Key) but as we need both we have to use the more complex one. If you do not know how to activate those permissions, just use the credentials and the import will fail and on the logs will inform of what is missing and how to activate it.\n\n## Usage\n\n### Migrating the database\n\n```go\ndb, err := sql.Open(\"mysql\", \"root:password@tcp(IP:3306)/databasename?multiStatements=true\")\n\n// Can be called on every start of your program, it does nothing if the migrations\n// have been executed already.\nerr = mysql.Migrate(context.Background(), db, \"pricing_migrations\")\n```\n\n### Ingesting pricing data\n\n```go\ndb, err := sql.Open(\"mysql\", \"root:password@tcp(IP:3306)/databasename?multiStatements=true\")\nbackend := mysql.NewBackend(db)\n\n// service can be \"AmazonEC2\" or \"AmazonRDS\"\n// region is any AWS region, e.g. \"us-east-1\" or \"eu-west-3\"\ningester, err := aws.NewIngester(service, region)\nerr = terracost.IngestPricing(context.Background(), backend, ingester)\n```\n\n### Tracking ingestion progress\n\nWe're using the `github.com/machinebox/progress` library for tracking ingestion progress.\n\n1. Create a channel that will receive progress updates and set up a goroutine (it will print the bytes ingested out of bytes total and remaining time each time progress update is sent on the channel):\n\n```go\nprogressCh := make(chan progress.Progress, 0)\n\ngo func() {\n\tfor p := range progressCh {\n\t\t// Check the docs for all available methods: https://pkg.go.dev/github.com/machinebox/progress#Progress\n\t\tfmt.Printf(\"%d / %d (%s remaining)\\n\", p.N(), p.Size(), p.Remaining().String())\n\t}\n}()\n```\n\n2. Initialize an ingester capable of tracking progress (in this example the channel will receive an update every 5 seconds):\n\n```go\ningester, err := aws.NewIngester(service, region, aws.WithProgress(progressCh, 5*time.Second))\n```\n\n3. Use the ingester as in the previous section.\n\n### Estimating a Terraform plan\n\nPlan estimation is possible after all the relevant pricing data have been ingested and stored in the\ndatabase.\n\n1. Generate a plan using `terraform` and convert it to JSON:\n\n```shell\nterraform plan -out update.tfplan\nterraform show -json update.tfplan \u003e tfplan.json\n```\n\n2. Read the plan file, estimate it and show the resource differences:\n\n```go\ndb, err := db.Open(\"mysql\", \"...\")\nbackend := mysql.NewBackend(db)\n\nfile, err := os.Open(\"path/to/tfplan.json\")\nplan, err := terracost.EstimateTerraformPlan(context.Background(), backend, file)\n\nfor _, res := range plan.ResourceDifferences() {\n  priorCost, err := res.PriorCost()\n  plannedCost, err := res.PlannedCost()\n\n  fmt.Printf(\"%s: %s -\u003e %s\\n\", res.Address, priorCost, plannedCost)\n}\n```\n\nCheck the documentation for all available fields.\n\n### Usage estimation\n\nSome resources do cannot be estimated just by the configuration and need some extra usage information, for that we have some default on `usage/usage.go` which are also all the resources and options we support currently and can be overwritten when estimating if passing a custom one instead of the custom Default one.\n\n## Examples\n\nFor more examples, please check [examples](examples/README.md).\n\n## Contributing\n\nFor Contributing Guide, please read [CONTIBUTING.md](CONTRIBUTING.md).\n\n## License\n\nThis project is licensed under the MIT license. Please see [LICENSE](LICENSE) for more details.\n\n## Meet Cycloid\n\n[Cycloid](https://www.cycloid.io/) is a hybrid cloud DevOps collaboration platform providing end-to-end frameworks to accelerate and industrialize software delivery.\n\nAs of now, we have three open-source tools:\n\n* [TerraCognita](https://github.com/cycloidio/terracognita): Read from your existing cloud providers and generate IaC in Terraform\n* [InfraMap](https://github.com/cycloidio/inframap): Reads .tfstate or HCL to generate a graph specific for each provider\n* [TerraCost](https://github.com/cycloidio/terracost): Cloud cost estimation for Terraform in the CLI\n\n...and the functionality of each is also embedded in our DevOps solution, which you can find out more about [here](https://www.cycloid.io/hybrid-cloud-devops-platform).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcycloidio%2Fterracost","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcycloidio%2Fterracost","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcycloidio%2Fterracost/lists"}