costs and tags schema, keywords, and syntax as Cost Reports.
You must have the Organization Owner role to edit Virtual Tag VQL in the console.
Where Virtual Tags Use VQL
A Virtual Tag configuration can contain VQL in the following locations:
The API examples on this page are request bodies for
POST /v2/virtual_tag_configs.
The order of objects in values determines precedence among value filters. When more than one value filter matches a cost, Vantage applies the first matching value. Value filters also take precedence over collapsed tag keys.
Schema
The schema below is the same one used for Cost Reports. VQL comprises two namespaces:costs and tags, which represent the available filters on Cost Reports in the Vantage console. Reference a filter as namespace.field, such as costs.provider or tags.name.
Availability of the fields listed below varies among different cloud providers. For a comprehensive list of available fields per provider, including the source billing field each one maps to, see the Data Dictionary.
costs.provider is optional. Omit it to filter across every connected provider in a single query—see Filter Across All Providers. Provider-specific fields (such as AWS costs.marketplace) only apply when costs.provider is included for that provider.Keywords
The keywords below are the same ones used for Cost Reports. VQL includes a set of keywords to create complex filter conditions. These keywords function similar to their SQL equivalents.
With these keywords, you can construct complex filter conditions in VQL, providing flexibility and precision when querying and analyzing cloud cost data.
Syntax
The syntax below is the same one used for Cost Reports. You can think of VQL in its current iteration as theWHERE clause of a SQL query. By combining the schema and keywords above with parentheses, you can form complex filter operations, such as:
Value Output Filters
Every object invalues requires a filter. For a custom value, the filter identifies the costs assigned that value. For business metric, cost-based, and percent-based values, it identifies the output costs to allocate.
The following examples map AWS accounts to team values. Because Platform appears first, it takes precedence if the filters overlap.
- API
- Terraform
Business Metric and Percentage Output Filters
Business metric and percent-based values also usevalues[].filter as their output costs filter:
- API
- Terraform
label_key selects the label column whose values become the tag values, and it’s required for business metrics that support named label columns. Business metrics created before multiple label columns were supported use a single label column; omit label_key for those metrics, because Vantage rejects it.Normalize Values Across Tag Keys
Use a value filter to map inconsistent provider tag keys to one Virtual Tag value. Repeat the provider condition in eachOR branch so each branch forms a complete filter set:
Cost-Based Allocation Filters
A cost-based value uses two VQL filters:values[].filterselects the output costs to allocate.values[].cost_metric.filterselects the input costs used to calculate the allocation percentages.
costs.charge_type = 'Usage' in the input filter so credits, taxes, and fees do not affect the allocation.
- API
- Terraform
Collapsed Tag Key Filters
Tag Key Collapsing copies the values of an existing tag key, either a provider tag or another Virtual Tag, into this Virtual Tag. Usecollapsed_tag_keys[].filter to restrict which costs are eligible.
When filter is set, do not also set providers. Put provider restrictions directly in the VQL filter. If you need only provider-level scoping and no other conditions, use providers instead of filter.
Collapsed tag keys follow these precedence rules:
- If a value filter and a collapsed tag key both match a cost, the value filter’s value is applied.
- If more than one collapsed tag key matches a cost, the key listed first is applied.
- API
- Terraform
Nested Virtual Tags
To reference an existing Virtual Tag, use its key and value with thetags namespace, just as you would use a provider tag:
Performance Guidelines
- Scope a filter to the providers it needs. A filter without
costs.provideris evaluated against every connected provider. - Prefer exact matches with
=andINoverLIKE,NOT LIKE,~*, and!~*. - When a filter applies to only a few providers, use a complete provider-specific expression in each
ORbranch. - Put high-volume value rules first so most costs match early.
Troubleshooting
- Wrap string values in single quotes, not double quotes.
- Do not use a saved filter to define a Virtual Tag value. Enter or paste the VQL expression directly.
- Do not combine
providersandfilteron the same collapsed tag key. - If multiple value filters match the same cost, reorder the values so the intended value appears first.
- If a nested tag fails validation, check for a cyclical reference between tags or a reference to an allocated tag outside the same provider-specific allocation chain.
costs.provider IN (...)is supported, butcosts.provider NOT IN (...)is not.- For invalid VQL, Vantage returns a
filter:error. An invalid cost-based input filter returns acost metrics filter:error.