cleandataengineering.aiData Platform, from the big picture to the code
You are here: Start here › Deploy

Data PlatformZoom level 1

Deployment: from a fresh checkout to a first run, with a gate at every stage

After you check out the code, deployment is fifteen steps. Some are automated by Terraform, the asset bundle and CI. Some are manual and will stay manual: signing in, accepting an account, putting a secret's value in. Between the steps there is a gate: a script that checks, without changing anything, that the step really happened. You do not start a step until the gate before it passes.

The gates

GateWhat it provesRun it with
G0tools, the catalog checkout, no keys in gitpython3 scripts/preflight.py --gate G0
G1access: AWS, Databricks, GitHub (and which services a policy denies)--gate G1 --databricks-profile NAME --aws-profile NAME
G2after the account setup: state bucket and CI roles exist--gate G2
G3after the infrastructure deploy: buckets, keys, secrets, catalogs, volume, external locations--gate G3 --env dev
G4after the metadata store setup: the Lakebase database exists--gate G4 --env dev
G5after the bundle deploy: the jobs exist and validate--gate G5 --env dev
G6after the first run: a report is in the volume--gate G6 --env dev

All gates are one script, scripts/preflight.py. It only lists and describes, so it is safe to run anywhere, any number of times. A failed check prints the step that fixes it. A check that depends on a failed one is skipped, so you see the first real problem and not a pile of follow-on errors. Optional things (Lakebase, a SQL warehouse) are warnings, not failures. Secrets are never printed: the account number is masked, and a key found in a file is reported by file name only.

ExampleWhat a run looks like (an example, not a recording)
python3 scripts/preflight.py --gate G1 --databricks-profile dev --aws-profile dev
[PASS] T1  Python 3.11 or newer: 3.12.4
[PASS] A1  signed in to AWS: arn:aws:iam::<account>:user/you
[FAIL] A2  S3 is allowed: AccessDenied: explicit deny in a service control policy
       fix A2: ask the account owner to lift the policy that denies S3 (step 2)
[skip] A9  Terraform state bucket: needs A2 first

The steps

StepWhat to doWhoNoteGate after it
0Check out the code and the catalog; install Python, uv, Terraform 1.10+, the AWS CLI v2, the Databricks CLI, rsyncmanualInstalling tools is a person's job.G0
1Run the offline checks: tests, bundle check, Terraform validateautomatedmake -C realms/aws-databricks check. Needs no account.G0
2Sign in to AWS: aws configure sso, then aws sso login. If a policy denies a service, ask the account ownermanualThe preflight lists exactly which services answer and which are denied.G1
3Create the Databricks account on AWS. Do not create a workspace in the quickstart. Note the account idmanualTerraform creates the workspaces.G1
4In the account console: group platform-admins, service principal dp-ci (account admin, in the group), a federation policy for GitHub ActionsmanualNot created by Terraform. Terraform needs an admin identity to exist first.G1
5Make your local values file: copy infra/envs/dev.tfvars to dev.local.tfvars and fill in the prefix and idsmanualThe .local.tfvars file is git-ignored. Real values never go in a tracked file.G0
6Sign in to Databricks: databricks auth login --host https://accounts.cloud.databricks.com --account-id ID, and a profile for the workspace latermanualOpens a browser.G1
7make bootstrap (state bucket), then make account (GitHub OIDC roles, the regional metastore, tags). Copy metastore_id into your local fileautomatedTerraform and the AWS CLI do it. A person starts it once and copies two outputs.G2
8Lakebase: check it is offered in the region. If not, set lakebase_enabled = false. Otherwise make the project, then run meta_setup.pymanual, then automatedThe probe is a decision. The database, schemas, functions and manifest load are one idempotent script.G4
9make deploy ENV=dev: infrastructure, then the asset bundleautomatedBuckets, keys, secrets, roles, workspace, catalogs, volume, jobs.G3
10Put the secrets' values: aws secretsmanager put-secret-value .... Give dp-ci the admin role in the new workspacemanualTerraform makes the secret, never its value.G3
11GitHub: environments dev and prod (reviewers on prod), the repository and environment variables, then DEPLOY_ENABLED = true lastmanualSettings in the GitHub web page. Not code.G5
12Run the job once: databricks bundle run engine_days (3 days). Look at the operations page it leaves in the volumemanual, then automatedA person starts it. The run, its checks and the report are automatic.G6
13From here on: a pull request runs the checks and a real plan. A merge deploys dev and runs the integration test. Prod waits for a reviewer, then deploys the same commitautomatedThe one manual act is the approval click on prod.G6
14A day after the first deploy: switch on activate_cost_tags and run make account againmanual, then automatedSo the cost tags appear in billing.G6

What is code and what is by hand

