Skip to main content
Set APP_EXPERIMENTAL=iac on the control plane and in your shell until v1.1.0. See Experimental features.

1. Write one file

Save this as infra/app.yaml (also at examples/iac/single-app/app.yaml):

2. Preview, then apply

diff changes nothing and exits 2 when the files differ from the live state.

3. Add a database

Add this document to the same file. The app reads the connection by reference, so no password lands in git. A similar full file is examples/iac/app-database/app.yaml.
Then point the app at it with env: { DATABASE_URL: { from: { database: main-db, field: url } } } and run levelrail-cli apply -f infra/ --yes again.

4. Export what exists

Export to a new directory, not the one you apply from.

5. Move it into a stack

A stack gives you a reviewed plan, numbered revisions and rollback. A stack refuses resources that a plain apply already created, because no stack owns them. Start the stack with fresh names. The first stack apply creates the stack, so there is no separate create step.
To bring the resources from step 2 into a stack instead, delete them first. The REST stack apply also accepts adopt: true, which claims existing resources, but the CLI has no flag for it. Next: IaC reference, Cron jobs and alert rules, Importing a deploy.yml or Portainer stack, GitHub Action, Platform as code, Stacks and GitOps.
Last modified on November 17, 2026