How to estimate GCP costs from Terraform
Estimate Google Cloud costs from Terraform configurations with sustained-use discounts applied automatically, Committed Use Discounts via usage file, and Spot VMs detected from the resource. No GCP credentials required.
Quick answer
Install C3X (brew install c3xdev/tap/c3x), point it at your Terraform directory (c3x estimate --path .), and you get a line-item GCP cost breakdown in seconds. Sustained-use discounts apply automatically. For Committed Use Discounts, specify purchaseOption in c3x-usage.yml. No GCP credentials, no plan invocation, no SaaS account.
GCP cost estimation from Terraform has two quirks that AWS and Azure don't: sustained-use discounts apply automatically, and Committed Use Discounts apply at the project level rather than per-resource. Other than that, the workflow is the same as estimating AWS or Azure: point c3x at the Terraform, get a per-resource breakdown, commit to CI for PR comments.
This post walks through GCP-specific patterns from a single command to PR-level cost gates.
Step 1: Install and verify
brew install c3xdev/tap/c3x
c3x --versionC3X is open source, no API key needed for the public pricing endpoint. Both Linux and macOS supported.
Step 2: Estimate a GCP project
Point c3x at your Terraform directory:
c3x estimate --path /path/to/terraformSample output for a small GCP stack:
Name Monthly Qty Unit Monthly Cost
google_compute_instance.api
├─ Instance usage (Linux, on-demand, e2-standard-4) 730 hours $97.82
├─ Sustained use discount applied -$29.34
└─ Boot disk (pd-balanced) 100 GB $10.00
google_sql_database_instance.postgres
├─ Compute (db-custom-4-16384, Regional HA) 730 hours $295.40
└─ Storage (SSD) 200 GB $34.00
google_storage_bucket.assets
└─ Standard storage 100 GB $2.00
OVERALL TOTAL $409.88Notice the sustained-use discount line item. C3X applies SUDs automatically for compute resources that run continuously. The discount tiers up to 30% off the on-demand rate.
For the per-resource pricing details, see the catalog pages for google_compute_instance, google_sql_database_instance, and google_storage_bucket.
Step 3: Handle GCP-specific patterns
Sustained-use discounts
SUDs are automatic for resources running >25% of the month. You don't need to do anything; c3x applies them. The output shows the post-SUD cost. For a fixed 24/7 instance, you get the full ~30% discount.
Committed Use Discounts
CUDs require pre-commitment for 1-year or 3-year terms. Configure in c3x-usage.yml:
# c3x-usage.yml
resource_usage:
google_compute_instance.api:
purchaseOption: "cud_1yr"
google_sql_database_instance.postgres:
purchaseOption: "cud_3yr"c3x applies the CUD-discounted rate. 1-year CUDs are typically 37% off on-demand; 3-year is up to 70%. The estimate output reflects the commitment.
Custom machine types
GCP lets you provision instances with arbitrary CPU and memory combinations:
resource "google_compute_instance" "api" {
name = "api"
machine_type = "custom-4-16384" # 4 vCPU, 16 GB RAM
zone = "us-central1-a"
# ...
}c3x parses the dimensions and uses the per-vCPU + per-GB-RAM pricing. The output looks similar to predefined types but with the custom dimensions noted.
Spot VMs
Add scheduling.provisioning_model = "SPOT" to use Spot pricing (typically 60-91% off on-demand):
resource "google_compute_instance" "batch_worker" {
name = "batch-worker"
machine_type = "n2-standard-8"
zone = "us-central1-a"
scheduling {
provisioning_model = "SPOT"
preemptible = true
automatic_restart = false
}
# ...
}c3x detects the Spot configuration and uses the Spot pricing tier. For more on Spot economics across clouds, see our Spot instances post — the same patterns largely apply.
Step 4: Diff branches for PR cost reviews
Same diff workflow as AWS or Azure:
c3x diff --path . --compare-to mainSample output for a PR that changes machine type and adds a Cloud SQL replica:
~ google_compute_instance.api
└─ Instance usage (e2-standard-4 -> n2-standard-8) +$87.30 ($97.82 -> $185.12)
+ google_sql_database_instance.postgres_replica
└─ Compute (db-custom-2-8192, Zonal) +$148/month
Monthly cost change: +$235.30 ($409.88 -> $645.18)Step 5: GCP-specific CI integration
The same setup-c3x action works for GCP Terraform. No cloud-specific configuration required:
# .github/workflows/cost.yml
on: pull_request
jobs:
cost:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: c3xdev/setup-c3x@v1
with:
path: .For full CI integration details, see the CI/CD documentation. For budget gating to block PRs over a cost threshold, see budget guardrails in CI.
What GCP cost dimensions to watch
Three GCP-specific gotchas to know:
Network egress to internet
GCP has two egress tiers: Premium (default, uses Google's global backbone) and Standard (cheaper, uses public internet for routing). The default Premium tier costs more but is faster. For workloads that don't need premium routing, switching to Standard can save ~50% on egress.
Persistent Disk types
pd-standard (HDD), pd-balanced (default SSD), pd-ssd (high-IOPS SSD), and Hyperdisk variants all have different per-GB pricing. The default boot disk is pd-balanced at $0.10/GB-month. Many production workloads provision pd-ssd ($0.17/GB-month) by reflex; check if the IOPS are actually needed.
Cloud Logging volume
GKE workloads generate large volumes of logs that flow to Cloud Logging at $0.50/GiB ingest. For 5-30 GiB/day per cluster, that's $75-450/month just for log ingest. See the google_logging_project_bucket catalog page for mitigations.
Common GCP patterns and their estimates
A typical small production stack
- 1 google_compute_instance (e2-standard-4) for app: ~$70/month with SUD
- 1 google_sql_database_instance (db-custom-2-8192 Zonal): ~$110/month
- 1 google_storage_bucket (100 GB Standard): $2/month
- Cloud Logging (5 GiB/day from GKE): ~$75/month
- Static IP (in use): $3/month
- Total: ~$260/month
A typical GKE-based stack
- google_container_cluster (Standard mode): $73/month control plane
- 3 google_container_node_pool nodes (e2-standard-4): $210/month
- Cloud SQL: $110/month
- Cloud Logging: $300/month (chatty K8s workloads)
- Artifact Registry storage: $5/month
- Total: ~$700/month
Cloud Logging is consistently the surprise line item in GCP-based Kubernetes workloads. Plan for it.
FAQ
Does C3X support Google Cloud Terraform configurations?
Yes. C3X parses google_* resources alongside AWS and Azure resources in the same Terraform configuration. The pricing data comes from the GCP Cloud Billing Catalog API and is refreshed daily. No GCP credentials are required for estimation.
How does C3X handle GCP sustained-use discounts?
Sustained-use discounts (SUDs) are applied automatically to GCP compute resources running more than 25% of the month. C3X computes the effective monthly rate including the SUD tier the workload reaches. For a 24/7 instance, you get the full ~30% SUD applied to the on-demand price.
What about Committed Use Discounts (CUDs)?
Set purchaseOption: 'cud_1yr' or 'cud_3yr' on the resource in c3x-usage.yml. C3X applies the CUD pricing tier from the Cloud Billing API. 1-year CUDs are typically 37% off; 3-year is up to 70%. CUDs apply at the project level in GCP; c3x estimates them per-resource as a reasonable proxy.
Does C3X support custom machine types?
Yes. C3X reads the machine_type attribute. For predefined types (e2-standard-4, n2-highmem-8), it looks up the bundled price. For custom types (custom-4-16384), it parses the CPU and memory dimensions and uses GCP's per-vCPU and per-GB-RAM rates.
How is GCP estimation different from AWS or Azure?
Three notable differences. GCP has automatic sustained-use discounts that apply without commitment; AWS and Azure don't. GCP's network egress to the internet has tiered pricing that depends on Premium vs Standard tier; AWS and Azure don't expose this distinction. GCP per-second billing is granular for compute; AWS bills per-second too, but Azure bills per-minute on most VM SKUs.
What about Cloud Run, Cloud Functions, and other serverless resources?
All supported. Cloud Run (google_cloud_run_v2_service) and Cloud Functions (google_cloudfunctions2_function) are usage-based; provide expected requests and duration in c3x-usage.yml. BigQuery, Dataflow, and similar data services are also estimated when configured with expected throughput.
Where to go from here
Three follow-ups for digging deeper:
- The full resource catalog covers every supported GCP resource with pricing dimensions and optimization tips.
- For the equivalent AWS workflow, see how to estimate AWS costs from Terraform.
- For PR-level cost gating, see budget guardrails in CI.
For air-gapped or self-hosted GCP cost estimation (regulated environments, GovCloud-equivalent isolated workloads), see our air-gapped Terraform cost estimation post. The same patterns apply to GCP as to AWS.
Share this post
Try C3X on your own Terraform
Free and open source. No API key required. One command to install, one command to estimate.