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 -o 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 my-space/sample-deployment --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)
      --display-name string                   friendly name for the entity, which need not be unique or URL-safe; an entity without one is shown by its slug
      --dry-run                               report what the command would write, and write nothing
      --filename string                       Read the ConfigHub entity's fields, as YAML or JSON, from file, URL (https://), or stdin (-), as --from-stdin does; 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's fields, as YAML or JSON, from stdin; merged with command arguments on create, and merged with command arguments and existing entity on update. A field the entity does not have, or one only the server sets, is refused; cub <entity> explain lists the fields
  -h, --help                                  help for create
      --hidden-reason string                  hide the entity, giving the reason as a name such as Archived: lists and bulk operations leave it out unless --include-hidden names the reason (use '-' to clear, which shows the entity again)
      --import string                         source unit slug (single mode only)
      --include-hidden string[="*"]           Also select hidden entities, to list or to act on: those hidden for the given HiddenReasons, comma-separated, as in --include-hidden=BackingUnit, or for any reason when given no value or "*". ConfigHub/YAML Units, which hold the configuration of other entities, are hidden with the reason BackingUnit. A --where naming entities by Slug or ID selects them whether hidden or not
      --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)
  -o, --output string                         Output format. One of: json, yaml, name, wide, mutations, jq=<expr>, yq=<expr>, custom-columns=<spec>
      --permission strings                    permission in format Action:UserIDOrUsername, Action:group:GroupSlugOrID for a group you belong to, or Action:serviceaccount:ServiceAccountSlugOrID (e.g., Manage:user@example.com, View:group:platform, View:serviceaccount:deploy-bot, can be repeated)
      --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 a bare --upstream-unit slug is looked up in; defaults to --space (single mode only)
      --upstream-unit string                  upstream unit to clone: a slug, <space>/<slug>, or UUID (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

      --component string   the Component of --variant, when that names the variant alone; --variant <component>/<variant> says the same in one flag
      --context string     The context to use for this command
      --debug              Debug output
      --space string       space to operate in, by slug or UUID. Omitted, a list or bulk operation spans the organization and a single entity is named as <space>/<slug>; "*" means the same as omitting it
      --variant string     variant to operate in, as <component>/<variant>, or as <variant> with --component: the space naming that Component whose Variant label is <variant>. The same scope as --space, named by what it is rather than by the space's slug; the two cannot be combined

SEE ALSO