This repository contains Terraform infrastructure configuration for the GBFS Validator service, intended for internal use at MobilityData.
Access to any MobilityData-managed Google Cloud environment is restricted unless explicitly authorized.
Deployments are fully automated via GitHub Actions. There is nothing to build or compile manually — the CI pipeline handles everything.
| Environment | GCP Project | Trigger | URL |
|---|---|---|---|
dev |
gbfs-validator-staging |
PR opened/updated, or manual (see below) | https://dev.gbfs.api.mobilitydatabase.org/validate |
qa |
gbfs-validator-staging |
Push to main, or manual (see below) |
https://qa.gbfs.api.mobilitydatabase.org/validate |
prod |
gbfs-validator-prod |
Manual only (see below) | https://gbfs.api.mobilitydatabase.org/validate |
Note:
devandqashare the same GCP project (gbfs-validator-staging). Each environment gets its own Cloud Run service, Artifact Registry path, runtime service account, and Terraform state.prodlives in a separate dedicated project.
client -> Cloudflare (mobilitydatabase.org zone) -> Worker mobilitydata-sites -> Cloud Run (run.app, IAM-protected)
- The public hostnames are served by the
mobilitydata-sitesCloudflare Worker (MobilityData/org-cloudflare-workers,sites/gbfs.api.mobilitydatabase.org/). It accepts onlyPOST /validate(plus the CORS preflight), checks the request, rate limits per IP and forwards it with an ID token of thegbfs-edge-{env}service account. Everything else gets a 404 at the edge and never starts a Cloud Run instance. - Once the legacy load balancer is removed (follow-up change), Cloud Run only accepts requests signed by
gbfs-edge-{env}(roles/run.invoker); until then the publicallUsersinvoker stays and the run.app URL is publicly reachable. Cloud Run uses request-based billing and is capped at 20 instances of 5 concurrent validations (4 vCPU, 4 GiB) in prod and 1 in dev/qa (gbfs-validator/function_config.json). Request limits and capacity: docs/edge-cutover.md. The validator's built-in Swagger UI is turned off; the API docs are on GitHub Pages. - The GCP load balancer and Cloud Armor are kept only during the cutover (
legacy_load_balancer_enabled) and removed in a follow-up change. See docs/edge-cutover.md for the two-step rollout and the manual steps (Worker secrets, DNS, cleanup).
The staging and prod workflows can be triggered manually from the GitHub Actions UI.
Staging (gbfs-validator-staging.yml):
target_environment— choosedev(default) orqaapp_version— optional. The version ofgbfs-validator-javato deploy (e.g.2.0.68). Can also be a snapshot version (e.g.2.0.69-SNAPSHOT). Leave empty to deploy the latest release from Maven Central.
Prod (gbfs-validator-prod.yml):
app_version— optional, same as above.
Both workflows call the shared reusable deployer (gbfs-validator-deployer.yml) which:
- Authenticates to GCP using the deployer service account JSON key
- Builds and pushes a Docker image to Artifact Registry
- Runs
terraform applyto deploy or update the Cloud Run service
Each environment's state is stored under its own prefix in a shared bucket:
- Staging:
mobilitydata-gbfs-validator-state-staging/{env}/terraform/state - Prod:
mobilitydata-gbfs-validator-state-prod/prod/terraform/state
This means terraform apply for one environment cannot affect another.
| Secret | Description |
|---|---|
STAGING_GCP_GBFS_VALIDATOR_SA_KEY |
Deployer SA JSON key for staging (all staging envs) |
PROD_GCP_GBFS_VALIDATOR_SA_KEY |
Deployer SA JSON key for prod |
| Variable | Value | Description |
|---|---|---|
GBFS_VALIDATOR_REGION |
northamerica-northeast1 |
GCP region (shared) |
STAGING_GBFS_VALIDATOR_PROJECT_ID |
gbfs-validator-staging |
Staging GCP project ID |
STAGING_GBFS_VALIDATOR_TF_STATE_BUCKET |
mobilitydata-gbfs-validator-state-staging |
Staging TF state bucket (shared) |
STAGING_GBFS_VALIDATOR_DEPLOYER_SA |
gbfs-deployer-service-account@gbfs-validator-staging.iam.gserviceaccount.com |
Staging deployer SA |
PROD_GBFS_VALIDATOR_PROJECT_ID |
gbfs-validator-prod |
Prod GCP project ID |
PROD_GBFS_VALIDATOR_TF_STATE_BUCKET |
mobilitydata-gbfs-validator-state-prod |
Prod TF state bucket |
PROD_GBFS_VALIDATOR_DEPLOYER_SA |
gbfs-deployer-service-account@gbfs-validator-prod.iam.gserviceaccount.com |
Prod deployer SA |
"All roads lead to Rome!"
There are many paths to reach the same destination. Use the following steps as a guideline and adapt them to your local or organizational requirements.
For more information, refer to the Google Cloud Platform documentation and the Terraform documentation.
These instructions apply when creating a new environment.
devandqaalready exist ingbfs-validator-staging. These steps apply when setting upprod(projectgbfs-validator-prod) or any future environment.
For illustration purposes, the examples below usegbfs-validator-stagingas the project anddevas the environment — substitute accordingly.
gcloud projects create gbfs-validator-staging --name="GBFS Validator Staging"Link your billing account to the new project via GCP Console or CLI.
Create a Firebase project and link it to the GCP project.
Create OAuth client credentials via the APIs & Services > Credentials page.
These credentials will be passed as Terraform variables.
Nothing to do: Cloudflare terminates TLS for the public hostname, and Cloud Run serves its run.app URL over TLS.
Enable Identity Platform in the project and configure authentication providers as needed.
gcloud auth application-default logingcloud config set project gbfs-validator-staginggcloud storage buckets create gs://mobilitydata-gbfs-validator-state-staging \
--project=gbfs-validator-staging \
--location=northamerica-northeast1 \
--uniform-bucket-level-accessCopy infra/backend.conf.rename_me to infra/backend.conf and populate it.
BUCKET_NAME is the full GCS bucket name (e.g. mobilitydata-gbfs-validator-state-staging).
ENVIRONMENT is the environment name (e.g. dev, qa) — it becomes the state prefix to isolate each environment's state within the shared bucket.
# Staging (dev or qa):
scripts/setup-environment.sh gbfs-validator-staging dev
# Prod (uses a separate AR repo):
scripts/setup-environment.sh gbfs-validator-prod prod northamerica-northeast1 gbfs-validatorThis script:
- Creates the deployer service account and grants IAM roles
- Enables required Google APIs
- Creates (or verifies) the shared Artifact Registry repository
- Creates the legacy load balancer's static IPs (
{env}-lb-ipv4,{env}-lb-ipv6) and SSL certificate, needed only whilelegacy_load_balancer_enabledis true
After the first Terraform deploy of the environment, follow docs/edge-cutover.md: create the edge service account key, add the Worker secrets, and hand {env}.gbfs.api.mobilitydatabase.org to the Worker as a Workers Custom Domain (delete its old DNS records; the Custom Domain creates its own record and certificate).
gcloud iam service-accounts keys create deployer-key.json \
--iam-account=gbfs-deployer-service-account@gbfs-validator-staging.iam.gserviceaccount.com \
--project=gbfs-validator-stagingStore the contents of deployer-key.json as the GitHub secret DEV_GCP_GBFS_VALIDATOR_SA_KEY. Delete the local file after.
Copy infra/vars.tfvars.rename_me to infra/vars.tfvars and populate it for local runs.
In CI, this is done automatically by scripts/replace-variables.sh.
cd infra
terraform init -backend-config=backend.confscripts/docker-build-validator.sh --push -version dev-$(($(date +%s)/60))cd infra
terraform apply -var-file=vars.tfvarsHappy coding!
- Locate the service list in the
scripts/setup-environment.shscript - Execute the script:
scripts/setup-environment.sh gbfs-validator-staging dev