Skip to content

cub trigger create

cub trigger create

Create a new trigger or bulk create triggers

Synopsis

Create a new trigger or bulk create multiple triggers by cloning existing ones.

SINGLE TRIGGER CREATION:

Create a new trigger to automate actions on resources.

Events:

  • Mutation: Triggered when a resource is being modified
  • PostClone: Triggered after a resource is cloned

Config Types:

  • Kubernetes/YAML: For Kubernetes YAML configurations
  • ConfigHub/YAML: For ConfigHub YAML configurations
  • AppConfig/Properties: For application Java Properties configurations
  • AppConfig/YAML: For application YAML configurations
  • AppConfig/TOML: For application TOML configurations
  • AppConfig/INI: For application INI configurations
  • OpenTofu/HCL: For OpenTofu HCL configurations

Example Functions:

  • vet-celexpr: Validate resources using CEL expressions
  • vet-approvedby: Check if resource is approved
  • vet-placeholders: Ensure no placeholders exist
  • set-default-names: Set default names for cloned resources
  • set-annotation: Set annotations on resources
  • ensure-context: Ensure context annotations are present

Function arguments can be provided as positional arguments or as named arguments using --argumentname=value syntax. Once a named argument is used, all subsequent arguments must be named. Use "--" to separate command flags from function arguments when using named function arguments.

BULK TRIGGER CREATION:

When no positional arguments are provided, bulk create mode is activated. This mode clones existing triggers based on filters and creates multiple new triggers with optional modifications.

Single Trigger Examples:

  # Create a trigger to validate replicas > 1 for Deployments
  cub trigger create --space my-space --json replicated Mutation Kubernetes/YAML vet-celexpr 'r.kind != "Deployment" || r.spec.replicas > 1'

  # Create a trigger to enforce low resource usage (replicas < 10)
  cub trigger create --space my-space --json lowcost Mutation Kubernetes/YAML vet-celexpr 'r.kind != "Deployment" || r.spec.replicas < 10'

  # Create a trigger to ensure no placeholders exist in resources
  cub trigger create --space my-space --json complete Mutation Kubernetes/YAML vet-placeholders

  # Create a trigger requiring approval before applying changes
  cub trigger create --space my-space --json require-approval Mutation Kubernetes/YAML vet-approvedby 1

  # Create a trigger to ensure context annotations
  cub trigger create --space my-space --json annotate-resources Mutation Kubernetes/YAML ensure-context true

  # Create a trigger to set default names for cloned resources
  cub trigger create --space my-space --json rename PostClone Kubernetes/YAML set-default-names

  # Create a trigger to add a "cloned=true" annotation after cloning
  cub trigger create --space my-space --json stamp PostClone Kubernetes/YAML set-annotation cloned true

  # Using named arguments for clarity (note the "--" separator)
  cub trigger create --space my-space --json stamp PostClone Kubernetes/YAML -- set-annotation --key=cloned --value=true

Bulk Create Examples:

  # Clone all triggers matching a pattern with name prefixes
  cub trigger create --where "Slug LIKE 'app-%'" --name-prefix dev-,staging- --dest-space dev-space

  # Clone specific triggers to multiple spaces
  cub trigger create --trigger my-trigger --dest-space dev-space,staging-space

  # Clone triggers using a where expression for destination spaces
  cub trigger create --where "Slug LIKE 'app-%'" --where-space "Labels.Environment IN ('dev', 'staging')"

  # Clone triggers with modifications via JSON patch
  echo '{"Disabled": false}' | cub trigger create --where "Event = 'Mutation'" --name-prefix active- --from-stdin

  # Clone triggers matching specific criteria
  cub trigger create --where "ToolchainType = 'Kubernetes/YAML' AND FunctionName = 'vet-celexpr'" --name-prefix v2-
cub trigger create [<slug> <event> <config type> <function> [<arg1> ...]] [flags]

Options

      --allow-exists          Allow creation of resources that already exist
      --annotation strings    annotations in key=value format; can separate by commas and/or use multiple instances of the flag
      --delete-gate strings   delete gates in key[=true] format; can separate by commas and/or use multiple instances of the flag
      --dest-space strings    destination spaces for bulk create (can be repeated or comma-separated)
      --disable               Disable trigger
      --enforce               Enforce trigger
      --filename string       Read the ConfigHub entity JSON from file, URL (https://), or stdin (-); mutually exclusive with --from-stdin
      --filter string         Filter entity to apply to the list. Specify as 'space/filter' for cross-space filters or just 'filter' for current space. Supports both slugs and UUIDs. The filter will be combined with any --where clause using AND logic. Examples: "production-filters/security-check", "my-filter-uuid", "validation-rules"
      --filter-space string   filter entity containing WHERE expression to select destination spaces for bulk create (slug or UUID)
      --from-stdin            Read the ConfigHub entity JSON (e.g., retrieved with cub <entity> get --quiet --json) from stdin; merged with command arguments on create, and merged with command arguments and existing entity on update
  -h, --help                  help for create
      --invocation string     invocation to execute (alternative to specifying function and arguments)
      --jq string             jq expression, suppressing default output
      --json                  JSON output, suppressing default output
      --label strings         labels in key=value format; can separate by commas and/or use multiple instances of the flag
      --name-prefix strings   name prefixes for bulk create (can be repeated or comma-separated)
      --quiet                 No default output.
      --trigger strings       target specific triggers by slug or UUID for bulk create (can be repeated or comma-separated)
      --verbose               Detailed output, additive with default output
      --where string          Filter expression using SQL-inspired syntax. Supports conjunctions with AND. String operators: =, !=, <, >, <=, >=, LIKE, ILIKE, ~~, !~~, ~, ~*, !~, !~*. Pattern matching with LIKE/ILIKE uses % and _ wildcards. Regex operators (~, ~*, !~, !~*) support POSIX regular expressions. Examples: "Slug LIKE 'app-%'", "DisplayName ILIKE '%backend%'", "Slug ~ '^[a-z]+-[0-9]+$'"
      --where-space string    where expression to select destination spaces for bulk create
      --worker string         worker to execute the trigger function
      --yaml                  YAML output, suppressing default output
      --yq string             yq expression, suppressing default output

Options inherited from parent commands

      --context string   The context to use for this command
      --debug            Debug output
      --space string     space ID to perform command on

SEE ALSO