The finance team asks you to attribute last quarter’s PaaS spend to the three product lines. You look at the invoice. It has one row per environment shape, three pages long, with names like acme-prod-v2 and migration-test-old. Nobody on the call knows which product line owns migration-test-old. The answer takes you two days of reading deployment logs and asking developers. The next month, you write a tagging policy: every environment carries team, product, customer, cost-center, env tags from the moment it’s created, and the billing API rolls usage up by tag. The next quarterly attribution takes 20 minutes.
What’s happening
Most cloudlet-billed PaaS platforms support environment tagging in the API but don’t enforce it in the UI. Tags are just key/value pairs attached to an environment. The billing API returns usage with tags included, which means a small aggregation script can produce per-team or per-customer cost reports without finance owning the spreadsheet.
What goes wrong without policy:
- Tag drift. Three different developers create three environments for the same customer using three different tag spellings (
customer:acme,customer:ACME,client:acme-corp). The roll-up is wrong. - Missing tags. An environment is provisioned during an outage by an on-call engineer who skips the tag form. It now lives in “unallocated” bucket forever, because nobody remembers what it’s for.
- Stale tags. A customer offboards. Their environments are kept “for archive.” Tags still say
customer:acme. The spend is attributed to a customer that hasn’t paid in nine months. - Tag explosion. Each developer adds their own tags (
purpose:test-thing,created-by:joe). The roll-up explodes into hundreds of tiny buckets and stops being a report.
A useful tag taxonomy is small (5-6 keys), enforced at creation time, and audited weekly.
How to verify
Read the current tag distribution and find environments missing required tags:
# 1. List every environment with its tags
curl -s "https://app.paas.example/1.0/environment/control/GetEnvs?session=$SESSION" \
| jq '.infos[] | {name: .env.shortdomain, tags: .env.tags}' > envs.json
# 2. Find environments missing any of the 5 required tags
REQUIRED=(team product customer cost-center env)
for env in $(jq -r '.name' envs.json); do
TAGS=$(jq -r --arg n "$env" '. | select(.name==$n) | .tags[]?' envs.json)
for key in "${REQUIRED[@]}"; do
if ! echo "$TAGS" | grep -q "^$key:"; then
echo "MISSING [$key] on $env"
fi
done
done
# 3. Find tag spelling variants on the same key
jq -r '.tags[]?' envs.json | sort | uniq -c | sort -rn | head -50
If uniq -c shows customer:acme, Customer:Acme, and client:acme all in use, you have drift. Pick a canonical spelling and fix the others.
Per-tag cost roll-up via the billing API:
# Get cloudlet-hour consumption per environment for the last 30 days
START=$(date -d '30 days ago' +%s)000
END=$(date +%s)000
curl -s "https://app.paas.example/1.0/billing/account/GetExternalBillingHistoryByPeriod?session=$SESSION&starttime=$START&endtime=$END" \
| jq -r '.array[] | [.envName, .cloudletsHours] | @tsv' > usage-by-env.tsv
# Join with tags to produce per-customer roll-up
jq -r '.infos[] | [.env.shortdomain, (.env.tags[]? | select(startswith("customer:")))] | @tsv' \
envs.json > env-customer-map.tsv
# Roll up
join -t$'\t' -1 1 -2 1 \
<(sort usage-by-env.tsv) \
<(sort env-customer-map.tsv) \
| awk -F'\t' '{customer=$3; hours[customer]+=$2} END {for (c in hours) print c, hours[c]}' \
| sort -k2 -rn
The output is a list of customers with their cloudlet-hour totals — directly comparable across the quarter without finance touching it.
The fix
The taxonomy we use on managed PaaS tenancies — five required tags, two optional:
| Key | Values | Why |
|---|---|---|
team | platform, data, frontend, backend, growth, … | Engineering org responsibility |
product | core, analytics, billing, internal-tools, … | Which product line carries the cost |
customer | shared, acme, globex, … | Customer attribution; shared for multi-tenant |
cost-center | cc-100-engineering, cc-200-saas, … | Finance cost-center code |
env | prod, staging, dev, uat, sandbox | Environment role (drives shutdown policy too) |
owner | email or slack handle (optional) | Who to ping if cost spikes |
expires | ISO date (optional) | Hard expiration for short-lived environments |
Enforcement:
- Wrapper script for environment creation. Don’t let people use the platform UI directly. Provide a
create-envscript that takes the five required tags as flags and refuses to run without them.
#!/usr/bin/env bash
# /opt/sh/create-env.sh - wrapper that enforces tag policy
set -euo pipefail
while [[ $# -gt 0 ]]; do
case $1 in
--name) ENV_NAME="$2"; shift 2 ;;
--team) TEAM="$2"; shift 2 ;;
--product) PRODUCT="$2"; shift 2 ;;
--customer) CUSTOMER="$2"; shift 2 ;;
--cost-center) CC="$2"; shift 2 ;;
--env) ENV_TIER="$2"; shift 2 ;;
*) echo "unknown flag $1"; exit 1 ;;
esac
done
for var in ENV_NAME TEAM PRODUCT CUSTOMER CC ENV_TIER; do
[[ -z "${!var:-}" ]] && { echo "missing --${var,,}"; exit 1; }
done
VALID_TIERS=(prod staging dev uat sandbox)
[[ " ${VALID_TIERS[*]} " == *" $ENV_TIER "* ]] || { echo "invalid env tier"; exit 1; }
TAGS="team:$TEAM,product:$PRODUCT,customer:$CUSTOMER,cost-center:$CC,env:$ENV_TIER"
curl -sf "https://app.paas.example/1.0/environment/control/CreateEnvironment?session=$SESSION&envName=$ENV_NAME&tags=$TAGS"
- Weekly drift audit. Cron job that runs the verification script and emails a list of untagged or mis-tagged environments to the platform team.
# /etc/cron.d/tag-audit - run every Monday morning
0 8 * * 1 root /opt/sh/tag-audit.sh | mail -s "Weekly tag drift report" platform@example.com
-
Tag enforcement at offboarding. When a customer offboards, the offboarding runbook includes “rename all
customer:acmetags tocustomer:archived-acme-2026Q2” so the spend stops showing up under an active customer. -
One canonical spelling per value. Document the allowed customer codes, team codes, and cost centers in a single file in the platform repo. Any new value goes through a PR. This is the only way to prevent drift over years.
-
Monthly attribution report sent to finance. Don’t wait for finance to ask. Run the roll-up monthly and send it. The number you publish becomes the number people argue with — and the argument is the feedback loop.
The tag taxonomy is worth it the first time finance asks “what did customer X cost us this quarter” and you answer in 20 minutes with evidence.
We design and operate billing-tag taxonomies as part of environment management on managed PaaS — taxonomy, wrapper scripts, weekly drift audits, monthly chargeback reports to finance. If your last quarterly cost attribution took longer than a coffee, book a tagging review.