The Terraform configuration inDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/luisumit/LaPreviaRestobar/llms.txt
Use this file to discover all available pages before exploring further.
infra/terraform/ provisions all Google Cloud and Firebase resources needed to run the La Previa Restobar backend. It uses the hashicorp/google and hashicorp/google-beta providers (~> 6.0) and requires Terraform >= 1.5.0. Resources are organized across dedicated .tf files for Cloud Run and Artifact Registry, Firebase, IAM, Secrets, and Auth — making each concern independently readable and maintainable.
Prerequisites
Before running any Terraform command, ensure the following tools are installed and authenticated:- Terraform
>= 1.5.0— Install Terraform - Google Cloud SDK (
gcloud) — Install gcloud - An authenticated
gcloudaccount with Owner or Editor permissions on the target project:
Input Variables
All variables are declared invariables.tf (core) and cloud_run.tf (backend-specific). Copy terraform.tfvars.example to terraform.tfvars and fill in your values before running terraform apply.
Core Variables
| Variable | Description | Default |
|---|---|---|
project_id | Firebase/Google Cloud project ID | "laprevia-restobar" |
region | Default region for cloud resources | "us-central1" |
Backend / Cloud Run Variables
| Variable | Description | Default |
|---|---|---|
backend_artifact_registry_repository_id | Artifact Registry repository ID for backend Docker images | "laprevia-backend" |
backend_artifact_registry_location | Location of the Artifact Registry repository | "us-central1" |
backend_image_name | Docker image name for the backend | "api-firebase" |
backend_image_tag | Docker image tag | "latest" |
backend_cloud_run_service_name | Name of the Cloud Run service | "laprevia-backend" |
backend_cloud_run_min_instances | Minimum Cloud Run instance count | 0 |
backend_cloud_run_max_instances | Maximum Cloud Run instance count | 2 |
backend_cloud_run_cpu | CPU allocated to each container | "1" |
backend_cloud_run_memory | Memory allocated to each container | "512Mi" |
backend_cloud_run_allow_public_invoker | Allow unauthenticated public access | true |
backend_service_account_json_secret_id | Secret Manager secret ID for the Firebase Admin JSON | "laprevia-backend-firebase-service-account-json" |
backend_service_account_json_secret_version | Secret version to mount at runtime (null to skip) | null |
Set
backend_service_account_json_secret_version to "latest" once you have manually uploaded the Firebase service account JSON value into Secret Manager. Leave it as null during initial provisioning to avoid a dependency error on a non-existent secret version.Resources Provisioned
Artifact Registry
google_artifact_registry_repository.backend creates a Docker image repository in us-central1 named laprevia-backend. The Cloud Build service account is granted roles/artifactregistry.writer and the Cloud Run service agent is granted roles/artifactregistry.reader.
Cloud Run Service
google_cloud_run_v2_service.backend deploys the Express.js backend container with the following configuration:
- Port:
3000 - Environment variables injected at runtime:
NODE_ENV=productionFIREBASE_DATABASE_URL— resolved from the Firebase Realtime Database instance URL outputFIREBASE_SERVICE_ACCOUNT_JSON— mounted from Secret Manager whenbackend_service_account_json_secret_versionis notnull
- Scaling: configurable min/max instances via variables (default 0–2)
- Traffic: 100% routed to the latest revision
Public Invoker (Optional)
google_cloud_run_v2_service_iam_member.public_invoker grants roles/run.invoker to allUsers when backend_cloud_run_allow_public_invoker = true. Disable this for production deployments that require authenticated callers.
Firebase Realtime Database
A Firebase Realtime Database instance is provisioned in the region specified byrealtime_database_region. The instance ID defaults to laprevia-restobar-default-rtdb.
Firebase Android Apps
google_firebase_android_app.main— the primary Android app (com.laprevia.restobar)google_firebase_android_app.staging— an optional staging app (com.laprevia.restobar.staging), created only whencreate_staging_android_app = true
Identity Platform / Auth
google_identity_platform_config.default configures Firebase Authentication with:
- Email/password sign-in enabled (password required)
- Anonymous sign-in disabled
- Duplicate emails disallowed
- Auto-deletion of anonymous users enabled
- Authorized domains:
localhost,laprevia-restobar.firebaseapp.com,laprevia-restobar.web.app
IAM Service Accounts
| Service Account | Account ID | Roles |
|---|---|---|
| Cloud Run runtime | laprevia-backend-run | roles/firebasedatabase.admin |
| Cloud Build deployer | laprevia-backend-build | roles/artifactregistry.writer, roles/run.developer |
roles/iam.serviceAccountUser on the runtime service account so it can deploy new revisions.
Secret Manager
google_secret_manager_secret.backend creates a secret named laprevia-backend-firebase-service-account-json with automatic replication. Terraform only creates the secret shell — it does not upload any secret value. Upload the Firebase Admin SDK JSON manually after terraform apply:
roles/secretmanager.secretAccessor on this secret.
Enabled APIs (Phase 2)
The following Google Cloud APIs are enabled automatically when phase 2 resources are provisioned:artifactregistry.googleapis.comcloudbuild.googleapis.comiam.googleapis.comrun.googleapis.comsecretmanager.googleapis.com
Outputs
Afterterraform apply completes, the following values are available via terraform output:
| Output | Description |
|---|---|
backend_cloud_run_url | Public HTTPS URL of the deployed Cloud Run backend service |
backend_container_image | Full image reference used by Cloud Run (Artifact Registry path) |
backend_artifact_registry_repository | Name of the Artifact Registry Docker repository |
project_id | GCP/Firebase project ID managed by this configuration |
firebase_project_number | Firebase project number |
android_app_id | Firebase App ID for the main Android app |
staging_android_app_id | Firebase App ID for the staging Android app (or null) |
realtime_database_url | Firebase Realtime Database URL injected into Cloud Run |
realtime_database_instance_name | Full resource name of the Realtime Database instance |
Deployment Steps
Copy and populate terraform.tfvars
Copy the example vars file to At minimum, review and set these values in
terraform.tfvars and fill in your project’s values:terraform.tfvars:Review the plan
Inspect all resources Terraform will create or modify before applying:Review the output carefully. No changes are made at this stage.
Building and Pushing the Docker Image
After Terraform has provisioned the Artifact Registry repository, build the backend Docker image locally frombackend/ and push it to the registry. Use the repository path printed in the backend_container_image output.
terraform apply updates the service.