# Cost Management and Discounts — Google Cloud Platform

Source: https://www.skillbyai.com/en/gcp/p-cost

> Track spending with budgets and labels and use Google Cloud discounts.

## Visibility first, then discounts

Start with visibility: **Cloud Billing reports** break spend down by project, service, SKU and **label**, and the **billing export to BigQuery** lets you build your own dashboards. **Budgets** send alerts at thresholds and can publish to Pub/Sub, so automation can react (for example, notify Slack or cap a sandbox). Then reduce spend. Compute Engine gives **sustained use discounts** automatically for many machine series that run a large part of the month (not E2 or some newer series). **Committed use discounts (CUDs)** trade a one- or three-year commitment for large savings, either for specific resources or as flexible spend-based commitments across services. Use **Spot VMs** for fault-tolerant batch work, scale-to-zero services, **Recommender** right-sizing suggestions, BigQuery partitioning and lifecycle rules for storage. Watch hidden costs: **network egress**, log ingestion and idle external IPs.

## A budget with alert thresholds

Budgets alert; they do not stop spending by themselves.

```bash
gcloud billing budgets create --billing-account=0X0X0X-0X0X0X-0X0X0X \
  --display-name="shop-dev monthly" \
  --budget-amount=20000INR \
  --filter-projects=projects/shop-dev-123456 \
  --threshold-rule=percent=0.5 --threshold-rule=percent=0.9 \
  --threshold-rule=percent=1.0,basis=forecasted-spend

# idle resources and right-sizing suggestions
gcloud recommender recommendations list --project=shop-dev-123456 --location=asia-south1-a \
  --recommender=google.compute.instance.MachineTypeRecommender
```

## Label from day one

Spend that cannot be attributed to a team cannot be managed. Make labels like `team` and `env` mandatory in Terraform modules and check them in code review.

**Quiz:** Which discount applies automatically, with no commitment, to eligible Compute Engine VMs that run most of the month?

- [x] Sustained use discount
- [ ] Committed use discount
- [ ] Spot pricing
- [ ] Free tier

*Answer:* Sustained use discount. Sustained use discounts are applied automatically to eligible machine series based on monthly usage.
