Skip to content

cub unit create

cub unit create

Create a unit or bulk create units

Synopsis

Create a new unit or bulk create multiple units by cloning existing ones.

SINGLE UNIT CREATION:

Like other ConfigHub entities, Units have metadata, which can be partly set on the command line and otherwise read from stdin using the flag --from-stdin.

Unlike other ConfigHub entities, Units also contain configuration data, which is read from another source.

Unit configuration data can be provided in multiple ways:

  1. From a local or remote configuration file, or from stdin (by specifying "-")
  2. By cloning an existing upstream unit (using --upstream-unit)

BULK UNIT CREATION:

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

Single Unit Examples:

  # Create a unit from a local YAML file
  cub unit create --space my-space myunit config.yaml

  # Create a unit from a file:// URL
  cub unit create --space my-space myunit file:///path/to/config.yaml

  # Create a unit from a remote HTTPS URL
  cub unit create --space my-space myunit https://example.com/config.yaml

  # Create a unit with config from stdin
  cub unit create --space my-space myunit -

  # Combine Unit JSON metadata from stdin with config data from file
  cub unit create --space my-space myunit config.yaml --from-stdin

  # Clone an existing unit
  cub unit create --space my-space --json --from-stdin myclone --upstream-unit sample-deployment

Bulk Create Examples:

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

  # Clone specific units to multiple spaces
  cub unit create --unit app1,app2 --dest-space dev-space,test-space

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

  # Clone units with target assignment and labels
  cub unit create --where "Labels.Tier = 'backend'" --name-prefix canary- --target my-target --label "Rollout=canary"

  # Clone units with JSON patch modifications
  echo '{"DisplayName": "Updated Name"}' | cub unit create --where "Slug = 'myapp'" --name-prefix v2- --from-stdin
cub unit create [<name> [config-file]] [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
      --change-desc string       change description
      --changeset string         changeset to associate the unit with
      --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)
      --destroy-gate strings     destroy gate for the unit (can be repeated or comma-separated)
      --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
      --import string            source unit slug (single mode only)
      --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-pattern string      a pattern string for name generation of clones, prefix 'template:' to use a Go template with .SourceEntitySlug to access the original Unit and .Labels to access variant labels, example: 'template:{{.SourceEntitySlug}}-{{.Labels.env}}'
      --name-prefix strings      name prefixes for bulk create (can be repeated or comma-separated)
      --quiet                    No default output.
      --target string            target for the unit
      --timeout string           completion timeout as a duration with units, such as 10s or 2m (default "10m0s")
  -t, --toolchain string         toolchain type (single mode only) (default "Kubernetes/YAML")
      --unit strings             target specific units by slug or UUID for bulk create (can be repeated or comma-separated)
      --upstream-space string    space slug of upstream unit to clone (single mode only)
      --upstream-unit string     upstream unit slug to clone (single mode only)
      --variant-labels strings   labels with multiple values for bulk creation in the format of key1=value1|value2,key2=value1|value2|value3
      --verbose                  Detailed output, additive with default output
      --wait                     wait for completion (default true)
      --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
      --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