chant workspace init
Synopsis
Section titled “Synopsis”chant workspace init [dir] [--name <name>] [--yes] [--verbose]chant workspace init --profile ideation|app|infra [dir] [--name <name>] [--param name=<display name>] [--from <repo>@<ref>|<chant checkout>] [--yes]Description
Section titled “Description”chant workspace init looks at a repository and proposes a workspace declaration for it. It prints the proposal and the directories that would leave the root project, then asks before it writes chant.workspace.json. Without a terminal to ask on, it writes nothing unless --yes is given. Only the file creates a workspace, so nothing changes until you write it (#2525 rule 1).
The root is dir when it’s given, otherwise the top of the git repository holding the current directory. The command refuses to run where a chant.workspace.json or .jsonc already exists.
It runs no project code. It reads file names, package.json files, and the text of each member’s chant.config.ts or chant.config.json for its ownership.stack. In a git repository the file names come from git, which leaves out ignored files and node_modules.
What it proposes
Section titled “What it proposes”| Found | Proposed entry |
|---|---|
a chant.config.ts or chant.config.json at the root | a chant member with directory ".", named root |
| any other outermost chant project | a chant member |
a directory with its own chant.workspace.json | a workspace member; nothing inside it is looked at. One under an examples-style directory is a workspace member too, with a because naming the examples directory it sits in (#4499). When that directory sits inside another package or project, the declaration stays an example of its group, since only the root member contains other members |
| a directory that a kind from an installed package claims, outside any other member (a chart, a kustomize overlay, an Argo app) | a member of that kind, with the package added to pins. It replaces the other member the same directory would get |
an npm workspace package, or any other package.json outside those, with no chant project | an other member, with a because |
chant projects under an examples, example, samples, test, tests or fixtures directory | an example group |
Projects inside a test runner’s directory, such as __fixtures__, stay with the package around them.
An example tree whose subdirectories are mostly projects gets one glob, such as examples/*. Trees that differ in one path segment merge, as lexicons/aws/examples/* and lexicons/gcp/examples/* become lexicons/*/examples/*, when the merged glob claims no member. When the only thing in the way is a member in that last segment, such as a workspace shipped as an example, the glob leaves that directory out by name: examples/!(kit). A tree that is mostly something else lists its projects one by one. Groups are named after the tree: examples, fixtures, or with a prefix such as lexicon-examples.
Member names come from package.json without the npm scope and without a leading <workspace>-, so @intentius/chant-lexicon-aws in the chant workspace becomes lexicon-aws. Without a usable package name, the directory’s name is used. The workspace’s name is --name, else the repository name from the origin remote, else the root package’s name, else the directory’s name.
The proposal is a starting point to review. It is read back through the same validation as any declaration before it is shown.
What leaves the root project
Section titled “What leaves the root project”Before it asks, init prints every member directory and example-group match that would leave the root project, with the number of .ts source files each holds (tests left out). A group’s matches are summed on one line, and a match inside a member’s directory leaves with that member. --verbose prints each directory and file.
DIRECTORY OWNER .TS FILES docs docs 2 33 directories examples 294 lexicons/aws lexicon-aws 337 packages/core core 562 2 directories fixtures 10Once the file is written, root-level chant build, lint, run and audit stop reading these directories (#2527). chant workspace build and its siblings cover them, each member with its own chant (#2537).
Profiles
Section titled “Profiles”--profile starts a workspace from one of the reference workspace’s three profiles instead of proposing one from what is there (#3174, ws-096). Each declares only what its kind of user needs, so nothing about a factory or an app is asked of a workspace that doesn’t build one.
| Profile | What it declares |
|---|---|
ideation | The decision, work and answer record kinds, and a stub app member of the app kind that answers /health and shows the workspace’s name. No box and no factory |
app | The same records, and an app member whose box block runs it as a service and declares the factory: it builds app, and the app’s tests are the verdict |
infra | The same records, and an estate member, network, a chant project on the terraform lexicon. Its box block declares only the factory, checked by a lint and a build, with no app member and no box services, so the factory runs on a fountain steward |
chant init --from copies the profile from reference-workspace/profiles/<profile> in the chant repository at the tag of the chant you run (chant-v<version>). The copy has a lineage lock, so chant workspace upgrade takes later versions of it. --from reads the profiles from another <repo>@<ref>, or from a chant checkout on disk. --param name=<display name> sets the name the stub app shows, and --name sets the declaration’s name. Each profile passes chant workspace check as it is copied.
Importing from another tool
Section titled “Importing from another tool”chant workspace init --from tfc --org <organization> [--input <export.json>] [--token <token>] [dir] [--yes]chant workspace init --from spacelift --endpoint <https://acme.app.spacelift.io/graphql> [--input <export.json>] [--token <token>] [dir] [--yes]chant workspace init --from backstage [dir] [--name <name>] [--yes]--from tfc|spacelift|backstage (#3178) reads structure a repository does not hold and proposes members and links from it, with environments and constraint records. Like plain init, it prints the proposal and what it left out, and writes only on confirmation. Confirming writes chant.workspace.json and chant-import.<source>.json. The second file holds the environments and constraint records, and the list of what was left out.
| Source | Read from | Becomes |
|---|---|---|
| Terraform Cloud | the API (token in --token, TFE_TOKEN or TF_TOKEN_app_terraform_io) or an exported file with --input | a workspace is a terraform member at its working directory; a run trigger is a link to the source’s applied output; an env: tag is an environment; a policy set is a constraint record |
| Spacelift | the GraphQL API (--endpoint, token in --token or SPACELIFT_API_TOKEN) or --input | a Terraform or OpenTofu stack is a terraform member, any other vendor an other member; a dependency is a link on the output it references, else applied; an env: label is an environment; a policy is a constraint record |
| Backstage | the catalog-info.yaml files under dir | a Component or Resource is an other member; dependsOn and consumesApis are links to a catalog output; spec.lifecycle is an environment |
A member is one directory, so workspaces or stacks that share a working directory fold into the first, and the output says so. Some structure is left out, each kind listed with a count and a reason. From the IaC tools that is variable values and VCS connections, contexts and state. From Backstage it is groups and users and systems. The terraform kind comes from @intentius/chant-lexicon-terraform, so pin that package before chant workspace check reads the members. The API readers only read, and are listed under “Importing structure from another tool” in the network egress page.
Promoting a member
Section titled “Promoting a member”chant workspace promote <member> [--state <terraform.tfstate>] [--lexicon <lexicon>] [--dry-run] [--output <patch>] [--json]promote changes one member’s kind: terraform to choudoufu, or choudoufu or other to chant. It stages the change in a git worktree at HEAD and gates it on the patch digest, as workspace upgrade does: the first run records a pending gate and exits 3, chant approve workspace-promote <member> approves that digest, and the same command run again applies the patch.
| From | To | Staging runs |
|---|---|---|
terraform | choudoufu | choudoufu live-check, then the read-only choudoufu live-import report (needs --state). After the approved patch is applied, live-import -approve stamps the ownership markers |
choudoufu | chant | chant import of the member’s directory (--lexicon defaults to terraform) |
other | chant | chant import (needs --lexicon) |
A failing check stops before any gate is recorded, and the tree is unchanged. A member of kind chant has no next kind.
On the terraform to choudoufu change the live-import report is printed, and with --json it is the adoption field: {estate, state, entries, claimed, total}, one entry per resource instance with its address, type, status (VERIFIED, DRIFTED, MISSING, UNTAGGABLE or UNADMITTED_TYPE), liveId, choudoufu’s detail, and claimed, true for the two statuses -approve stamps. --dry-run --json is the read-only way to ask what adopting a root would claim: it stages and checks, records no gate, and leaves the tree as it was. A relative --state is resolved against the current directory before the staging runs.
The digest the gate binds covers the member, the kind change, what the staging wrote outside the declaration and, for choudoufu, the digest of the live-import report, so the approval is for the report the approver read. A report that changes before the apply (a resource drifted, one went missing) is a new digest and waits for a new approval. On apply, the kind change is written into the declaration in the tree, so one member’s uncommitted promotion does not block another’s.
Promoting a workspace in waves
Section titled “Promoting a workspace in waves”chant workspace promote --all [--state-dir <dir>] [--state <member>=<terraform.tfstate>]... [--canary <member>] [--wave-size <n>] [--dry-run] [--json]--all adopts every terraform member into choudoufu (#4461). Without --all, the members named by --state <member>=<path> are the set. Each root goes through the single-member promotion above, so each has its own gate, workspace-promote/<member>, bound to its own live-import report digest, and is approved with chant approve workspace-promote <member>.
The canary, --canary <member> or else the first member in declaration order, is wave 1. The rest follow in declaration order, --wave-size roots a wave (default 5). Roots run one after another within a wave. A root that fails leaves the other roots and the tree as they were, and the rest of its wave is still tried. The next wave runs only when every root of the wave before it landed: applied, already promoted, or staged cleanly under --dry-run. So a failed canary stops every other wave, and a gated root holds the waves after it until it is approved and the command is run again.
The staging worktree has no .terraform/ of its own, so each root’s staging runs choudoufu init -backend=false before live-check and the report, and nothing it installs goes into the patch. The stamp after approval runs in the same staging worktree, so it reads each resource through the providers that init installed there, and the member’s own directory needs none. A retry of a pending stamp stages a worktree of its own first (HEAD plus the tree’s changes to the member) and runs choudoufu init -backend=false in it before the stamp. TF_PLUGIN_CACHE_DIR saves a download per root.
Each root’s state is --state <member>=<path>, else <state-dir>/<member>.tfstate, else terraform.tfstate in the member’s directory. live-import reads a local tfstate of format version 4. A root with a remote backend and no local state is refused by name with the terraform state pull to run first, and a state of another version is refused too. A state kept in the member’s directory has to be ignored by git, since promote refuses a member with uncommitted changes. Only resources of admitted types are stamped: the report lists the rest under UNADMITTED_TYPE and the summary counts them per root.
The command ends with one line per root naming its wave and outcome:
| Outcome | Meaning |
|---|---|
applied | approved, the kind is now choudoufu, and live-import -approve stamped the markers |
already-promoted | the member is already choudoufu; nothing was staged |
gated | a pending gate waits on this root’s digest |
dry-run | staged and checked; no gate recorded |
checks-failed | live-check or the live-import report failed in staging |
refused | the state is not a local version 4 tfstate |
stamp-failed | the kind was written but live-import -approve failed. The promote keeps the stamp as pending in .chant/workspace-promote/<member>.stamp.json, and the same command run again retries only the stamp; the line also prints the live-import -approve command, which is safe to run by hand in a directory where the member’s providers are installed |
failed | anything else that stopped the root, such as uncommitted changes in its directory |
not-run | an earlier wave did not land |
The exit code is 1 when any root failed, else 3 when any root is gated, else 0. Re-running over a workspace that has landed reports every root already-promoted, stages nothing and exits 0. A root with a pending stamp is retried instead, and lands as applied once the stamp passes. --json prints the summary as one document with the waves and each root’s digest, report digest and counts.
Ownership stacks
Section titled “Ownership stacks”Each chant member needs an ownership.stack of its own (#2538, ws-037). Ownership markers carry no member name, so the stack is what tells two members’ resources and receipts apart, and the WSP071 check fails when two members share one (see Ledgers). Init prints one distinct stack per member after the directories that leave the root project:
MEMBER STACK CHANGE api shop keep web web rename from "shop" in services/web/chant.config.json, which another member uses jobs jobs set ownership.stack in services/jobs/chant.config.tsMembers are taken in declaration order, so the root member and then the outermost directories keep their stacks first. A stack that only one member uses is kept. A shared stack stays with the first member that uses it, and each other member gets its member name. A member that sets no stack gets its member name too, with a number added when another member already uses that name. A stack the config computes rather than writes as a plain string is listed as computed, with the member name as the proposal.
The stack stays in the member’s config and the declaration gains no marker key, so init never writes these changes. Apply them by hand. Renaming the stack of a member that is already deployed changes the markers on its resources, so resources deployed under the old stack are no longer matched as that member’s.
Options
Section titled “Options”| Option | Effect |
|---|---|
dir | The directory to propose a workspace for. Defaults to the git root. |
--name <name> | The workspace’s name, in the name grammar. |
--yes | Write the file without asking. |
--verbose | List every directory and file leaving the root project. |
--profile <profile> | Copy the ideation, app or infra profile instead of proposing a declaration. See Profiles. |
--from <source> | With --profile, where the profiles are read: a <repo>@<ref>, or a chant checkout on disk. Defaults to the chant repository at this chant’s release tag. |
--param name=<value> | With --profile, the display name the profile’s stub app shows. |
Exit codes
Section titled “Exit codes”| Code | Meaning |
|---|---|
| 0 | The proposal was shown, and written if confirmed. Declining writes nothing and still exits 0. |
| 1 | A declaration already exists, --name is invalid, dir doesn’t exist, or the profile is unknown or couldn’t be copied. |
Examples
Section titled “Examples”# See what a declaration for this repository would look likechant workspace init
# Write it without a prompt, for a scriptchant workspace init --yes --name acme
# Start an infra workspace whose factory builds its estatechant workspace init estate --profile infra --name estate --yes