Skip to main content
Inspect your tenant’s virtual tags from the terminal, and check what a new rule would match before anyone saves it. A virtual tag assigns a tag value to cost rows that match a rule, without changing the tags on your infrastructure. Refer to Virtual tags overview for how rules are evaluated.

Requirements

The costgraph tags commands need a signed-in CLI session. They don’t accept API keys, including keys with virtual-tags:read or virtual-tags:write. Those scopes apply to the virtual tag management API that the Terraform provider uses. Refer to Install and sign in. The commands read and preview rules in your session’s tenant. Run costgraph auth status to check which tenant that is.
In CLI 0.11.0, costgraph tags create can validate and preview a rule but can’t save it. CostGraph refuses the save request for both a saved CLI session and an API key. Save rules in the dashboard under Settings > Tenants Settings > Virtual tags, as described in Create virtual tags, or with the Terraform provider.

List tag keys and rules

The following command lists every tag key and its rules in evaluation order.
The table shows each rule’s key, rank, type, predicate, and assigned value. Long predicates are shortened to fit your terminal. Add --wide to print them in full, or --key Team to show one key.

Browse rules interactively

Open the explorer with one key expanded.
Use / to filter rules, Esc to clear the filter, and q to quit. Omit Team to browse every key. Running costgraph tags without a subcommand opens this view in a terminal and prints help otherwise.

Inspect one rule

costgraph tags list --pick lets you choose one key and rule in your terminal and prints that rule in detail.

Find fields to match

A rule condition matches a field of your billing rows. The following command lists the fields you can use and how many rows populate each one.
The table shows each field with its coverage, populated rows, total rows, and whether it’s usable. The CLI hides fields below the usability threshold. Add --all to include them. The list covers billing rows. It doesn’t change for rules with the k8s scope.

Preview a virtual tag rule

costgraph tags create --dry-run validates a rule and shows which cost rows it would match. With --dry-run, the command doesn’t save the rule. The following command previews a rule that assigns Platform to Amazon EC2 charges under the Team key.
The output summarizes the rule, then the preview. The preview reports the number of matched rows, their spend in each currency, and a sample of the matched rows. Check that the matched spend is what you expect before you save the rule. A rule creates no cost data, usage, or charges. It also applies to matching cost data that arrives later. The preview reflects only rows already imported into the tenant, so it can show zero matched rows for a rule that matches future data.

Write the condition

Define the condition in one of two ways. Pass exactly one of them.
  • A single clause uses --field, --op, and --match. --op defaults to equals. It also accepts not_equals, contains, not_contains, starts_with, and ends_with.
  • A CostQL expression uses --expr, such as --expr 'bill.service_name == "AmazonEC2"'. Use an expression for conditions that combine several fields. Billing expressions qualify fields with bill..

Choose the rule type and scope

Choose how the rule obtains its value. --scope chooses which cost data the rule applies to. billing, the default, matches billing line items. k8s matches Kubernetes allocation. This --scope is unrelated to the scopes on an API key.

Preview in a script

Add -o json to get the rule request and preview as JSON. Keep --dry-run in every scripted call.
Without --dry-run, costgraph tags create doesn’t ask for confirmation when it runs in a script, a pipe, or with -o json. It sends the write request to CostGraph immediately. In CLI 0.11.0, CostGraph refuses that request, as described in Requirements. Pass --dry-run whenever you only want a preview.

Group costs by a virtual tag

After a rule is saved and applied, group costs by its key with tag:<key>.
Refer to Query costs for filters and periods.

Resolve virtual tag errors

The following messages come from costgraph tags commands:

Command reference

Commands are shown without the costgraph prefix. Add --help for the complete flag list.

Browse and inspect

All tags commands require a saved session. tag is an alias for tags.
command
Lists keys and rules. Use --key for one key, --wide for full predicates, or --pick to inspect a rule.
command
Opens the interactive explorer. Bare tags opens it in a terminal and prints help otherwise.
command
Lists billing fields and coverage. Use --all to include fields below the usability threshold.

Rule preview

CLI 0.11.0 can preview rules but cannot save them.
command
Validates and previews a rule with --dry-run. Keep that flag for previews in scripts.

Rule condition flags

Use a simple clause or a CostQL expression for a literal rule.
string
Names the virtual tag key.
string
Set the billing field and match value for a simple clause.
string
default:"equals"
Chooses equals, not_equals, contains, not_contains, starts_with, or ends_with.
string
Sets a CostQL condition instead of --field and --match. Qualify billing fields with bill..
string
default:"literal"
Chooses literal or inherited_value.
string
Sets the fixed tag value for a literal rule.
string
Sets the value expression for an inherited rule.

Scope and output flags

These flags select the data and preview behavior.
string
default:"billing"
Selects billing or k8s cost data. Does not grant API key permissions.
boolean
Previews matching rows without saving a rule.
string
Use json for the rule request and preview. Keep --dry-run.