Default cost-allocation tags (Terraform, AWS provider) Every resource gets team, service and environment tags without repeating them. Activate the same keys as cost allocation tags in billing.
hcl Copy
provider "aws" {
region = var.region
default_tags {
tags = {
team = var.team
service = var.service
environment = var.environment
managed_by = "terraform"
}
}
} S3 lifecycle: tier, then expire Move colder objects to cheaper classes and expire logs you do not need. Adjust days to your retention rules.
hcl Copy
resource "aws_s3_bucket_lifecycle_configuration" "logs" {
bucket = aws_s3_bucket.logs.id
rule {
id = "tier-then-expire"
status = "Enabled"
filter {}
transition {
days = 30
storage_class = "STANDARD_IA"
}
expiration {
days = 400
}
abort_incomplete_multipart_upload {
days_after_initiation = 7
}
}
} Monthly budget with an alert (Terraform) A budget that emails when forecast spend passes 90 percent. Route the address to a group that can act.
hcl Copy
resource "aws_budgets_budget" "team" {
name = "team-monthly"
budget_type = "COST"
limit_amount = "5000"
limit_unit = "USD"
time_unit = "MONTHLY"
cost_filter {
name = "TagKeyValue"
values = ["user:team$platform"]
}
notification {
comparison_operator = "GREATER_THAN"
threshold = 90
threshold_type = "PERCENTAGE"
notification_type = "FORECASTED"
subscriber_email_addresses = ["finops@example.com"]
}
} Namespace ResourceQuota and LimitRange (Kubernetes) Stops one namespace from claiming the cluster and gives containers sane defaults so requests are never empty.
yaml Copy
apiVersion: v1
kind: ResourceQuota
metadata:
name: team-quota
namespace: team-a
spec:
hard:
requests.cpu: "20"
requests.memory: 40Gi
limits.memory: 80Gi
pods: "100"
---
apiVersion: v1
kind: LimitRange
metadata:
name: defaults
namespace: team-a
spec:
limits:
- type: Container
defaultRequest:
cpu: 100m
memory: 128Mi
default:
memory: 512Mi Require cost labels on workloads (Kyverno) Rejects deployments without team and service labels so allocation never starts from "unknown".
yaml Copy
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: require-cost-labels
spec:
validationFailureAction: Enforce
background: true
rules:
- name: check-labels
match:
any:
- resources:
kinds: [Deployment, StatefulSet, CronJob]
validate:
message: "Workloads need team and service labels for cost allocation."
pattern:
metadata:
labels:
team: "?*"
service: "?*" Test in a non-production account or cluster first. Names and values are examples.