CostFormation Reference
This page is the complete YAML syntax reference for CostFormation, CloudZero's cost allocation language. Use it to look up conditions, source IDs, transforms, properties, and allocation syntax. For concepts, see How to Build a Dimension. For copy-paste templates, see CostFormation Templates.
Key terms:
- Dimension: A category that organizes cloud costs into groups (for example, Environment, Team, Product).
- Element: A value within a Dimension (for example,
ProductionandDevelopmentare elements of an Environment Dimension). - Source: The data attribute CloudZero checks when evaluating rules and conditions (for example,
Account,Tag:Environment,K8s:Namespace). See Source IDs for all available sources. - Rule: Logic that assigns costs to elements. Types: Group (explicit names), GroupBy (automatic from source values), Metadata (substring matching).
- Condition: A comparison applied to a source value to determine if a cost matches a rule (for example,
Equals: production).
Definition file structure
All Dimension definitions live in a single YAML file per namespace. The file starts with the Dimensions root key:
Dimensions:
Environment:
Name: Environment
Source: Account
Rules:
- Type: Group
Name: Production
Conditions:
- Equals: 012345678901
Team:
Name: Team
Source: Tag:Team
Rules:
- Type: GroupByEach Dimension has a unique ID (like Environment or Team) and a set of properties. You can define as many Dimensions as you need in a single file.
Dimension properties
| Property | Type | Required | Description |
|---|---|---|---|
| Name | String | No | Display name throughout the platform. If omitted, the Dimension ID is used. |
| Type | String | No | Grouping (default) or Allocation. |
| Source / Sources | String or list | No | Default data source for all rules. Can be overridden at the rule or condition level. See Sources and inheritance. |
| CoalesceSources | Boolean | No | When true, uses the first source that has a value. Defaults to false. See Multiple sources and CoalesceSources. |
| Transforms | List | No | Transforms applied to source values before rules are evaluated. See Transforms. |
| DefaultValue | String | No | Element name for costs that do not match any rule. If omitted, unmatched costs appear under Not In Dimension. |
| Child | String | No | The Dimension shown when you click an element in the Explorer to see what is inside it. For example, setting Child: Service on an Environment Dimension lets users click Production to see a breakdown by service. Any valid source is a valid Child. |
| Hide | Boolean | No | When true, the Dimension is processed but not visible in the platform. Use for Dimensions that serve as building blocks for other Dimensions. |
| Disable | Boolean | No | When true, the Dimension is not processed and not visible. Use to deactivate a Dimension without deleting it. |
| Override | String | No | Replaces a CloudZero built-in Dimension with your custom definition. See Overriding default Dimensions. |
| Rules | List | Yes, if Type is Grouping | Rules that determine how costs are grouped into elements. |
| AllocateByRules / AllocateByStreams | Object | Yes, if Type is Allocation | Defines how shared costs are split. Use one or the other. See Allocation syntax. |
Sources and inheritance
Sources can be specified at three levels: the Dimension root, a rule, or a condition. Each level inherits from its parent unless it specifies its own source.
Environment:
Name: Environment
Source: Account # Default source for all rules
Rules:
- Type: Group
Name: Production
Conditions:
- Equals: 012345678901 # Inherits Source: Account
- Source: Tag:Environment # Overrides with its own source
Equals: production
- Type: Group
Name: Cloud Management
Source: CZ:Defined:Category # Overrides at the rule level
Conditions:
- Equals: Cloud Management # Inherits Source: CZ:Defined:CategoryWhen a rule or condition specifies its own Source, all source properties are overridden as a set (including Transforms and CoalesceSources). Inherited transforms do not carry into the override.
Multiple sources and CoalesceSources
Specify multiple sources using the Sources property (plural). By default, conditions are applied as an OR across all sources. Set CoalesceSources: true to use the first source that has a value (checked in the order listed) instead.
Sources:
- Tag:Env
- Tag:Environment
- Tag:environment
CoalesceSources: trueRules
Group rules
Group rules create elements with explicit names. A cost is placed in the element if any condition evaluates to true.
Rules:
- Type: Group
Name: Production
Conditions:
- Equals:
- 012345678901
- 109876543210Multiple rules can share the same element name; costs matching any of them are grouped together.
GroupBy rules and Format strings
GroupBy rules create elements automatically from source values. Format strings control element naming when using multiple sources.
Rules:
- Type: GroupBy
Sources:
- Service
- Region
Format: '{0} -- {1}'Format placeholders use zero-based indexes: {0} is the first source, {1} is the second. If Format is omitted, source values are concatenated with a space. When sources are coalesced, use a single placeholder ({0}).
Format indexes are zero-based ({0}, {1}). This is different from the Split transform, where Index is 1-based.
Metadata rules
Metadata rules match substrings within source values and create elements from the matched values.
Rules:
- Type: Metadata
Format: 'Service: {0}'
Sources:
- Tag:Name
- CZ:Defined:ResourceSummaryDisplay
Conditions:
- Source: Account
Equals: 012345678901
Values:
- -Web-:
- -UI-
- Frontend
- Order-Processing
- Order-Staging:
- WebOrderStaging
- Order-Fulfillment| Property | Type | Required | Description |
|---|---|---|---|
| Type | String | Yes | Must be Metadata. |
| Format | String | No | Template for element names. Must use a single placeholder ({0}). |
| Source / Sources | String or list | Yes | Sources to check for metadata matches. Transforms are not supported for Metadata rule sources. |
| Conditions | List | No | Conditions that must be true before metadata matching is applied. |
| Values | List | Yes | Metadata values to match. Costs are checked to see if the source contains each value. |
Metadata value requirements:
- Values can only contain letters, numbers, and dashes (
-). Other characters cause a validation failure. - Metadata matching automatically normalizes source values by converting special characters to dashes and comparing case-insensitively. This is built into Metadata rule behavior and is separate from the Normalize transform (which you would use with Group or GroupBy rules).
- Element names preserve the case of the specified metadata value.
- Leading and trailing dashes are used for matching but removed from element names (
-Web-matches the substring but creates an element namedWeb).
Alternatives: List alternatives after a metadata value to handle inconsistent naming. If any alternative matches, costs are grouped under the primary value. In the example above, costs containing -UI- or Frontend are grouped with -Web-.
Conditions
Conditions are listed under the Conditions: key within a rule. Each item in the list is evaluated independently, and the results are combined as an OR: if any single condition is true, the cost matches the rule. To require all conditions to be true, wrap them in an And block. Each condition can optionally specify its own source.
And
All conditions must be true.
- And:
- <Condition 1>
- <Condition 2>Or
Any condition must be true.
- Or:
- <Condition 1>
- <Condition 2>Not
Evaluates conditions as an OR, then negates the result. True only if all conditions are false.
- Not:
- <Condition 1>
- <Condition 2>BeginsWith
Source value starts with any of the specified strings.
- BeginsWith: <Value>- BeginsWith:
- <Value 1>
- <Value 2>Contains
Source value includes any of the specified strings.
- Contains: <Value>- Contains:
- <Value 1>
- <Value 2>EndsWith
Source value ends with any of the specified strings.
- EndsWith: <Value>- EndsWith:
- <Value 1>
- <Value 2>Equals
Source value exactly matches any of the specified strings.
- Equals: <Value>- Equals:
- <Value 1>
- <Value 2>HasValue
Checks whether a source has any value or is null.
- HasValue: <True|False>If True, the condition is true when the source has a value. If False, the condition is true when the source does not have a value.
Matches
Source value matches any of the specified regular expressions. Uses Snowflake's regex syntax (passthrough to REGEXP_LIKE). For details, see the Snowflake regex documentation.
- Matches: <RegEx>- Matches:
- <RegEx 1>
- <RegEx 2>Example: Matches: ".*(prod|production).*" evaluates to true for my-prod-server, production-db, and app-production-us but not for staging-server.
Before
Source value comes before the provided value alphabetically.
- Before: <value>BeforeOrEquals
Source value comes before the provided value alphabetically or is the same.
- BeforeOrEquals: <value>After
Source value comes after the provided value alphabetically.
- After: <value>AfterOrEquals
Source value comes after the provided value alphabetically or is the same.
- AfterOrEquals: <value>ForDateRange
Cost data with usage between the specified dates (inclusive). Recommended format: YYYY-MM-DD.
- ForDateRange:
From: <Date>
Until: <Date>Example: From: 2025-01-01, Until: 2025-03-31 matches costs with usage in Q1 2025.
Transforms
Transforms normalize source values before rules are evaluated. They are applied in order: the output of the first becomes the input of the second.
Transforms can be set at three levels: the Dimension root (applies to all rules), a rule (applies to all conditions in that rule), or a condition (applies to that condition only). Each level inherits from its parent unless it specifies its own Source, which overrides all source properties including transforms. See Sources and inheritance.
CostFormation applies transforms before evaluating conditions. Conditions match against the transformed values, not the originals. To match against untransformed values, specify a separate
Sourceat the condition level.
Lower
Converts all letters to lowercase.
- Type: LowerExample: ProductionResource 1 → productionresource 1
Upper
Converts all letters to uppercase.
- Type: UpperExample: the cost types → THE COST TYPES
Title
Converts to title case (first letter of each word capitalized).
- Type: TitleExample: the cost types → The Cost Types
Trim
Removes leading and trailing whitespace.
- Type: TrimExample: " the cost types " → "the cost types"
Clean
Removes leading and trailing whitespace. Converts .,/#!$%^&*;:=_~()\' and spaces to dashes.
- Type: CleanExample: " The:Cost!Types " → "The-Cost-Types"
Normalize
Removes leading and trailing whitespace, converts to lowercase, converts .,/#!$%^&*;:=_~()\' and spaces to dashes.
- Type: NormalizeExample: Production/Resources#4561 → production-resources-4561
Split
Splits the source value by a delimiter and extracts the substring at the specified index. Index is 1-based.
- Type: Split
Delimiter: <delimiter>
Index: <1-based index>Example: eu-west-1 with Delimiter: '-', Index: 1 → eu
Lookup
Parses the source value as JSON and extracts a field. Specify the field using either Key or Path (not both). Use Key for top-level fields and Path for nested objects or arrays. If the source value is not valid JSON, or the specified field does not exist, the result is null.
Key treats the value as a literal field name. Use Key for most cases, especially when field names contain special characters like colons (:) or dots (.).
- Type: Lookup
Key: <field name>Example: {"user:github_repo": "my-app", "region": "us-east-1"} with Key: user:github_repo → my-app
Example: {"owner": "platform-team", "env": "prod"} with Key: owner → platform-team
Path uses dot-notation to traverse nested JSON objects. Characters like . and : are interpreted as path separators. Supports nested paths (metadata.team) and array indexing (items[0].name).
- Type: Lookup
Path: <dot-notation path>Example: {"metadata": {"team": "billing", "region": "us-east-1"}} with Path: metadata.team → billing
If your JSON keys contain colons (
:) or dots (.), useKeyinstead ofPath.Keyhandles special characters as literal field names without requiring escaping.
Source IDs
The following tables list all available source IDs for use in CostFormation definitions.
Not all sources are available in the Explorer or Views. Check the Name in Explorer/Views column. Source availability is also controlled by namespace-level access control.
Core Cloud Provider Dimensions
| Source ID | Name in Explorer/Views | Description |
|---|---|---|
Account | Account | IDs for connected cloud accounts. Example values: AWS 012345678901, Azure xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, GCP my-project-id. |
BillingConnectionID | Not Available | ID tying costs to a Billing Connection |
CloudProvider | Cloud Provider | Cloud providers supported by CloudZero (for example, AWS, Azure, GCP, Oracle) |
CommittedUseSubscription | Not Available | Details of committed use subscriptions (RI, Savings Plan) |
Description | Not Available | Text field explaining the service, resource, or pricing component |
InvoiceID | Not Available | Invoice ID of costs |
K8s:Pod | Not Available | Deployed pod resources in Kubernetes clusters |
LineItemType | Not Available | Type of charge for a billing line item |
Operation | Operation | Specific cloud provider operation covered by the billing line item |
PayerAccount | Not Available | Management Account associated with costs |
PricingTerm | Not Available | How costs are priced (for example, on-demand, reserved) |
PricingUnit | Not Available | Unit of measurement for billing |
PricingUnits | Not Available | Unit of measure for pricing (GB, hours, requests). AWS: pricing/unit; GCP: usage.pricing_unit; Azure: unitOfMeasure; CBF: usage/units |
ProductFamily | Not Available | Product family of the resource (for example, Compute Instance, NAT Gateway) |
Region | Region | Cloud region where the billed resource is located |
Resource | Not Available | CloudZero Resource Name (CZRN). Use CZ:Defined:ResourceSummaryDisplay instead to avoid Explorer performance issues. If you must match by resource ID, use CZ:Defined:ResourceDisplay (native IDs). |
RequestType | Not Available | Incoming request type |
Service | Not Available | Cloud provider service type codes. Use CZ:Defined:ServiceDisplay for values that match the CloudZero UI. |
TransferType | Not Available | Type of data transfer (for example, outbound, intra-region) |
UsageDay | Not Available | ISO-formatted date for the day applied to each line item |
UsageFamily | Usage Family | Cloud service costs |
UsageType | Usage Type | Usage details of the billing line item |
Additional Cloud Provider Dimensions
| Source ID | Name in Explorer/Views | Description |
|---|---|---|
CZ:Defined:BillingLineItem | Billing Line Item | Categories of billing line item (for example, Usage, Support) |
CZ:Defined:Category | Service Category | Service categories (for example, Networking, Compute) |
CZ:Defined:Elasticity | Elasticity | Storage and Variable Costs |
CZ:Defined:InstanceType | Instance Type | Resource type, size, and family |
CZ:Defined:NetworkingCategory | Networking Category | Major networking spend types (for example, VPC Endpoints, Data Transfer) |
CZ:Defined:NetworkingSubCategory | Networking Sub-Category | Detailed networking costs (for example, VPC Endpoint (Hours), S3 Outbound) |
CZ:Defined:PaymentOption | Payment Option | Payment types (for example, Reservation, Discount) |
CZ:Defined:ResourceDisplay | Not Available | Native resource IDs (not CZRNs). Use CZ:Defined:ResourceSummaryDisplay to avoid performance issues. |
CZ:Defined:ResourceNameOnly | Not Available | Deprecated. Use CZ:Defined:ResourceSummaryDisplay. |
CZ:Defined:ResourceSummaryDisplay | Resource Summary | Groups logically related resources (such as EKS clusters), omits individual instance IDs. Recommended for matching resources in CostFormation. |
CZ:Defined:ResourceSummaryID | Not Available | Same as ResourceSummaryDisplay but uses CZRNs. Use ResourceSummaryDisplay instead. |
CZ:Defined:ResourceType | Resource Type | Resource types per service (for example, BigQuery: job, S3: bucket) |
CZ:Defined:ServiceDisplay | Service | Service values matching the CloudZero UI |
CZ:Defined:ServiceDetail | Service Detail | Normalized UsageType/Operation data, optimized per service |
CZ:Defined:TaggableVsUntaggable | Taggable vs. Untaggable | Taggable resources and untaggable types |
When matching resources in CostFormation,
CZ:Defined:ResourceSummaryDisplayis almost always the best choice. It uses native resource IDs shown in the CloudZero UI and groups logically related resources to prevent Explorer performance issues.
Tag Dimensions
| Source ID | Name in Explorer/Views | Description |
|---|---|---|
Tag:<Tag Name> | Tag > <Tag Name> | Values for the given tag |
Kubernetes Dimensions
| Source ID | Name in Explorer/Views | Description |
|---|---|---|
K8s:Cluster | Cluster | Kubernetes cluster names |
K8s:Namespace | Namespace | Kubernetes namespaces across all clusters |
K8s:Workload | Workload | Deployed workload resources |
K8s:Label:... | Label > Label Name | Labels and annotations. See syntax table below. |
K8s Label and annotation syntax:
| Syntax | Example | Description |
|---|---|---|
K8s:Label:<key> | K8s:Label:env | Pod label |
K8s:Label:<resource-type>:<key> | K8s:Label:deployment:app | Label on a specific resource type |
K8s:Label:annotation:<key> | K8s:Label:annotation:owner | Pod annotation |
K8s:Label:<resource-type>:annotation:<key> | K8s:Label:deployment:annotation:version | Annotation on a specific resource type |
Custom Dimensions
| Source ID | Name in Explorer/Views | Description |
|---|---|---|
User:Defined:<Dimension ID> | <Dimension Name> | Elements grouped according to the CostFormation definition |
Allocation syntax
For allocation concepts (when to use each method, how proportional allocation works), see Splitting Shared Costs. To configure allocation visually, see Create an Allocation Dimension.
CloudZero enforces limits on the number of streams and combined allocation sources per dimension definition. If you hit a validation error related to these limits, contact your account manager to discuss adjustments.
AllocateByStreams
<DimensionId>:
Type: Allocation
AllocateByStreams:
Streams:
- <stream-name>Rate-based allocation
Rate-based allocation gives consuming teams a stable, predictable cost per unit. Unlike proportional allocation, where the effective cost per unit changes whenever the total bill changes, rate-based allocation locks in a fixed price per unit of usage.
This is useful for internal chargeback when your organization has agreed on a fixed transfer price. For example, finance sets the rate for a CPU hour at $1.00. Consuming teams budget against that rate regardless of what the infrastructure actually costs. The platform team sees the surplus or deficit in the DefaultElement, which tells them whether their internal pricing is sustainable.
For example, a shared compute cluster costs $1,000. Two teams use it:
| Element | Usage (CPU hours) | Rate | Allocated cost |
|---|---|---|---|
| Team A | 700 | $1.00 | $700 |
| Team B | 200 | $1.00 | $200 |
| Unallocated Cost (default) | $100 | ||
| Total | $1,000 |
If total usage exceeds the actual spend, the default element receives a negative value to reconcile.
Your telemetry data only needs to contain raw usage, for example CPU hours, API calls, or gigabytes stored. You do not need to convert it to dollar amounts.
<DimensionId>:
Type: Allocation
AllocateByStreams:
Rate:
Type: Fixed
Value: 1.00
DefaultElement: 'Unallocated Cost'
Streams:
- cpu-hours-by-team| Key | Required | Description |
|---|---|---|
| Type | Yes | Fixed. Applies the same rate to every usage value. |
| Value | Yes | Cost per unit of usage (for example, 1.00 means $1.00 per unit). |
| DefaultElement | Yes | Element that receives the remaining spend after rate-based allocation. Can be positive or negative. |
AllocateByRules
<DimensionId>:
Type: Allocation
AllocateByRules:
AllocationMethod: <Even | Proportional>
SpendToAllocate:
Conditions:
- <conditions>
AcrossElements:
Rules:
- <rules>
ForEachElementOf: # Optional, proportional only
Source: <Dimension>
Values:
- <value>| Key | Description |
|---|---|
| AllocationMethod | Even (equal split) or Proportional (split by relative cost). |
| SpendToAllocate | Conditions identifying the shared costs to split. Supported keys: Source, Sources, CoalesceSources, Conditions. |
| AcrossElements | Rules defining who receives the allocated costs. Supported keys: Rules, Source, Sources, Transforms. |
| ForEachElementOf | Optional. Further segments the allocation by another Dimension. Supported keys: Source, Sources, Transforms, Values. Only available with Proportional. |
| Values (under ForEachElementOf) | Optional. Limits ForEachElementOf to specific elements in the source Dimension. If omitted, all elements are included. |
Even allocation example
Even allocation splits costs equally across all elements:
SharedInfra:
Type: Allocation
AllocateByRules:
AllocationMethod: Even
SpendToAllocate:
Conditions:
- Source: Account
Equals: '123456789012'
AcrossElements:
Rules:
- Type: GroupBy
Source: User:Defined:TeamProportional cost type and granularity
When you only need the default granularity and cost type, use the short form: AllocationMethod: Proportional. To customize granularity or cost type, use the expanded form below.
Default cost type: RealCost. Default granularity: UsageDaily.
AllocateByRules:
AllocationMethod:
Method: Proportional
Granularity: <UsageDaily | UsageMonthly | BillingPeriod>
CostType: <cost type>Supported cost types: BilledCost, DiscountedCost, DiscountedAmortizedCost, AmortizedCost, InvoicedAmortizedCost, RealCost (default), OnDemandCost, UsageAmount.
ElementCutoff
Filters low-value elements from allocation Dimensions. For conceptual details, see Splitting Shared Costs.
ElementCutoff:
ThresholdPercent: 5 # Required: 0-100 exclusive
Name: 'Other' # Optional: bucket name for grouped elements| Parameter | Required | Description |
|---|---|---|
| ThresholdPercent | Yes | Cumulative percentage threshold. Set to 0 to disable when an organization default is set. |
| Name | No | Grouping bucket name. When provided, sub-threshold elements are aggregated into this element instead of excluded. |
Supported allocation types:
| Allocation type | Supported |
|---|---|
| AllocateByStreams | Yes |
| AllocateByStreams (rate-based) | No |
AllocateByRules with Proportional | Yes |
AllocateByRules with Even | No |
Combining dedicated and shared costs
Use a GroupBy rule referencing an Allocation Dimension to merge allocated costs into a parent Dimension alongside dedicated costs:
Product:
Name: Product
DefaultValue: Other
Rules:
- Type: Group
Name: Mobile
Conditions:
- Source: Tag:Application
Equals: mobile
- Type: Group
Name: Web
Conditions:
- Source: Tag:Application
Equals: web
- Type: GroupBy
Source: User:Defined:SharedCostAllocationGroup rules match dedicated costs (tagged per application). The trailing GroupBy references an Allocation Dimension (User:Defined:SharedCostAllocation) to pull in shared costs. If the Allocation Dimension uses the same element names (Mobile, Web), costs are combined automatically. This works for both telemetry-based and proportional Allocation Dimensions.
Overriding default Dimensions
CloudZero provides built-in Dimensions like Elasticity and Payment Option. To replace a default with your own definition, use the Override property:
Elasticity:
Name: Elasticity
Override: CZ:Defined:Elasticity
Rules:
- Type: Group
Name: Variable
Conditions:
- Source: CZ:Defined:Category
Equals: ComputeThe Override property references the ID of the default Dimension you are replacing. Without it, the definition fails validation because the name conflicts with the built-in Dimension.
Other Dimensions that reference the overridden default are automatically updated to use your custom definition.
Restrictions:
- Only default Dimensions can be overridden. You cannot override a Custom Dimension from the
User:Definednamespace. - A default Dimension can only be overridden by one Custom Dimension.
- All Dimension names must be unique, unless a Custom Dimension is overriding the default Dimension with the same name.
- The ID and name of the overriding Custom Dimension do not need to match the overridden default.
Have questions or feedback? Reach out to your account manager.
Updated 2 days ago
