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

  # Clone it as it stood before a change order, so a following upgrade replays the change into it
  cub unit create --space my-space myclone --upstream-unit sample-deployment \
      --upstream-revision Before:ChangeOrder:base-space/release-42

  # Clone a unit as a draft to change and review, with a link back to merge the change home
  cub unit create --space drafts mydraft --upstream-unit sample-deployment \
      --upstream-space my-space --syncback

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

  # Clone a space's units as drafts, each linked back to the unit it was cloned from
  cub unit create --where "SpaceID = '<space-uuid>'" --dest-space drafts --syncback

  # Clone units and bring their links to units left behind, so the clones read from the same producers
  cub unit create --where "Labels.Tier = 'backend'" --dest-space prod-space \
      --include-outgoing-links-where "UpdateType = 'TransformPaths'"
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)
      --include-outgoing-links-where string   where expression selecting which of each cloned unit's links to units outside the cloned set to copy onto its clones; the copy keeps the original upstream unit as its to-unit, so the clone tracks the same one. Links within the cloned set are always copied and retargeted at the clones
      --label strings                         labels in key=value format; can separate by commas and/or use multiple instances of the flag
      --merge-external-source string          external source identifier (sets source type to MergeExternal)
      --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)
      --option stringArray                    bridge options in key=value format; use semicolons to separate multiple options within one flag value (e.g., --option 'key1=val1;key2=val2'); each --option flag instance corresponds to a ConfigType by position
  -o, --output string                         Output format. One of: json, yaml, name, wide, mutations, jq=<expr>, yq=<expr>, custom-columns=<spec>
      --provider string                       provider type for the unit; None marks the unit as not applied and not included in releases
      --quiet                                 No default output.
      --syncback                              also link each clone back to the unit it was cloned from, with a MergeUnits link in the upstream unit's space, so changes made in the clone can be merged home with "cub unit update --patch --resolve"; requires cloning (--upstream-unit in single mode)
      --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-revision string              revision of the upstream unit to copy instead of its head (same format as --restore, resolved against the unit being cloned). Before:ChangeOrder:<slug> takes the state a change order starts from, so a following --upgrade --change-order replays the change into the clone
      --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, NOT LIKE, ILIKE, ~~, !~~, ~, ~*, !~, !~*. Pattern matching with LIKE/ILIKE uses % and _ wildcards. Regex operators (~, ~*, !~, !~*) support POSIX regular expressions. A related entity is referenced by prefix, as in "UpstreamUnit.Slug = 'base'"; when the reference names a list, a * segment matches any element, as in "FromLink.*.Slug = 'upgrade-app'". Examples: "Slug LIKE 'app-%'", "DisplayName ILIKE '%backend%'", "Slug ~ '^[a-z]+-[0-9]+$'"
      --where-space string                    where expression to select destination spaces for bulk create

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