Tag Filter β
The Tag Filter can be used in multiple Terramate features:
- stack.after
- stack.before
terramate <cmd> --tags <filter>terramate <cmd> --no-tags <filter>
Using the tags filter, you can list or run commands on stacks based on tag conditions. Use --tags to filter stacks having specific tags and --no-tags to filter those without the specified tags. The --tags filter support using AND (:) and OR (,) for more complex queries, while the --no-tags filter supports using OR (,). The query language is best explained with some examples but a formal definition can be found here.
Examples of Commands with --tags and --no-tags β
Listing stacks:
terramate list --tags abc: Lists stacks with the tagabc.terramate list --no-tags xyz: Lists stacks without the tagxyz.terramate list --tags abc:xyz: Lists stacks containing bothabcANDxyz.terramate list --tags app:k8s,app:nomad: Lists stacks containing bothappANDk8sor bothappANDnomad.
Running commands in stacks:
terramate run --tags abc -- echo "hi from stack with tag abc": Runs the command in stacks with the tagabc.terramate run --no-tags xyz -- echo "hi from stack without tag xyz": Runs the command in stacks without the tagxyz.
Running Terramate scripts:
terramate script run --tags abc myscript: Runsmyscriptin stacks with the tagabc.terramate script run --no-tags xyz myscript: Runsmyscriptin stacks without the tagxyz.
Notes:
- The
:character defines the AND operation and the,character the OR operation. They can be freely combined but no explicit grouping is supported (yet). --no-tagsflag does not support AND (:). In fact, it only supports OR (,).terramate list --no-tags xyz,abcwill list stacks without the tagxyzORabc.
Filter Grammar β
Below is the formal grammar definition:
txt
query ::= or_term {',' or_term}
or_term ::= and_term {':' and_term}
and_term ::= tagname
tagname ::= ident
ident ::= allowedchars { allowedchars } | allowedchars
allowedchars ::= lowercase | digit | '-' | '_' | '.' | '/'
digit ::= '0' ... '9'
lowercase ::= 'a' | 'b' | ... | 'z'The ident definition is a simplification and you should refer to stack.tags for the correct definition (in prose) for the expected declaration of tag names.