Infrastructure Configuration Guide
MechCrate supports hierarchical configuration for infrastructure providers like Cloudflare, DigitalOcean, AWS, and Hetzner. This allows you to set up credentials once globally and reuse them across all projects, while still allowing project-specific overrides when needed.
Quick Start
# Set up global credentials (once per workstation)mx infra setup cloudflare
# Create a new project with Cloudflare infrastructuremx new myproject --infra cloudflare
# Link the project to your global credentialscd myprojectmx infra link cloudflare
# Or use project-specific credentials insteadmx cf setupmx cf <cmd> is a thin wrapper over the project’s make cf-<cmd> targets
(make/cloudflare.mk, present when the project was created with
--infra cloudflare): mx cf deploy myapp runs exactly
make cf-deploy a=myapp. mx cf --help lists every wrapped target.
mx aws <cmd> is the same wrapper for a project created with --infra aws:
mx aws up starts the local emulator, mx aws cli s3 ls runs
make aws-cli c="s3 ls" against it, and mx aws sandbox terraform plan runs a
command against the configured sandbox account after mx aws check-sandbox
passes. mx aws --help lists every wrapped target.
Hierarchical Config Resolution
Every credential resolves on its own, highest precedence first:
- The environment (or the
makecommand line) - Project-local config (
./infra/<provider>/.env.<provider>), unless the project is linked to global - Global config (
~/.mech-crate/config/infra/<provider>.env), shared by every project on the workstation
Within a scope the canonical name is read before a deprecated alias
(CLOUDFLARE_ACCOUNT_ID before CF_ACCOUNT_ID), but precedence is by scope,
never by spelling: a project file carrying only the alias still beats a global
file carrying the canonical name. This is the order make/cloudflare.mk
implements, and mx infra inspect <provider> prints the resolved set with the
scope that supplied each key, so the two cannot disagree.
Linking
A project is linked when its .env.<provider> contains the exact line
MX_INFRA_USE_GLOBAL=true. A linked project’s file is not read for values, so
its credentials resolve from the environment, then the global config. That one
line is the whole mechanism, and every reader honors it: mx infra inspect,
make cf-vars / mx cf vars (which print CF_PROJECT_LINKED=true), every
make cf-* target, and scripts/cf-init-app.sh.
mx infra link <provider>adds the line (creating the file if needed) and keeps everything else in the file. It needs a project (run it from the root or below) and an existing global config, and is idempotent.mx infra unlink <provider>removes the line, so the project’s own values apply again. A file that held nothing but the link is deleted. Unlinking an unlinked project is a no-op.
Linking is only needed to make a project with its own .env.<provider> defer
to the global config without deleting that file: a project with no project
file already falls through to global.
The older .env.linked marker file is deprecated and ignored. It was only
ever read by the Rust resolver and written by nothing. mx infra inspect warns
about a stray one, and mx infra link / unlink delete it.
Supported Providers
| Provider | Description | Config File |
|---|---|---|
cloudflare | Cloudflare Workers & Containers | cloudflare.env |
digitalocean | DigitalOcean Droplets & App Platform | digitalocean.env |
aws | Amazon Web Services: local emulator lane plus sandbox-account gate (mx new --infra aws, make aws-*; see local-aws-emulation-architecture.md) | aws.env |
hetzner | Hetzner Cloud | hetzner.env |
Commands
Global Configuration
# Interactive provider selectionmx infra setup
# Configure a specific providermx infra setup cloudflaremx infra setup digitaloceanmx infra setup awsmx infra setup hetzner
# List all configured providersmx infra list
# Show the resolved config for a provider: each key with the scope that# supplied it (environment / project / global, deprecated aliases tagged),# the link state, and both file paths. Secrets are masked.mx infra inspect cloudflare
# Remove a global configmx infra remove cloudflareProject Linking
From within a MechCrate project:
# Link project to global configmx infra link cloudflare
# Remove link (the project's own values apply again)mx infra unlink cloudflare
# Check current config status (alias of mx cf vars)mx cf configConfiguration Files
Global Config Location
~/.mech-crate/config/infra/├── cloudflare.env├── digitalocean.env├── aws.env└── hetzner.envProject Config Location
./infra/<provider>/└── .env.<provider>Link Marker
A linked project’s config file contains the line mx infra link writes:
# Linked to the global config by `mx infra link`; `mx infra unlink` removes this.MX_INFRA_USE_GLOBAL=trueAny other lines in the file are kept, and ignored while the link is in place.
Provider-Specific Configuration
Cloudflare
# Global setupmx infra setup cloudflare
# Project-local setup (if needed)mx cf setup
# Show the resolved credentials and which scope supplied them (make cf-vars)mx cf vars
# Fail early if no account id resolves (make cf-check-credentials)mx cf check-credentials
# Initialize and deploy an app (make cf-init / make cf-deploy)mx cf init api.example.com --type=containermx cf deploy api.example.comConfig Variables:
CLOUDFLARE_ACCOUNT_ID- Your Cloudflare account IDCF_DOCKER_PLATFORM- Docker platform; Cloudflare Containers requirelinux/amd64, the defaultCLOUDFLARE_API_TOKEN- API token for CI/CD (optional)
The two credential names are wrangler’s own, so the value in a config file
reaches the deploy untranslated. CF_ACCOUNT_ID / CF_API_TOKEN are deprecated
aliases: still read at their own scope’s precedence so an older config keeps
working, never written. For Cloudflare specifically, both scopes are read with no
linking required, the project file winning over the global one; make cf-vars
(mx cf vars) prints which scope supplied the account id and
make cf-check-credentials (mx cf check-credentials) fails loudly when none
did. See mx-cloudflare-deploy.md §5 for the as-implemented detail.
DigitalOcean
mx infra setup digitaloceanConfig Variables:
DO_API_TOKEN- Personal Access TokenDO_DEFAULT_REGION- Default region (e.g., nyc3)DO_SPACES_ACCESS_KEY- Spaces access key (optional)DO_SPACES_SECRET_KEY- Spaces secret key (optional)DO_SPACES_REGION- Spaces region (optional)
AWS
mx infra setup awsConfig Variables:
AWS_ACCESS_KEY_ID- AWS access key IDAWS_SECRET_ACCESS_KEY- AWS secret access keyAWS_DEFAULT_REGION- Default region (e.g., us-east-1)
Hetzner
mx infra setup hetznerConfig Variables:
HETZNER_API_TOKEN- Hetzner Cloud API tokenHETZNER_DEFAULT_LOCATION- Default location (e.g., fsn1)
Workflows
Shared Team Setup
When multiple team members work on the same project but have different accounts:
# Each developer sets up their own global configmx infra setup cloudflare
# Project is configured to use global config by defaultcd myprojectmx infra link cloudflare
# Developer B with different account uses project-local insteadmx infra unlink cloudflaremx cf setup # Enter different credentialsCI/CD Setup
For CI/CD pipelines, you typically want to use project-local config with secrets from the pipeline:
# In CI/CD, create the config file directlycat > infra/cloudflare/.env.cloudflare << EOFCLOUDFLARE_ACCOUNT_ID=$CLOUDFLARE_ACCOUNT_IDCF_DOCKER_PLATFORM=linux/amd64CLOUDFLARE_API_TOKEN=$CLOUDFLARE_API_TOKENEOFOr use environment variables directly. For Cloudflare the environment is the highest-precedence scope, above both config files:
export CLOUDFLARE_ACCOUNT_ID=...export CLOUDFLARE_API_TOKEN=...mx cf deploy myappMulti-Account Setup
For projects that deploy to different accounts (staging vs production):
# Project structuremyproject/├── infra/│ └── cloudflare/│ ├── .env.cloudflare # Staging credentials│ └── .env.cloudflare.prod # Production credentials
# Deploy to staging (uses default .env.cloudflare)mx cf deploy myapp
# Deploy to production (export the prod config; the environment wins)set -a; source infra/cloudflare/.env.cloudflare.prod; set +amx cf deploy myappSecurity Notes
- Global configs have 600 permissions - Only readable by the owner
- Config files are gitignored - Never commit credentials
- Secrets are masked in
mx infra inspectoutput - API tokens are optional - Use
wrangler loginfor interactive auth
Troubleshooting
Config not found
# Check what configs existmx infra list
# See detailed status for a providermx infra inspect cloudflare
# For Cloudflare specificallymx cf configWrong config being used
# Check which config is activemx cf vars
# If linked but want localmx infra unlink cloudflare
# If local but want globalmx infra link cloudflareReset configuration
# Remove global configmx infra remove cloudflare
# Remove project link (or delete the project file to drop its values too)mx infra unlink cloudflare
# Start freshmx infra setup cloudflarePart of the MechCrate documentation