Skip to main content

AnythingLLM on Google Cloud Run

This document provides a comprehensive reference for the modules/AnythingLLM_CloudRun Terraform module. It covers architecture, IAM, configuration variables, AnythingLLM-specific behaviours, and operational patterns for deploying AnythingLLM on Google Cloud Run (v2).


1. Module Overview

AnythingLLM is a private AI workspace and Retrieval-Augmented Generation (RAG) platform. It allows teams to chat with documents, connect to any LLM provider (OpenAI, Anthropic, Ollama, and others), and build AI-powered knowledge assistants — without sending data to third-party services. AnythingLLM CloudRun is a wrapper module built on top of App CloudRun. It uses App CloudRun for all GCP infrastructure provisioning and injects AnythingLLM-specific application configuration, secrets, and storage configuration via AnythingLLM Common.

Key Capabilities:

  • Compute: Cloud Run v2 (Gen2 recommended), 2 vCPU / 4 Gi by default. min_instance_count = 1 to keep AnythingLLM warm for AI workloads.
  • Data Persistence: Cloud SQL PostgreSQL 15 (required by AnythingLLM's Prisma ORM). GCS document storage bucket auto-provisioned by AnythingLLM Common. Optional NFS for persistent document/vector store data.
  • Security: Four application-level secrets are auto-generated by AnythingLLM CommonJWT_SECRET, AUTH_TOKEN, SIG_KEY, and SIG_SALT — and injected into the container via Secret Manager. Inherits Cloud Armor WAF, IAP, Binary Authorization, and VPC Service Controls from App CloudRun.
  • Caching: Redis is disabled by default (enable_redis = false). Enable for session or cache workloads if required.
  • CI/CD: Cloud Build custom image pipeline by default; Cloud Deploy progressive delivery optional.
  • Reliability: Health probes target /api/ping with a 60-second initial delay to allow model loading and database migration on first boot.

Project & Application Identity

VariableGroupTypeDefaultDescription
project_id1stringGCP project ID. Required.
tenant_deployment_id2string'demo'Short suffix appended to all resource names.
support_users2list(string)[]Email recipients for monitoring alerts.
resource_labels2map(string){}Labels applied to all provisioned resources.
application_name3string'anythingllm'Base resource name. Do not change after initial deployment.
application_display_name3string'AnythingLLM'Human-readable name shown in dashboards.
application_description3string'AnythingLLM Private AI Workspace on Cloud Run'Service description.
application_version3string'latest'Container image version tag.

Wrapper architecture: AnythingLLM CloudRun calls AnythingLLM Common to build an application_config object containing AnythingLLM-specific environment variables, probe configuration, and the db-init job definition. AnythingLLM Common generates and stores JWT_SECRET, AUTH_TOKEN, SIG_KEY, and SIG_SALT in Secret Manager and returns their IDs via module.anythingllm_app.secret_ids. The GOOGLE_CLOUD_STORAGE_BUCKET_NAME environment variable is automatically set from module.anythingllm_app.storage_buckets[0].name. The scripts_dir is resolved to abspath("${module.anythingllm_app.path}/scripts") at apply time.

PostgreSQL note: AnythingLLM uses Prisma ORM and requires PostgreSQL. database_type = "POSTGRES_15" is the default. Do not set this to a MySQL or SQL Server variant.


2. IAM & Access Control

AnythingLLM CloudRun delegates all IAM provisioning to App CloudRun. The Cloud Run SA, Cloud Build SA, IAP service agent, and password rotation role sets are identical to those in App CloudRun.

Application secrets: AnythingLLM Common auto-generates four secrets on first apply:

  • JWT_SECRET — signs AnythingLLM authentication tokens.
  • AUTH_TOKEN — optional API bearer token for programmatic access.
  • SIG_KEY — HMAC signing key for request signatures (32+ characters).
  • SIG_SALT — salt used alongside SIG_KEY for HMAC signatures (32+ characters).

These secrets are stored in Secret Manager and injected natively at Cloud Run revision start. Plaintext is never written to Terraform state.

Database initialisation identity: The db-init Cloud Run Job runs under the Cloud Run SA. It connects to Cloud SQL PostgreSQL via the Auth Proxy Unix socket (since enable_cloudsql_volume = true by default), using DB_HOST (the socket path under /cloudsql), DB_USER, and ROOT_PASSWORD (from Secret Manager).

120-second IAM propagation delay: Inherited from App CloudRun — the AnythingLLM service is not deployed until the delay completes, preventing secret-read failures on the first revision start.


3. Core Service Configuration

A. Compute (Cloud Run)

AnythingLLM is a Node.js application that performs AI embedding and LLM inference operations. It has higher resource requirements than typical web applications.

min_instance_count = 1 is recommended to keep AnythingLLM warm and avoid cold starts for AI document ingestion and chat operations. max_instance_count = 1 is the default — AnythingLLM's local storage model means multiple instances require NFS for consistent document access.

Startup CPU Boost is always enabled (hardcoded in App CloudRun).

Container image: container_image_source defaults to 'custom', meaning Cloud Build compiles a custom AnythingLLM image using AnythingLLM_Common's Dockerfile. Set container_image_source = 'prebuilt' and container_image = '<image-uri>' to skip the build and deploy an existing image.

VariableGroupDefaultDescription
deploy_application4trueSet false for infrastructure-only deployment (SQL, storage, secrets).
container_image_source4'custom''custom' builds via Cloud Build. 'prebuilt' deploys an existing image URI.
container_image4""Override image URI. Leave empty for Cloud Build to manage the image.
container_build_config4{ enabled=true }Cloud Build configuration: dockerfile_path, context_path, build_args, artifact_repo_name.
enable_image_mirroring4trueMirrors the container image into Artifact Registry before deployment.
cpu_limit4'2000m'CPU per instance. 2 vCPU minimum for AI workloads.
memory_limit4'4Gi'Memory per instance. 4 Gi minimum for embedding and inference.
min_instance_count41Minimum instances. Set to 1 to avoid cold starts.
max_instance_count41Maximum instances. Increase with NFS for shared document access.
container_port43001AnythingLLM's native HTTP port.
container_protocol4'http1''http1' or 'h2c'.
execution_environment4'gen2'Gen2 required for NFS mounts and GCS Fuse.
timeout_seconds4300Max request duration. Increase for long-running document ingestion.
enable_cloudsql_volume4trueInjects Cloud SQL Auth Proxy sidecar for database connectivity.
cloudsql_volume_mount_path4'/cloudsql'Container path for the Auth Proxy Unix socket.
traffic_split4[]Percentage-based canary/blue-green traffic allocation.
service_annotations4{}Advanced Cloud Run annotations.
service_labels4{}Labels applied to the Cloud Run service.

Differences from App CloudRun defaults:

VariableApp CloudRunAnythingLLM CloudRunReason
container_port80803001AnythingLLM's native port.
cpu_limit'1000m''2000m'AI workloads require more CPU for embedding and inference.
memory_limit'512Mi''4Gi'LLM context, document vectors, and Prisma ORM require more RAM.
min_instance_count01Keep warm for AI operations; cold starts are expensive.
health probe path'/healthz''/api/ping'AnythingLLM's health endpoint.

B. Database (Cloud SQL — PostgreSQL 15)

AnythingLLM uses Prisma ORM and requires PostgreSQL. database_type = "POSTGRES_15" is the default set by AnythingLLM Common. The entrypoint script constructs the DATABASE_URL Prisma connection string from the platform-injected DB_* variables at container start time, working correctly on both Unix socket (Cloud Run) and TCP (GKE) connections.

VariableGroupDefaultDescription
database_type12'POSTGRES_15'Cloud SQL engine. AnythingLLM requires PostgreSQL.
application_database_name12'anythingllmdb'PostgreSQL database name. Do not change after initial deployment.
application_database_user12'anythingllmuser'Database user. Password auto-generated and stored in Secret Manager.
database_password_length1232Auto-generated password length. Range: 16–64.
enable_auto_password_rotation12falseAutomated zero-downtime password rotation.
rotation_propagation_delay_sec1290Seconds to wait after rotation before restarting the service.
db_host_env_var_name12""Additional env var name to expose DB_HOST. Leave empty to inject only DB_HOST.
db_user_env_var_name12""Additional env var name to expose DB_USER.
db_name_env_var_name12""Additional env var name to expose DB_NAME.
db_port_env_var_name12""Additional env var name to expose DB_PORT.
service_url_env_var_name12""Additional env var name to expose CLOUDRUN_SERVICE_URL.

C. Storage (NFS & GCS)

NFS is disabled by default (enable_nfs = false). For multi-instance deployments or persistent document/vector store access, enable NFS. Requires execution_environment = 'gen2'.

GCS document bucket: AnythingLLM Common automatically provisions a dedicated anythingllm-docs GCS bucket. The GOOGLE_CLOUD_STORAGE_BUCKET_NAME environment variable is set to this bucket name automatically. This bucket is separate from any additional buckets in storage_buckets.

VariableGroupDefaultDescription
create_cloud_storage11trueSet false to skip bucket creation. The anythingllm-docs bucket from AnythingLLM Common is always provisioned.
storage_buckets11[{ name_suffix = "data" }]Additional GCS buckets beyond the auto-provisioned docs bucket.
enable_nfs11falseProvisions a Cloud Filestore NFS instance. Required for multi-instance AnythingLLM deployments.
nfs_mount_path11'/mnt/nfs'Container path where the NFS share is mounted.
nfs_instance_name11""Name of an existing NFS GCE VM. Leave empty to auto-discover.
nfs_instance_base_name11'app-nfs'Base name for an inline NFS GCE VM when none exists.
gcs_volumes11[]GCS buckets to mount via GCS Fuse (requires gen2).
manage_storage_kms_iam11falseCreates a CMEK KMS keyring/key and enables CMEK on all storage buckets.
enable_artifact_registry_cmek11falseCreates an Artifact Registry KMS key and enables at-rest CMEK encryption.

D. Networking

Cloud Run uses Direct VPC Egress to reach Cloud SQL's internal IP. With enable_cloudsql_volume = true, the Auth Proxy sidecar handles the Cloud SQL connection via Unix socket.

VariableGroupDefaultDescription
ingress_settings5'all''all' — public internet; 'internal' — VPC only; 'internal-and-cloud-load-balancing' — forces traffic through the HTTPS LB.
vpc_egress_setting5'PRIVATE_RANGES_ONLY''PRIVATE_RANGES_ONLY' routes only RFC 1918 traffic via VPC. 'ALL_TRAFFIC' routes all egress via VPC.

E. Initialization & Bootstrap

A db-init Cloud Run Job is automatically provisioned by AnythingLLM Common when initialization_jobs is left as the default empty list ([]). It uses the postgres:15-alpine image and executes AnythingLLM_Common/scripts/create-db-and-user.sh, which performs the following idempotent operations:

  1. Connects to Cloud SQL PostgreSQL via the Auth Proxy Unix socket.
  2. Creates the AnythingLLM database user with the password from Secret Manager.
  3. Creates the AnythingLLM database if it does not exist.
  4. Grants the user full privileges on the database.

Override initialization_jobs with a non-empty list to replace this default with custom jobs.

VariableGroupDefaultDescription
initialization_jobs13[]One-shot Cloud Run Jobs. Leave empty for AnythingLLM Common to supply the default db-init job. Each entry: name, description, image, command, args, env_vars, secret_env_vars, cpu_limit, memory_limit, timeout_seconds, max_retries, task_count, execution_mode, mount_nfs, mount_gcs_volumes, depends_on_jobs, execute_on_apply, script_path.
cron_jobs13[]Recurring jobs triggered by Cloud Scheduler. Each entry: name, schedule (cron UTC), image, command, args, env_vars, secret_env_vars, cpu_limit, memory_limit, timeout_seconds, max_retries, task_count, parallelism, mount_nfs, mount_gcs_volumes, script_path, paused.
additional_services13[]Additional Cloud Run services deployed alongside AnythingLLM.

4. Advanced Security

A. Cloud Armor WAF

When enable_cloud_armor = true, a Global HTTPS Load Balancer with a Cloud Armor WAF policy (OWASP Top 10, adaptive DDoS, 500 req/min rate limiting) is provisioned in front of Cloud Run.

VariableGroupDefaultDescription
enable_cloud_armor10falseProvisions Global HTTPS LB + Cloud Armor WAF. Required for custom domains and DDoS protection.
admin_ip_ranges10[]CIDR ranges exempted from WAF rules (e.g., office VPN, CI/CD egress IPs).

B. Identity-Aware Proxy (IAP)

When enable_iap = true, Cloud Run's native IAP integration is enabled. Google identity authentication is required before requests reach AnythingLLM. Recommended for internal AI workspace deployments.

VariableGroupDefaultDescription
enable_iap5falseEnables IAP natively on the Cloud Run service.
iap_authorized_users5[]Users/service accounts granted access. Format: 'user:email' or 'serviceAccount:sa@...'.
iap_authorized_groups5[]Google Groups granted access. Format: 'group:name@example.com'.

C. Binary Authorization

When enable_binary_authorization = true, Cloud Run enforces that deployed images carry a valid cryptographic attestation.

VariableGroupDefaultDescription
enable_binary_authorization8falseEnforces image attestation. Requires a Binary Authorization policy and attestor pre-configured in the project.

D. VPC Service Controls

When enable_vpc_sc = true, all GCP API calls from this module are bound within an existing VPC-SC perimeter.

VariableGroupDefaultDescription
enable_vpc_sc22falseRegisters module API calls within the project's VPC-SC perimeter.
vpc_cidr_ranges22[]VPC subnet CIDR ranges for the VPC-SC network access level.
vpc_sc_dry_run22trueLogs VPC-SC violations without blocking. Set false to enforce.
organization_id22""GCP Organization ID for VPC-SC. Required when enable_vpc_sc = true.
enable_audit_logging22falseEnables detailed Cloud Audit Logs.

E. Secret Manager Integration

Four AnythingLLM application secrets are auto-generated by AnythingLLM Common and stored in Secret Manager:

SecretPurpose
JWT_SECRETSigns AnythingLLM authentication tokens.
AUTH_TOKENOptional API bearer token for programmatic access.
SIG_KEYHMAC signing key for request signatures (32+ characters).
SIG_SALTSalt used alongside SIG_KEY for HMAC request signatures.

Additional user-defined secrets can be added via secret_environment_variables (e.g., LLM API keys).

VariableGroupDefaultDescription
secret_environment_variables6{}Map of env var name → Secret Manager secret ID. (e.g., { OPENAI_API_KEY = "anythingllm-openai-key" })
secret_rotation_period6'2592000s'Frequency at which Secret Manager emits rotation notifications. Default: 30 days.
secret_propagation_delay630Seconds to wait after secret creation before dependent resources proceed.

5. Traffic & Ingress

A. HTTPS Load Balancer

When enable_cloud_armor = true, a Global HTTPS Load Balancer backed by a Serverless NEG is provisioned. Traffic flows: Internet → Cloud Armor → Global HTTPS LB → Serverless NEG → Cloud Run.

Setting ingress_settings = 'internal-and-cloud-load-balancing' forces all AnythingLLM traffic through the LB, preventing direct *.run.app URL access.

B. Cloud CDN

When enable_cdn = true (requires enable_cloud_armor = true), Cloud CDN is attached to the HTTPS Load Balancer backend.

AnythingLLM consideration: AnythingLLM is primarily an API-driven application with authenticated sessions. CDN caching is only appropriate for static assets. Ensure proper Cache-Control headers are in place before enabling CDN on the AnythingLLM API endpoints.

VariableGroupDefaultDescription
enable_cdn10falseEnables Cloud CDN on the HTTPS LB backend. Only effective when enable_cloud_armor = true.
max_images_to_retain107Maximum container images to keep in Artifact Registry.
delete_untagged_images10trueAutomatically deletes untagged images from Artifact Registry.
image_retention_days1030Days after which images are eligible for deletion.

C. Custom Domains

VariableGroupDefaultDescription
application_domains10[]Custom domain names for the HTTPS LB. Google-managed SSL certificates provisioned per domain.

6. CI/CD & Delivery

A. Cloud Build Triggers

When enable_cicd_trigger = true, a Cloud Build GitHub connection and push trigger are provisioned.

VariableGroupDefaultDescription
enable_cicd_trigger8falseProvisions a Cloud Build GitHub trigger. Requires github_repository_url and credentials.
github_repository_url8""Full HTTPS URL of the GitHub repository.
github_token8""GitHub PAT (repo, admin:repo_hook scopes). Required on first apply. Sensitive.
github_app_installation_id8""GitHub App installation ID (preferred for organisation repos).
cicd_trigger_config8{ branch_pattern = "^main$" }Advanced trigger config: branch_pattern, included_files, ignored_files, trigger_name, substitutions.

B. Cloud Deploy Pipeline

VariableGroupDefaultDescription
enable_cloud_deploy8falseProvisions a Cloud Deploy pipeline. Requires enable_cicd_trigger = true.
cloud_deploy_stages8[dev, staging, prod(approval)]Ordered promotion stages. Each: name, target_name, service_name, require_approval, auto_promote.

7. Reliability & Scheduling

A. Health Probes & Uptime Monitoring

AnythingLLM exposes /api/ping as its health endpoint. Both the startup and liveness probes target this path. AnythingLLM requires additional startup time for AI model loading and database migration.

VariableGroupDefaultDescription
startup_probe14{ enabled=true, path="/api/ping", initial_delay_seconds=60, timeout_seconds=5, period_seconds=10, failure_threshold=30 }Startup readiness probe. Container receives no traffic until this succeeds.
liveness_probe14{ enabled=true, path="/api/ping", initial_delay_seconds=30, timeout_seconds=5, period_seconds=30, failure_threshold=3 }Liveness probe. Container is restarted after failure_threshold consecutive failures.
startup_probe_config14Same as startup_probeAlias passed to App CloudRun health probe configuration.
health_check_config14Same as liveness_probeAlias passed to App CloudRun liveness probe configuration.
uptime_check_config14{ enabled=true, path="/" }Cloud Monitoring uptime check. Alerts notify support_users if unreachable.
alert_policies14[]Cloud Monitoring metric alert policies.

B. Auto Password Rotation

When enable_auto_password_rotation = true, a zero-downtime password rotation pipeline is provisioned.

VariableGroupDefaultDescription
enable_auto_password_rotation12falseEnables automated password rotation.
rotation_propagation_delay_sec1290Seconds to wait after writing the new secret before restarting the service.

8. Integrations

A. LLM Provider Configuration

AnythingLLM connects to LLM providers via environment variables. Use environment_variables for non-sensitive provider configuration and secret_environment_variables for API keys.

Common AnythingLLM environment variables:

VariablePurposeExample
LLM_PROVIDERLLM backendopenai, anthropic, ollama, native
EMBEDDING_ENGINEEmbedding providernative, openai, ollama
VECTOR_DBVector database backendlancedb, chroma, qdrant, pinecone
SERVER_PORTHTTP port (fixed by AnythingLLM Common)3001
STORAGE_DIRDocument storage path (fixed)/app/server/storage

Store provider API keys in Secret Manager and reference them via secret_environment_variables:

secret_environment_variables = {
OPENAI_API_KEY = "anythingllm-openai-key"
ANTHROPIC_API_KEY = "anythingllm-anthropic-key"
}

B. Redis Cache

Redis is disabled by default for AnythingLLM. Enable it if your deployment requires session caching or a shared cache layer.

VariableGroupDefaultDescription
enable_redis21falseEnables Redis. Not required for AnythingLLM core functionality.
redis_host21nullRedis server hostname or IP. Required when enable_redis = true.
redis_port21'6379'Redis server TCP port (string).
redis_auth21""Redis AUTH password. Sensitive — leave empty if not required.

C. Backup Import & Recovery

VariableGroupDefaultDescription
backup_schedule7'0 2 * * *'Cron expression (UTC) for automated daily backups.
backup_retention_days77Days to retain backup files in GCS.
enable_backup_import7falseTriggers a one-time restore on apply. Set false after a successful import.
backup_source7'gcs''gcs' or 'gdrive'.
backup_file7'backup.sql'Filename of the backup to import.
backup_format7'sql'Backup file format. Options: sql, tar, gz, tgz, tar.gz, zip, auto.

D. Custom SQL Scripts

VariableGroupDefaultDescription
enable_custom_sql_scripts9falseRuns custom SQL scripts from a GCS bucket against the application database.
custom_sql_scripts_bucket9""GCS bucket containing SQL scripts.
custom_sql_scripts_path9""Path prefix within the bucket.
custom_sql_scripts_use_root9falseRun scripts as the root DB user.

9. Platform-Managed Behaviours

The following behaviours are applied automatically by AnythingLLM CloudRun regardless of variable values. They cannot be overridden via tfvars.

BehaviourImplementationDetail
PostgreSQL 15 requireddatabase_type = "POSTGRES_15" fixed by AnythingLLM CommonAnythingLLM's Prisma ORM requires PostgreSQL. MySQL is not supported.
Prisma DATABASE_URLConstructed by anythingllm-entrypoint.sh at container startThe entrypoint script builds the PostgreSQL connection string from DB_* vars injected by App CloudRun.
Application secrets auto-generatedJWT_SECRET, AUTH_TOKEN, SIG_KEY, SIG_SALT provisioned by AnythingLLM CommonGenerated with random_password (32 chars, alphanumeric). Secret IDs are forwarded to App CloudRun via module_secret_env_vars.
GCS document bucketanythingllm-docs bucket provisioned by AnythingLLM CommonThe GOOGLE_CLOUD_STORAGE_BUCKET_NAME env var is set automatically in module_env_vars.
Fixed environment variablesSERVER_PORT=3001, STORAGE_DIR=/app/server/storage, UID=1000, GID=1000Set by AnythingLLM Common. Do not override these in environment_variables.
Unix socket by defaultenable_cloudsql_volume = true defaultAnythingLLM connects to Cloud SQL via the Auth Proxy Unix socket.
Image mirroring enabledenable_image_mirroring = true defaultMirrors the AnythingLLM image into Artifact Registry to avoid Docker Hub rate limits.
Default db-init jobSupplied by AnythingLLM Common when initialization_jobs = []PostgreSQL database and user are created automatically. Override with a non-empty initialization_jobs list to replace.
Scripts directoryscripts_dir = abspath("${module.anythingllm_app.path}/scripts")Initialization scripts are sourced from AnythingLLM Common.

10. Variable Reference

All user-configurable variables exposed by AnythingLLM CloudRun, sorted by UI group then order. Group 0 variables are reserved for platform metadata — leave them at their defaults for standard deployments.

VariableGroupDefaultDescription
module_description0(AnythingLLM platform text)Platform metadata: module description.
module_documentation0(docs URL)Platform metadata: documentation URL.
module_dependency0['Services GCP']Platform metadata: required modules.
module_services0(GCP service list)Platform metadata: GCP services consumed.
credit_cost050Platform metadata: deployment credit cost.
require_credit_purchases0falsePlatform metadata: enforces credit balance check.
enable_purge0truePermits full deletion of module resources on destroy.
public_access0falsePlatform catalogue visibility.
deployment_id0""Deployment ID suffix. Auto-generated if empty.
resource_creator_identity0(platform SA)Service account used by Terraform to manage resources.
impersonation_service_account0""Service account to impersonate for GCP API calls.
project_id1GCP project ID. Required.
region1'us-central1'GCP region for all resources.
tenant_deployment_id2'demo'Short suffix appended to all resource names.
support_users2[]Email addresses for monitoring alerts.
resource_labels2{}Labels applied to all provisioned resources.
application_name3'anythingllm'Base resource name. Do not change after initial deployment.
application_display_name3'AnythingLLM'Human-readable name.
application_description3'AnythingLLM Private AI Workspace on Cloud Run'Service description.
application_version3'latest'Container image version tag.
deploy_application4trueSet false for infrastructure-only deployment.
container_image_source4'custom''custom' (Cloud Build) or 'prebuilt' (existing image).
container_image4""Container image URI. Leave empty for Cloud Build to manage.
container_build_config4{ enabled=true }Cloud Build configuration object.
enable_image_mirroring4trueMirrors the container image into Artifact Registry.
cpu_limit4'2000m'CPU per instance. 2 vCPU minimum for AI workloads.
memory_limit4'4Gi'Memory per instance. 4 Gi minimum for AnythingLLM.
min_instance_count41Minimum instances. Set to 1 to keep AnythingLLM warm.
max_instance_count41Maximum instances.
container_port43001AnythingLLM's native port.
container_protocol4'http1''http1' or 'h2c'.
execution_environment4'gen2'Gen2 required for NFS mounts and GCS Fuse.
timeout_seconds4300Max request duration. Increase for document ingestion.
enable_cloudsql_volume4trueInjects Cloud SQL Auth Proxy sidecar.
cloudsql_volume_mount_path4'/cloudsql'Container path for the Auth Proxy socket.
traffic_split4[]Canary/blue-green traffic allocation.
service_annotations4{}Advanced Cloud Run annotations.
service_labels4{}Labels applied to the Cloud Run service.
ingress_settings5'all''all', 'internal', or 'internal-and-cloud-load-balancing'.
vpc_egress_setting5'PRIVATE_RANGES_ONLY''PRIVATE_RANGES_ONLY' or 'ALL_TRAFFIC'.
enable_iap5falseEnables IAP on the Cloud Run service.
iap_authorized_users5[]Users/SAs granted IAP access.
iap_authorized_groups5[]Google Groups granted IAP access.
environment_variables6{}Plain-text env vars. Do not include secret values.
secret_environment_variables6{}Secret Manager references (e.g., { OPENAI_API_KEY = "anythingllm-openai-key" }).
secret_rotation_period6'2592000s'Secret rotation notification frequency.
secret_propagation_delay630Seconds to wait after secret creation.
backup_schedule7'0 2 * * *'Cron expression (UTC) for automated backups.
backup_retention_days77Days to retain backup files in GCS.
enable_backup_import7falseTriggers a one-time restore on apply.
backup_source7'gcs''gcs' or 'gdrive'.
backup_file7'backup.sql'Backup filename to import.
backup_format7'sql'Backup format. Options: sql, tar, gz, tgz, tar.gz, zip, auto.
enable_cicd_trigger8falseProvisions a Cloud Build GitHub trigger.
github_repository_url8""Full HTTPS URL of the GitHub repository.
github_token8""GitHub PAT. Sensitive.
github_app_installation_id8""GitHub App installation ID.
cicd_trigger_config8{ branch_pattern = "^main$" }Advanced Cloud Build trigger config.
enable_cloud_deploy8falseProvisions a Cloud Deploy pipeline.
cloud_deploy_stages8[dev, staging, prod(approval)]Ordered Cloud Deploy promotion stages.
enable_binary_authorization8falseEnforces image attestation on deployment.
enable_custom_sql_scripts9falseRuns SQL scripts from GCS after provisioning.
custom_sql_scripts_bucket9""GCS bucket containing SQL scripts.
custom_sql_scripts_path9""Path prefix within the bucket.
custom_sql_scripts_use_root9falseRun scripts as the root DB user.
enable_cloud_armor10falseProvisions Global HTTPS LB + Cloud Armor WAF.
admin_ip_ranges10[]CIDR ranges exempted from WAF rules.
application_domains10[]Custom domains with Google-managed SSL certificates.
enable_cdn10falseEnables Cloud CDN on the HTTPS LB backend.
max_images_to_retain107Maximum container images to keep in Artifact Registry.
delete_untagged_images10trueAutomatically deletes untagged images.
image_retention_days1030Days after which images are eligible for deletion.
create_cloud_storage11trueSet false to skip GCS bucket creation.
storage_buckets11[{ name_suffix = "data" }]Additional GCS buckets to provision.
enable_nfs11falseProvisions NFS shared storage. Requires gen2.
nfs_mount_path11'/mnt/nfs'Container path where NFS is mounted.
nfs_instance_name11""Name of an existing NFS GCE VM.
nfs_instance_base_name11'app-nfs'Base name for inline NFS VM.
gcs_volumes11[]GCS buckets to mount via GCS Fuse (requires gen2).
manage_storage_kms_iam11falseCreates CMEK KMS key and enables CMEK on storage buckets.
enable_artifact_registry_cmek11falseCreates Artifact Registry KMS key for at-rest image encryption.
database_type12'POSTGRES_15'Cloud SQL engine. AnythingLLM requires PostgreSQL.
application_database_name12'anythingllmdb'PostgreSQL database name.
application_database_user12'anythingllmuser'Database user.
database_password_length1232Auto-generated password length. Range: 16–64.
enable_auto_password_rotation12falseAutomated zero-downtime password rotation.
rotation_propagation_delay_sec1290Seconds to wait after rotation before restarting.
db_host_env_var_name12""Additional env var name for DB_HOST.
db_user_env_var_name12""Additional env var name for DB_USER.
db_name_env_var_name12""Additional env var name for DB_NAME.
db_port_env_var_name12""Additional env var name for DB_PORT.
service_url_env_var_name12""Additional env var name for CLOUDRUN_SERVICE_URL.
initialization_jobs13[]One-shot Cloud Run Jobs. Leave empty for default db-init.
cron_jobs13[]Recurring scheduled Cloud Run Jobs.
additional_services13[]Additional Cloud Run services alongside AnythingLLM.
startup_probe14{ path="/api/ping", initial_delay_seconds=60, failure_threshold=30, ... }Startup probe. Long delay for AI model loading.
liveness_probe14{ path="/api/ping", initial_delay_seconds=30, failure_threshold=3, ... }Liveness probe.
startup_probe_config14(same as startup_probe)Alias passed to App CloudRun.
health_check_config14(same as liveness_probe)Alias passed to App CloudRun.
uptime_check_config14{ enabled=true, path="/" }Cloud Monitoring uptime check.
alert_policies14[]Cloud Monitoring metric alert policies.
enable_redis21falseEnables Redis. Not required for AnythingLLM core functionality.
redis_host21nullRedis hostname or IP. Required when enable_redis = true.
redis_port21'6379'Redis TCP port (string).
redis_auth21""Redis AUTH password. Sensitive.
enable_vpc_sc22falseRegisters API calls within the project's VPC-SC perimeter.
vpc_cidr_ranges22[]VPC subnet CIDR ranges for VPC-SC network access level.
vpc_sc_dry_run22trueLogs VPC-SC violations without blocking.
organization_id22""GCP Organization ID for VPC-SC.
enable_audit_logging22falseEnables detailed Cloud Audit Logs.

11. Outputs

OutputDescription
service_nameName of the Cloud Run service.
service_urlPublic URL of the Cloud Run service.
service_locationGCP region where the Cloud Run service is deployed.
project_idGCP project ID.
deployment_idDeployment ID suffix used in resource names.
database_instance_nameName of the Cloud SQL PostgreSQL instance.
database_nameName of the application database.
database_userName of the application database user.
database_password_secretSecret Manager secret name for the database password.
database_hostDatabase host IP address (sensitive).
database_portDatabase port.
storage_bucketsCreated GCS storage buckets.
nfs_server_ipNFS server internal IP (sensitive).
nfs_mount_pathNFS mount path inside containers.
container_imageContainer image used for the deployment.
container_registryArtifact Registry repository name.
deployment_summarySummary of the deployment.
initialization_jobsCreated initialization job names.
cicd_enabledWhether the CI/CD pipeline is enabled.
github_repository_urlGitHub repository URL connected for CI/CD.
artifact_registry_repositoryArtifact Registry repository for container images.
cloudbuild_trigger_nameCloud Build trigger name for CI/CD.
monitoring_enabledWhether monitoring is configured.

Configuration Pitfalls & Sensible Defaults

Risk levels: Critical (data loss, full outage, security breach) — High (service unavailable or significant degradation) — Medium (degraded function or increased cost) — Low (minor impact).

VariableSensible DefaultRiskConsequence of Incorrect Value
JWT_SECRET (auto-generated)Random secret stored in Secret ManagerCriticalAnythingLLM uses JWT_SECRET to sign all user authentication tokens. Rotating or changing it immediately invalidates all active sessions and logs out every user. Treat as immutable after first login.
AUTH_TOKEN (optional)"" (no token required)HighAUTH_TOKEN acts as a global API bearer token for AnythingLLM's REST API. If left empty, the API is unauthenticated (only protected by network-level controls). Set a strong value and distribute it only to authorised callers.
STORAGE_DIR / document storageGCS Fuse mountCriticalAnythingLLM stores all workspace documents, vector embeddings, and LLM configuration under STORAGE_DIR. If this directory is not on a persistent volume (GCS Fuse or NFS), all data is lost on every container restart. Never point STORAGE_DIR to the container's local filesystem without a persistent backend.
enable_nfsfalseHighWithout NFS or GCS Fuse, vector indices and uploaded documents are ephemeral. For multi-instance deployments (max_instance_count > 1) shared storage is required or each pod has an inconsistent view of the workspace data.
nfs_mount_path"/mnt/nfs"HighMust match the STORAGE_DIR environment variable passed to AnythingLLM. A mismatch means the app writes to a local path while the NFS mount is unused, and data is lost on restart.
LLM_PROVIDER (via environment_variables)"native" (built-in)CriticalWithout setting the correct LLM_PROVIDER value and corresponding API key, AnythingLLM falls back to its built-in model or errors on all AI requests. When using OpenAI, set LLM_PROVIDER = "openai" and provide OPENAI_API_KEY via secret_environment_variables.
EMBEDDING_ENGINE (via environment_variables)"native"HighThe embedding engine must be consistent across all documents in a workspace. Changing EMBEDDING_ENGINE after ingesting documents makes existing vector indices incompatible — re-ingest all documents after any change.
secret_environment_variables (API keys){} (none)CriticalAI provider API keys (OPENAI_API_KEY, ANTHROPIC_API_KEY, etc.) must be provided via secret_environment_variables pointing to existing Secret Manager secrets. Providing them as plain environment_variables exposes them in Cloud Run revision metadata.
memory_limit4GiHighAnythingLLM loads embedding models into memory during document ingestion. Running the native embedding engine with less than 4 Gi causes OOM-kills during ingestion of large documents.
cpu_limit2000mMediumAnythingLLM AI workloads are CPU-intensive. With less than 2 vCPU, embedding and inference operations run slowly and Cloud Run requests may time out.
min_instance_count1HighScale-to-zero causes 30–60 s cold starts. For a knowledge workspace used interactively, set to 1 to keep a warm instance. With scale-to-zero, in-memory vector index state is rebuilt on each cold start from the persistent storage.
timeout_seconds300HighDocument ingestion for large files (PDFs, long text) can take several minutes. Requests time out with a 504 if timeout_seconds is too low. Increase to 6003600 for document-heavy workloads.
database_type"POSTGRES"CriticalAnythingLLM requires PostgreSQL for workspace metadata, user accounts, and conversation history. Using "NONE" causes the application to fall back to SQLite which is not persistent on Cloud Run.
enable_cloudsql_volumetrueCriticalDisabling the Cloud SQL Auth Proxy while relying on Cloud SQL causes all database connections to fail at startup.
ingress_settings"all"High"all" exposes the AnythingLLM workspace publicly. Only the login form protects it. Enable IAP (enable_iap = true) for production deployments, especially if AUTH_TOKEN is not set.
enable_iapfalseHighWithout IAP, access control relies solely on the application login. Enabling IAP provides an additional authentication layer before the application is reached.
gcs_volumesAuto-provisioned for document storageHighThe GCS volume stores all workspace documents. Without implicit-dirs in the mount options, AnythingLLM cannot list files stored in subdirectories and document browsing fails.
execution_environment"gen2"HighNFS mounts require gen2. If enable_nfs = true with gen1, the NFS volume silently fails to mount and all document writes go to the ephemeral container filesystem.
backup_schedule"" (disabled)HighWithout automated backups, the PostgreSQL metadata database (workspaces, users, settings) is unprotected. Enable and set backup_retention_days for production.
enable_redisfalseLowRedis is optional for AnythingLLM core functionality. If enabled, redis_host must be set or the container will fail to start with a connection error on Redis initialisation.
VECTOR_DB (via environment_variables)"lancedb" (built-in)HighChanging the vector database engine after workspaces have been populated requires re-ingesting all documents. Existing vectors are stored in the previous engine's format and are not automatically migrated.
application_version"latest"MediumAnythingLLM releases may change the database schema. An unplanned upgrade can run migrations that are incompatible with the current schema, crashing startup. Pin to a specific release in production.

Destroying Resources

Known Deletion Issue: Serverless IPv4 Address Release

When destroying a Cloud Run deployment, you may encounter an error similar to:

Error: Error waiting for Subnetwork to be deleted: The following serverless IPv4 address(es) on subnet ... are still in use.

Cause: GCP holds serverless IPv4 addresses on the VPC subnet asynchronously after a Cloud Run service is deleted. These addresses are released by GCP approximately 20–30 minutes after the Cloud Run service is removed.

Resolution: Wait 20–30 minutes after the initial destroy attempt, then re-run:

tofu destroy

The second run will succeed once GCP has released the reserved addresses.