Terraform stacks
Three Terraform modules under terraform/spanway/ deploy the gateway, backend and UI as separate containers on managed compute, together with the infrastructure around them. They come with the deployment files in your onboarding pack. The modules contain only HCL and pull the published images. Each is a plain module with no provider block of its own, so you can call it with for_each, count and depends_on and keep region, credentials and tags under your control. A ready-to-run root lives at <stack>/examples/default/ for the one-command path.
| Stack | Compute | Database | Cache | Object store | Entrypoint |
|---|---|---|---|---|---|
aws/ | ECS Fargate | Aurora Postgres writer and reader, IAM authentication | ElastiCache for Redis | S3 | Application Load Balancer |
gcp/ | Cloud Run | Cloud SQL for PostgreSQL with a read replica, password authentication | Memorystore | Cloud Storage | External HTTPS load balancer |
azure/ | Container Apps | PostgreSQL Flexible Server with a read replica, password authentication | Azure Cache for Redis | Storage account with Data Lake Gen2 | Front Door |
Every stack uses the four componentised images: spanway-gateway on 4000, spanway-backend on 4001, spanway-ui on 3000 and spanway-migrations for the one-off schema migration. The load balancer routes the gateway's data-plane prefixes to the gateway, the UI asset paths to the UI and everything else to the backend, mirroring the componentised Helm chart ingress. The prefix list is the same one the gateway itself keeps, and a test fails the build when the stacks or the chart drift from it. The one exception is the generic /<provider>/ pass-through, which a load balancer rule cannot express, so call providers that have no named pass-through through a named or custom pass-through endpoint instead.
A real-world scenario
A team needs the same gateway layout in two regions. They call the stack as a module with for_each over the regions from their own Terraform root, keep provider credentials and tags under their control, and get one load balancer URL per region from the outputs.
Steps
-
Copy
<stack>/examples/default/for your cloud and set the inputs in Inputs every stack shares. -
Mirror the four images into a registry the stack can pull from and set the image inputs, because the release images are private during the preview and the default tag
v2.0.0only resolves once 2.0.0 is released. Each cloud's page says how. -
On AWS set
acm_certificate_arn, and on GCP setlb_domains, so the load balancer serves HTTPS. For a short trial setallow_plaintext_alb = trueorallow_plaintext_lb = trueinstead. Without one of them the plan stops, see errors. Azure serves HTTPS on its Front Door hostname with no input. -
Run
terraform initandterraform apply. -
Check the gateway at the URL the stack printed.
curl "$(terraform output -raw alb_url)/health/readiness"On GCP and Azure the output is
lb_url. -
Open the URL followed by
/uiand sign in asadminwith the master key.
Expected result
The apply creates the network and data stores, runs the migration, then starts the gateway, backend and UI. /health/readiness reports the database as connected.
Quick start on any cloud
cd terraform/spanway/<stack>/examples/default
cp terraform.tfvars.example terraform.tfvars
terraform init
terraform apply
Before the apply, edit terraform.tfvars to set the image inputs and the TLS input, as steps 2 and 3 above say. Then one apply creates the network and data stores, runs the schema migration, and only then starts the gateway and backend. When it returns, terraform output prints the URL of the load balancer (alb_url on AWS, lb_url on GCP and Azure) and where the master key was stored. The Admin UI logs in as admin with the master key.
Inputs every stack shares
| Input | What it does |
|---|---|
tenant, env | Every resource is named <tenant>-spanway-<env>, so several tenants and environments coexist in one account |
tags (AWS, Azure) or labels (GCP) | Merged onto every taggable resource, on top of the stack's own managed-by and stack identity tags |
spanway_master_key | Optional. Empty means the stack generates an sk-... key and stores it in the cloud's secret store |
spanway_license | Optional. When set, the stack stores it in the cloud secret store and the gateway, backend and workflow workers receive it as SPANWAY_LICENSE |
workflow_worker_enabled | Optional. Adds a service that runs workflow runner steps and makes the gateway and backend producers. It needs a license with the workflow_runner and workflow_queue_workers features. The sizing inputs differ per cloud and are listed on each stack's page |
ui_password | Optional Admin UI password |
proxy_config | The gateway config as a Terraform map, YAML-encoded and delivered to the gateway and backend. It mirrors gateway.config.proxy_config in the Helm chart. Editing it rolls a new revision |
gateway_extra_env, backend_extra_env | Plain environment variables per component |
gateway_extra_secrets, backend_extra_secrets | Environment variables resolved from the cloud secret store at start, keyed by the variable name the config references with os.environ/NAME |
gateway_num_workers | Uvicorn workers per gateway container |
gateway_connection_pool_enabled, gateway_pool_max_db_connections, gateway_pool_max_client_conn | The in-container PgBouncer, gateway only |
gateway_image, backend_image, ui_image, migrations_image | Per-component image references. GCP and Azure also compose them from image_registry and image_tag. The default is a pinned release tag, v2.0.0, which only resolves once 2.0.0 is released, so until then name the tag from your onboarding pack. The AWS example takes the four image inputs in terraform.tfvars, and the GCP and Azure examples take image_registry and image_tag |
otel_endpoint, otel_exporter, otel_environment_name, otel_capture_message_content | OpenTelemetry export, off until otel_endpoint is set. The headers secret is otel_headers_secret_arn on AWS and otel_headers_secret elsewhere |
billing_metrics_endpoint, billing_metrics_client_cert_pem, billing_metrics_client_key_pem, billing_metrics_ca_cert_pem | Enterprise billable-request metering over mutual TLS, off until the endpoint is set |
collector_enabled, collector_port, collector_cpu, collector_memory, collector_buffer_size, collector_on_unavailable, collector_drain_timeout_seconds | The spend collector sidecar next to the gateway container, listening on loopback TCP |
Secrets go through the cloud secret store, never through tfvars. Provider API keys live in a Secrets Manager entry, a Secret Manager secret or a Key Vault secret, referenced from *_extra_secrets by ARN, resource id or URI, and the YAML in proxy_config names the resulting environment variable. Pass spanway_master_key and spanway_license as TF_VAR_* environment variables for the same reason.
The database and PgBouncer environment variables the stacks set on the containers, such as IAM_TOKEN_DB_AUTH, DATABASE_HOST and SPANWAY_PGBOUNCER_ENABLED, are explained on environment variables.
Coordination Redis needs no input. Each stack provisions the managed Redis and exports REDIS_HOST, REDIS_PORT and REDIS_SSL (plus REDIS_SSL_CA_CERTS on GCP and REDIS_PASSWORD on Azure) into the gateway and backend, which the proxy uses for cross-instance rate limits, spend tracking and the lock manager. Response caching is separate and stays off unless spanway_settings.cache is set in proxy_config. If that Redis cannot be reached, requests that carry a rate limit or a budget get a 503 instead of being admitted, see when Redis is unreachable.
How migrations run
The gateway and backend assume the schema exists, so each stack provisions a one-off task from the spanway-migrations image and triggers it from terraform apply through a local-exec provisioner in bootstrap.tf. The compute services depend on that step, so they do not start until the schema is in place. The provisioner shells out to the cloud CLI (aws ecs run-task, gcloud run jobs execute or az containerapp job start), which therefore has to be installed and authenticated on the machine running Terraform. Remote runners without the CLI, including HCP Terraform's hosted agents, skip that step. Each stack exposes the exact command as the migration_run_command output so you can run it by hand after the first apply or whenever you need a re-run.
Using a stack as a module
module "spanway" {
source = "./terraform/spanway/aws"
region = "us-west-2"
tenant = "examplecorp"
env = "prod"
azs = ["us-west-2a", "us-west-2b"]
}
Because the module declares no provider, the same block works with for_each = toset(["examplecorp", "globex"]) to run one stack per tenant from a single configuration, with an aliased or assume-role provider, or behind count for a conditional environment.
What the stacks leave to you
TLS certificates and DNS names: the AWS stack takes acm_certificate_arn, the GCP stack takes lb_domains and provisions a managed certificate, and the Azure stack serves HTTPS on its Front Door hostname from day one and takes custom domains through lb_domains. Remote state: the examples use local state, so add an s3, gcs or azurerm backend in versions.tf before sharing a stack with a team. Observability beyond the cloud's own logs is wired through *_extra_env or the OpenTelemetry inputs.
Errors
| What you see | What it means | Fix |
|---|---|---|
ALB has no HTTPS listener. Either set acm_certificate_arn to enable TLS, or set allow_plaintext_alb = true to opt into HTTP-only (trial / dev only). | The AWS plan has no certificate and no plaintext opt-in. | Set acm_certificate_arn, or allow_plaintext_alb = true for a trial. |
LB has no HTTPS forwarding rule. Either set lb_domains to a list of DNS names you want a Google-managed cert for, or set allow_plaintext_lb = true to opt into HTTP-only (trial / dev only). | The GCP plan has no domain and no plaintext opt-in. | Set lb_domains, or allow_plaintext_lb = true for a trial. |
Tasks or revisions fail to pull spanway-* images | The images are private during the preview and the stack has no pull credentials. | Mirror the images and set the image inputs, see each cloud's page. |
| The migration step is skipped on a remote runner | The runner has no cloud CLI. | Run the migration_run_command output by hand after the apply. |
terraform apply fails on the migration | The task could not reach the database or the image could not be pulled. | Read the task's log in the cloud console. |
| The services start but answer 500 | The schema is missing because the migration never ran. | Run the migration command. |
Logs
Each stack sends the container output to the cloud's own log service, and that is where the migration result and the gateway's startup lines show up.
| Cloud | Where the logs are |
|---|---|
| AWS | CloudWatch log groups /ecs/<tenant>-spanway-<env>/gateway, /backend, /ui, /migrations, /bootstrap-db and /workflow-worker |
| GCP | Cloud Logging, under the Cloud Run services <tenant>-spanway-<env>-gateway, -backend and -ui and the Cloud Run job <tenant>-spanway-<env>-migrations |
| Azure | The Container Apps environment's Log Analytics workspace, under the gateway, backend and ui apps and the <tenant>-spanway-<env>-migrations job |
A successful migration ends with Migration job completed successfully., and a failed one with Migration job failed after retries. after the Prisma error. The log reference lists both, and the gateway's startup lines are under startup lines.