Governance & Cost Optimization
In our Lego city analogy, governance is like the city council that enforces rules, while cost optimization is the budget committee ensuring resources aren’t wasted. When your city spans multiple countries (AWS, Azure, GCP), you need consistent policies and smart spending strategies.
Terraform provides tools like Sentinel policies, tagging, and cost estimation to keep multi‑cloud deployments compliant and cost‑effective.
Key Concepts
1. Governance in Multi‑Cloud
- Consistency: Enforce naming conventions, tagging, and resource standards.
- Compliance: Ensure encryption, private subnets, and restricted access.
- Policy‑as‑Code: Use Sentinel or Open Policy Agent (OPA) to enforce rules.
2. Sentinel Policy
# Sentinel policy: enforce encryption on S3 buckets
import "tfplan/v2" as tfplan
main = rule {
all tfplan.resources.aws_s3_bucket as _, bucket {
bucket.applied.server_side_encryption_configuration is not null
}
}
- Ensures all S3 buckets have encryption enabled.
- Similar policies can be applied to Azure Blob Storage and GCP Cloud Storage.
3. Cost Optimization Strategies
- Right‑Sizing: Choose appropriate instance sizes (avoid over‑provisioning).
- Auto‑Scaling: Scale resources up/down based on demand.
- Reserved Instances / Savings Plans: Commit to long‑term usage for discounts.
- Storage Lifecycle Rules: Move data to cheaper tiers (archive, cold storage).
- Cross‑Cloud Cost Comparison: Deploy workloads where they are most cost‑effective.
4. Tagging & Resource Management
- Use tags for:
- Owner: Who created the resource.
- Environment: Dev, staging, prod.
- Cost Center: Department or project.
- Tags help track costs and enforce accountability.
Hands‑On Lab / Demo
Lab: Governance & Cost Optimization
- Create Sentinel policy to enforce encryption on all storage buckets.
- Apply tagging standards across AWS, Azure, and GCP resources.
- Configure auto‑scaling groups for cost efficiency.
- Compare instance pricing across providers using Terraform variables.
- Run cost estimation tool (e.g., Infracost) integrated with CI/CD pipeline.
Pro Tips & Best Practices
- Always enforce encryption and private networking.
- Use Sentinel/OPA for compliance checks.
- Integrate cost estimation tools into pipelines.
- Document tagging standards for team adoption.
- Regularly review cloud bills and adjust resources.
Summary & Cheatsheet
- Governance: Consistency, compliance, policy‑as‑code.
- Cost Optimization: Right‑sizing, auto‑scaling, reserved instances, lifecycle rules.
- Tags: Owner, environment, cost center.
- Best practice: Enforce policies, track costs, automate reviews.
Quick mnemonic: Govern → Tag → Optimize → Save
The Hackers Notebook
Governance and cost optimization are the guardrails and budget controls of multi‑cloud deployments. By enforcing policies with Sentinel and optimizing costs with right‑sizing, auto‑scaling, and tagging, you ensure compliance and efficiency across AWS, Azure, and GCP.

Updated on Dec 31, 2025