# Terraform Cloud Cost Controls: Budgets, Policies, and Tagging

URL: https://www.devopsness.com/blog/terraform-cloud-cost-controls-budgets-policies-and-tagging
Author: Kiril Urbonas
Published: 2025-07-01
Updated: 2025-07-01
Categories: Infrastructure
Tags: AWS, Terraform, Monitoring

Summary: Manage cloud spend with Terraform: cost estimation, tagging, and policy-as-code.

---
# Terraform Cloud Cost Controls: Budgets, Policies, and Tagging

Infrastructure as code should include **cost awareness**. Use Terraform to enforce tags, estimate cost, and align with budgets.

## 1. Cost Estimation in CI

```hcl
# Infracost or Terraform Cloud cost estimation in pipeline
plan:
  - terraform plan -out=tfplan
  - infracost breakdown --path=tfplan
  - # fail or warn if delta exceeds threshold
```

Catch expensive changes before apply.

## 2. Tagging Strategy

- Add **cost allocation tags** to every resource (team, project, environment).
- Use Terraform variables or workspace to set tags consistently.

```hcl
tags = {
  Team     = var.team
  Project  = var.project
  Env      = var.environment
  ManagedBy = "terraform"
}
```

## 3. Policy as Code

- Use Sentinel (TFC) or OPA to enforce: “No instance type larger than X,” “All resources must have cost tags.”
- Gate applies on policy pass.

Best practice: treat cost as part of the PR review and make tag compliance automatic.
