drift Docs
Pages
drift Docs
Start
What is Drift?
The tour, if you are new here.
Use cases
Whether Drift does your thing.
Getting started
Nothing to deployed, in one command.
Architecture
How a slice is put together.
What it costs
The free grant, four unit prices, two rules.
Moving off Azure
Estimate, snapshot and transform a resource group.
Build
Canvas
Static sites, same origin as your API.
Tools
Operate
Auth
Route gates, API keys and your account.
Teams
More than one person on one account.
Security
Boundaries, sandboxing and hardening.
Troubleshooting
Error codes
What went wrong, and what to do about it.
Legal
Acceptable use
What a slice may not be used for.
Data processing
The DPA, and every sub-processor.

Environments: per-environment deploys

Ship the same project to several places: production, a staging copy, a throwaway dev slice. An environment block declares another slice from the same file, and variable blocks say what differs between them. drift plan staging shows what the staging slice would change, and drift apply staging makes it so, creating the slice when it does not exist.

Each environment is a slice of its own, with its own bill.

A project with prod and staging environments is two slices, links and links-staging, each shaped and priced on its own. They are separate in every sense: their own data, their own URL, their own bill. drift plan staging quotes the staging slice's price before drift apply staging agrees to it.

An environment changes only what a variable carries, plus its slice. There is no per-environment override of whole sections and no merging: the file is written once, and a variable stands wherever a value should differ.

Driftfile
slice "links" {}

variable "memory" {
  default = "64MiB"
}

variable "store" {
  default = "64MiB"
}

variable "rate" {
  default = "600/min"
}

variable "seed" {
  default = "backbone/seed.jsonl"
}

environment "prod" {}

environment "staging" {
  vars = {
    memory = "32MiB"
    store  = "16MiB"
    rate   = "60/min"
    seed   = "backbone/demo.jsonl"
  }
}

environment "dev" {
  slice = "links-sandbox"
  vars  = { memory = "16MiB" }
}

atomic {
  backend "default" {
    function "POST /shorten" {
      handler = "PostShorten"
      memory  = var.memory
    }
  }
}

backbone {
  nosql "links" {
    size = var.store
    seed = var.seed
  }
}

edge {
  rate_limit = var.rate

  site_auth {
    realm = "links"
    paths = ["*"]
    user "review" {
      password = env("REVIEW_PASS")
    }
  }
}

Here links is production, links-staging is a free slice with a smaller Function booking, a 16MiB collection, a lower rate limit and demo rows, and links-sandbox is a development slice that books less memory and keeps everything else.

The blocks

attributesmeaning
  • variable "name"
    attributes
    default
    meaning
    A value the file reads as var.name. It can be a string, number, bool, list or map.
  • environment "name"
    attributes
    vars, slice
    meaning
    Another slice from the same file. vars is a map of the variables it sets, by name; slice names the slice it applies to.

A variable takes the environment's value from vars, else its default. A variable with neither is an error at its line. An environment that sets a variable no variable block declares is an error too. A value in vars is a string, and it is read as the number or bool the attribute needs, so n = "7" fills depth = var.n.

A variable stands for an attribute's value: a memory booking, a size, a rate limit, a seed path, a list of allowed addresses. A block's label, such as a Function's route or a collection's name, is written out.

Which slice an environment is

The name is derived, not declared:

environment applies to
prod and productionthe bare slice, here links
any other, such as stagingslice-environment, here links-staging
any, with slice = "..."the slice it names, here links-sandbox for dev

The slice name follows the name rules, so slice-environment is at most 32 characters. An environment the file does not declare is refused, naming the ones it does:

Driftfile

Driftfile:1:1: Unknown environment: there is no environment "nope": the file declares staging

Working with an environment

command does
drift plan stagingCompares the file, with staging's variables, to the links-staging slice, and quotes its price
drift apply stagingCreates or resizes that slice, then deploys into it
drift apply plan.jsonApplies a plan file; it records the environment it was planned for
drift file run stagingBuilds and runs the staging project locally
drift file test stagingRuns its test blocks against the local run
drift file resolve --env stagingPrints the shape the file compiles to for staging: every booking, size and limit. Offline

The plan says which slice it is looking at:

Shell
$ drift plan staging
  · environment staging → slice links-staging

An environment follows the same rule as any slice: its shape decides whether it can be one of your free slices. In the example staging is small enough to fit the free slice, so drift apply staging asks whether to make it one of your free slices; a collection of the production 64MiB would not fit, which is why store is a variable too. There is no separate flag for an environment. drift apply does not yet move an existing slice between free and priced; when a free slice's shape no longer fits it refuses, and drift slice resize makes that move.

Secrets per environment

Config lives in the Driftfile; values that differ per environment live in files beside it. env("NAME") reads a variable from the terminal, then from --var NAME=value, then from .env.environment (for staging, .env.staging), then from .env, in that order. The environment's own file wins over the base one, and --no-env-file skips both.

# .env.staging, beside the Driftfile
REVIEW_PASS=staging-review-pass

The name inside env() is always written out, so the same name carries a different value in each environment. A secret, an API key and a site password are references only, in every environment.

Where an environment can differ

Everything a variable can reach differs per environment: the memory a Function books, a storage size, a limits figure, the rate limit, an edge allowlist, a seed file, an environment variable's value. The edge section describes what each of those settings does, and a variable can stand in any of them.

This is not a CI pipeline: there is no "deploy staging, test, promote prod" orchestration in the Driftfile. Drift gives the verbs; your CI chains them, with plan files.