ThingWhere it comes fromCode or by hand
S3 buckets per layer, KMS key, IAM rolesTerraform: modules/storage, network, github_cicode
Secret containers (Secrets Manager)Terraform: modules/secretscode
Secret valuesaws secretsmanager put-secret-valueby hand, never in git
Kinesis, SNS, log group, budgetTerraform: modules/stream, alerts, budgetcode
Workspace, metastore assignment, storage credential, external locationsTerraform: modules/workspace, unity_catalogcode
Catalogs by layer, schemas, landing volumeTerraform: modules/unity_catalogcode
LakebaseTerraform modules/lakebase creates an instance. Lakebase has moved from instances to projects: verify the module against your workspacecode, to verify
Metadata store schemas and the manifestmeta_setup.pyautomated, run by a person
Jobs and pipelinesAsset bundle: realms/databricks/engine, benchmarking/databrickscode
Group, service principal dp-ci, federation policyAccount consoleby hand
Admin role for dp-ci in each workspaceWorkspace settingsby hand
GitHub environments, variables, reviewersRepository settingsby hand
Your own account valuesinfra/envs/NAME.local.tfvarsby hand, git-ignored

Keys never go in git

Three rules, all checked by the gate G0. Real account values live in NAME.local.tfvars, which is git-ignored, and Make passes it after the tracked file. Secret values live only in the secret store. Tokens (a Databricks login, a Power BI token) come from the environment or a sign-in, and are held in the running process only. The gate checks that the ignore patterns are in place, scans every tracked text file for key-shaped text, and runs gitleaks over the history if it is installed.

Setting up Lakebase, the metadata database

The metadata store is a PostgreSQL database on Lakebase, one per environment. Setting it up is four steps, the last three in one idempotent script.

  1. Check. Lakebase must be offered in your region and tier. The gate G1 warns if it is not. If not, set lakebase_enabled = false and the same store binds to plain PostgreSQL.
  2. Create. A Lakebase project or instance named for the environment. Terraform has a module for it; verify it against your workspace, because Lakebase changed from instances to projects.
  3. Wake and connect. A disabled endpoint is enabled, and a short-lived token is minted from your login. It lives in the process only.
  4. Install and load. realms/aws-databricks/meta_setup.py creates the database, installs the schemas and functions, loads the manifest, and reads it back as a check.
ExampleLoad the tyre manifest and record the table format and silver engine on every dataset
python3 realms/aws-databricks/meta_setup.py --instance dp-meta-dev \
    --manifest ~/data-platform-catalog/slices/02-tyre/manifest \
    --table-format delta-uc-uniform --silver-engine job

The table format and silver engine are stored beside each dataset and are part of its fingerprint, so a run record shows which format it ran on. Be aware that today the run itself takes the table format from the job's parameter, not from the store, so the stored value documents the run and does not change it.

Fixing a failed gate

What you seeWhat to do
G0 fails: a tool is old or missingInstall or upgrade the tool named. Terraform must be 1.10 or newer; the Databricks CLI must have bundles.
G0 fails: key-like text in a tracked fileRemove it, rotate the key, and keep the value in the secret store. The check names the file, never the value.
G1 fails: a service answers AccessDeniedAn organisation policy or a missing permission denies it. Ask the account owner. For Kinesis alone, set streams = {}.
G1 fails: Databricks loginRun databricks auth login again. The token may have expired.
G2 fails: the state bucket is not reachableRun make bootstrap. The bucket name is in account.backend.hcl.
G3 fails: a catalog is missingmake deploy did not finish. Read its Terraform error, fix, run it again. It is idempotent.
G3 fails: the secret does not existTerraform did not create it, or the prefix in your local file differs from the one used at deploy.
G4 fails: no LakebaseCreate the project, wake a disabled endpoint, then run meta_setup.py. Or set lakebase_enabled = false and bind plain PostgreSQL.
G5 fails: the bundle does not validateRead the message it prints. Usually a wrong profile or a missing variable.
G6 fails: no report in the volumeThe run failed. Open the job run, then the operations page of the last run.
The run says a table or schema already existsSafe: every step is idempotent. Run it again.

Day two: changing things

ChangeHow
A new datasetAdd its manifest and contract in the catalog, load with meta_setup.py or the loader, deploy the bundle. No pipeline code.
A new environmentA new NAME.local.tfvars and a make deploy ENV=NAME. The gates take --env NAME.
A different table formatChange the job's table_format parameter and the stored setting. See Orchestration, end to end.
A rollbackRe-run the deploy at the previous commit. Terraform and the bundle are both declarative.
Not built yet, or known gaps
  • Nothing has been deployed on Databricks on AWS yet. The infrastructure is written and checked offline (validate and a plan on mocked providers). Only the Free Edition Databricks half was ever deployed, and its AWS half was blocked by the account's policy.
  • The service principal, group and federation policy are made by hand. They could be Terraform at the account level once a first admin exists. That is not written.
  • The Lakebase module creates the older instance shape. Lakebase has moved from instances to projects, so the module needs checking before the first real run.
  • There is no gate that proves the manifest is loaded: that needs a database login, and the gate script only lists. meta_setup.py reads it back and says so.
  • Gate G6 checks that a report exists, not that its numbers equal the world's truth. That judgement is in the report itself.
  • The steps were written from the realm's README, Makefile and workflow files. They have not been run end to end on a fresh account.