Requirements
Thecostgraph 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.--wide to print them in full, or --key Team to show one key.
Browse rules interactively
Open the explorer with one key expanded./ 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.--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.
Write the condition
Define the condition in one of two ways. Pass exactly one of them.- A single clause uses
--field,--op, and--match.--opdefaults toequals. It also acceptsnot_equals,contains,not_contains,starts_with, andends_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 withbill..
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.
Group costs by a virtual tag
After a rule is saved and applied, group costs by its key withtag:<key>.
Resolve virtual tag errors
The following messages come fromcostgraph tags commands:
Command reference
Commands are shown without thecostgraph prefix. Add --help for the complete flag list.
Browse and inspect
Alltags commands require a saved session. tag is an alias for tags.
Lists keys and rules. Use
--key for one key, --wide for full predicates, or --pick to inspect a rule.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.Rule condition flags
Use a simple clause or a CostQL expression for a literal rule.Chooses
equals, not_equals, contains, not_contains, starts_with, or ends_with.