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.
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.
Google-managed SSL certificates are created automatically by scripts/setup-environment.sh (step 11 below).
They provision once the DNS A/AAAA records are in place and the load balancer is deployed.
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 global static IPv4 and IPv6 addresses for the load balancer (
{env}-lb-ipv4,{env}-lb-ipv6) - Creates a Google-managed SSL certificate for
{env}.gbfs.api.mobilitydatabase.org
At the end it prints the IP addresses you will need for DNS.
After running the setup script, ask your DNS administrator (Cloudflare) to create:
| Type | Name | Value |
|---|---|---|
A |
{env}.gbfs.api.mobilitydatabase.org |
IPv4 printed by the script |
AAAA |
{env}.gbfs.api.mobilitydatabase.org |
IPv6 printed by the script |
Note: DNS proxy must be disabled (grey cloud in Cloudflare) to allow Google-managed cert provisioning.
The SSL certificate will complete provisioning automatically once DNS resolves to the load balancer IP.
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