define* resources (secret() / env()) and for the CLI itself (CARGO_*
variables). This page covers both, and how to deploy the same code to more than
one workspace.
secret() vs env()
Both read a value from process.env at deploy time, but they differ in one
important way — whether the value is tracked in the content hash:
connectors/hubspot.ts
How each behaves
secret("NAME")returns a deferred reference (SecretRef). At apply time the CDK readsprocess.env.NAME, wraps it in Cargo’s encryption envelope, and sends it to the API. If the variable is unset at deploy, the deploy throws. Because the reference — not the value — enters the spec, rotating a secret doesn’t register as drift, and a plaindeploywon’t push the new value (nothing in the hash changed). Re-apply the resource to roll a rotated secret: make any other change, or runcargo-ai cdk deploy --refresh.env("NAME")readsprocess.env.NAMEwhen the file is imported and inlines the value into the spec. If the variable is unset it returns a visible${NAME}placeholder so the gap surfaces incargo-ai cdk plan.
CLI environment variables
Thecargo-ai CLI (and therefore cargo-ai cdk) reads three environment
variables. They take precedence over the saved credentials file
(~/.config/cargo-ai/credentials.json):
In CI or an AI coding agent, set these instead of running
cargo-ai login:
whoami reports the source as environment when a CARGO_API_TOKEN is set,
or credentials-file when it’s reading the saved login.
Promoting code to a second workspace
The same CDK code can deploy to multiple workspaces (e.g. staging → production). Two things change per workspace; the code does not:- Which workspace you target — set
CARGO_WORKSPACE_UUID(or log in to that workspace), socargo-ai cdk deployresolves the right target. - The secret values — provide each environment’s
secret()values via its own environment variables. Becausesecret()resolves fromprocess.envat deploy time, pointing the same code at production keys is just a different set of exported variables.
cargo.state.json
records only uuids, hashes, and outputs — never secret values.
