In this guide, we’ll deploy a router endpoint to Google Cloud Run with Terraform, following an approach inspired by Apollo’s official deployment guide.
Apollo GraphQL
Containerization with Docker
Google Cloud Platform (GCP)
Infrastructure as Code via Terraform
Automated CI/CD using Azure DevOps Pipelines (Terraform validation + deployment)
Before proceeding, ensure the following are installed and configured:
- Google Cloud Project
- Create a free Google Cloud Account
- Install the gcloud CLI
- Terraform
- Install the Terraform CLI
- Apollo GraphQL Account
- Create a free Apollo GraphQL Account
- Create a
Graph(Supergraph) - Store these values to your GCP Secret Manager
apollo-api-key-> APOLLO_KEY- e.g. service::
apollograph-id-> APOLLO_GRAPH_REF (e.g.<graph-name>@current)
- This repository provides the infrastructure and pipeline setup needed to deploy and publish a Subgraph to an Apollo Supergraph
# Authenticate your GCP account
gcloud init
# Set your default project
gcloud config set project <my-project-id>
# Configure application default credentials (for SDKs and integrations)
gcloud auth application-default login# Clone repository
git clone https://github.com/mel-cdn/apollo-graphos-router-google-cloud-run.git
cd apollo-graphos-router-google-cloud-run# Move to Terraform path
cd ./terraform
# Initialize Terraform with your remote backend
terraform init --backend-config="bucket=<terraform-state-gcs-bucket>"
# Format Terraform configuration files
terraform fmt
# Validate configuration
terraform validate
# Generate execution plan
terraform plan \
-var="project_prefix=$(GCP_PREFIX)" \
-var="environment=$(ENVIRONMENT)" \
-var="region=$(GCP_REGION)" \
-var="root_domain_name=$(ROOT_DOMAIN_NAME)" \
-out=tfplan
# Apply changes
terraform apply tfplanAPOLLO_KEY=<APOLLO_KEY> rover subgraph publish <APOLLO_GRAPH_REF> \
--schema="./tmp/schema.graphql" \
--name="subgraph-name" \
--routing-url="https://<subgraph-graphql-api-url>/graphql"