Skip to main content

AnythingLLM Common

This document provides a reference for the modules/AnythingLLM_Common Terraform module. AnythingLLM_Common is an internal shared module called by both AnythingLLM_CloudRun and AnythingLLM_GKE. It is not intended to be called directly by users.


1. Module Overview

AnythingLLM Common encapsulates all AnythingLLM-specific configuration that is shared between the Cloud Run and GKE deployment targets:

  • Secret generation: Provisions JWT_SECRET, AUTH_TOKEN, SIG_KEY, and SIG_SALT in Secret Manager.
  • Application config: Builds the config local consumed by AnythingLLM CloudRun and AnythingLLM GKE via their application_modules locals.
  • Storage: Returns a pre-configured storage_buckets list containing the anythingllm-docs GCS bucket definition.
  • Initialization jobs: Supplies the default db-init Kubernetes/Cloud Run Job when initialization_jobs is left empty.
  • Environment variables: Sets fixed values for SERVER_PORT, STORAGE_DIR, UID, and GID.

2. Secrets Provisioned

AnythingLLM Common creates the following Secret Manager secrets on first apply:

SecretEnvironment VariablePurpose
<prefix>-jwt-secretJWT_SECRETSigns AnythingLLM authentication tokens.
<prefix>-auth-tokenAUTH_TOKENOptional API bearer token for programmatic access.
<prefix>-sig-keySIG_KEYHMAC signing key (32 alphanumeric characters).
<prefix>-sig-saltSIG_SALTHMAC salt (32 alphanumeric characters).

All secrets are generated with random_password (32 characters, no special characters) and stored in Secret Manager with automatic replication. A time_sleep of 30 seconds delays the secret_ids output until Secret Manager has fully propagated the new versions. The secret_ids output is consumed by the Application Module and forwarded to App CloudRun or App GKE as module_secret_env_vars.


3. Fixed Environment Variables

The following environment variables are injected into every AnythingLLM container by AnythingLLM Common:

VariableValuePurpose
SERVER_PORT3001AnythingLLM HTTP port. Must match container_port.
STORAGE_DIR/app/server/storageAnythingLLM document and vector storage directory.
UID1000Container user ID.
GID1000Container group ID.

Do not override these variables via environment_variables in the Application Module — they are set by AnythingLLM Common and the Application Module merges them before passing to the Foundation Module.


4. Default Initialization Job

When initialization_jobs is passed as an empty list ([]), AnythingLLM Common supplies a single default job:

FieldValue
namedb-init
descriptionCreate AnythingLLM Database and User
imagepostgres:15-alpine
script_path<module_path>/scripts/create-db-and-user.sh
execute_on_applytrue
cpu_limit1000m
memory_limit512Mi
timeout_seconds600
max_retries1

The create-db-and-user.sh script idempotently creates the AnythingLLM PostgreSQL database user and database. It connects to Cloud SQL via the Auth Proxy Unix socket (Cloud Run) or TCP 127.0.0.1 (GKE) and uses ROOT_PASSWORD from Secret Manager.

To replace the default job, pass a non-empty initialization_jobs list to the Application Module.


5. Storage Bucket

AnythingLLM Common returns a single pre-configured storage bucket definition in its storage_buckets output:

FieldValue
name<resource-prefix>-anythingllm-docs
name_suffixanythingllm-docs
storage_classSTANDARD
force_destroytrue
public_access_preventioninherited

The Application Module sets GOOGLE_CLOUD_STORAGE_BUCKET_NAME to module.anythingllm_app.storage_buckets[0].name in module_env_vars.


6. Variables

AnythingLLM Common accepts a subset of the variables from the Application Module. These are passed through from the caller — do not modify AnythingLLM Common directly.

VariableTypeDefaultDescription
project_idstringGCP project ID.
tenant_deployment_idstring'demo'Deployment environment identifier.
regionstring'us-central1'GCP region.
deployment_idstring""Unique deployment ID.
resource_labelsmap(string){}Labels applied to all resources.
application_namestring'anythingllm'Base name for resources and secrets.
application_versionstring'latest'Container image version tag.
display_namestring'AnythingLLM'Human-readable application name.
descriptionstring'AnythingLLM — Private AI Workspace and RAG Platform'Application description.
db_namestring'anythingllmdb'Database name used in the db-init script.
db_userstring'anythingllmuser'Database user created by the db-init script.
cpu_limitstring'2000m'CPU limit (forwarded to container_resources).
memory_limitstring'4Gi'Memory limit (forwarded to container_resources).
min_instance_countnumber1Minimum instances/replicas.
max_instance_countnumber1Maximum instances/replicas.
startup_probeobject{ enabled=true, path="/api/ping", initial_delay_seconds=60, ... }Startup probe configuration.
liveness_probeobject{ enabled=true, path="/api/ping", initial_delay_seconds=30, ... }Liveness probe configuration.
environment_variablesmap(string){}Additional environment variables. Merged with fixed vars.
enable_cloudsql_volumebooltrueEnables Cloud SQL Auth Proxy sidecar.
initialization_jobslist(any)[]Custom initialization jobs. Empty triggers the default db-init.

7. Outputs

OutputDescription
configFull application configuration object consumed by Application Module application_modules local.
storage_bucketsList containing the anythingllm-docs bucket definition.
secret_idsMap of environment variable names to Secret Manager secret IDs: { JWT_SECRET, AUTH_TOKEN, SIG_KEY, SIG_SALT }.
secret_valuesMap of secret plaintext values (sensitive). Used for validation only — not consumed by Application Modules.
pathAbsolute path to the AnythingLLM Common module directory. Used by Application Modules to resolve scripts_dir.