Deploy Memcached with Terraform
Bahriya provides managed Memcached instances that run alongside your containers. Use them for session caching, query result caching, or any key-value workload that benefits from in-memory speed.
Bahriya provides managed Memcached instances that run alongside your containers. Use them for session caching, query result caching, or any key-value workload that benefits from in-memory speed.
Required fields
| Field | Type | Example | Description |
|---|---|---|---|
handle | string | "session-cache" | Permanent identifier. Cannot be reused after deletion. |
name | string | "Session Cache" | Display name. |
memorymb | number | 512 | Cache size in megabytes. An integer, not a string. |
activeregions | list | ["helsinki-1"] | One or more regions to deploy to. |
project | string | bahriya_project.x.id | The project UUID (not handle). |
Minimal example
resource "bahriya_project" "app" {
handle = "my-app"
name = "My Application"
regions = ["falkenstein-1"]
}
resource "bahriya_memcached" "cache" {
handle = "app-cache"
name = "Application Cache"
memorymb = 512
activeregions = ["falkenstein-1"]
project = bahriya_project.app.id
}Multi-region cache
When deployed to multiple regions, each region gets its own independent cache. Caches are not synchronised across regions.
resource "bahriya_memcached" "cache" {
handle = "session-cache"
name = "Session Cache"
memorymb = 1024
activeregions = ["falkenstein-1", "helsinki-1", "virginia-1"]
project = bahriya_project.app.id
}Connecting from a container
Memcached instances are reachable from containers in the same project over the internal network on port 11211:
<memcached-handle>.<org-handle>-<project-handle>:11211Pass this as an environment variable to your container:
resource "bahriya_container" "api" {
# ... other required fields ...
newenvvar {
key = "MEMCACHED_HOST"
value = "app-cache.myorg-my-app:11211"
}
}Available memory sizes
The platform supports: 64 MB, 128 MB, 256 MB, 512 MB, 1024 MB (1 GB), 2048 MB (2 GB), 4096 MB (4 GB), 8192 MB (8 GB).
Outputs
| Attribute | Description |
|---|---|
id | Memcached instance UUID. |
status | Current status (running, provisioning, terminated, etc.). |
output "cache_status" {
value = bahriya_memcached.cache.status
}Notes
memorymbis an integer (e.g.512), not a string. This differs from container fields likemincpuwhich are strings.- Handles cannot be reused after deletion (soft-delete).
- Each region runs an independent cache — there is no cross-region replication.