skip to content
wihan.dev
view as markdown
browse the dokploy docs

dokploy_libsql (Resource)

A Dokploy libsql service: a distributed SQLite (sqld) database.

~> A replica (sqld_node = "replica") requires sqld_primary_url and cannot set an external port. A primary (sqld_node unset or "primary") must not set sqld_primary_url. Dokploy rejects all three violations at apply time. The provider rejects them earlier, at plan time.

~> A replica does not replicate without command on Dokploy v0.30.5. Dokploy stores the role and the URL and passes them to the container as SQLD_NODE and SQLD_PRIMARY_URL. It also starts sqld with a fixed command that bypasses the image entrypoint, and sqld reads neither variable. The container then runs as a second primary. Set command to sqld --db-path iku.db --http-listen-addr 0.0.0.0:8080 --admin-listen-addr 0.0.0.0:5000 --primary-grpc-url http://<primary app_name>:5001. Verified on the rig (2026-09-05): with that command, a row written on the primary reads back from the replica.

Example Usage

terraform
resource "dokploy_libsql" "example" {
  name              = "edge-db"
  environment_id    = dokploy_project.example.production_environment_id
  database_user     = "libsql"
  database_password = var.db_password # use a sensitive variable
  docker_image      = "ghcr.io/tursodatabase/libsql-server:v0.24.32"

  external_port       = 8080
  external_admin_port = 8081
  external_grpc_port  = 8082

  # The Docker Swarm service specification. Set swarm.mode or replicas, not
  # both. Durations are in nanoseconds.
  # swarm = {
  #   mode      = { replicated = { replicas = 1 } }
  #   placement = { constraints = ["node.labels.tier == db"] }
  # }
}

# A replica follows a primary in the same environment. On Dokploy v0.30.5 the
# role and the URL alone do not make the container replicate; the command
# override does. Do not add --grpc-listen-addr to a replica command.
resource "dokploy_libsql" "replica" {
  name              = "edge-db-replica"
  environment_id    = dokploy_project.example.production_environment_id
  database_user     = "libsql"
  database_password = var.db_password
  sqld_node         = "replica"
  sqld_primary_url  = "http://${dokploy_libsql.example.app_name}:5001"
  command           = "sqld --db-path iku.db --http-listen-addr 0.0.0.0:8080 --admin-listen-addr 0.0.0.0:5000 --primary-grpc-url http://${dokploy_libsql.example.app_name}:5001"
}

Schema

Required

  • database_user (String) LibSQL database user.
  • environment_id (String) Id of the environment that holds this service. Use dokploy_project.production_environment_id for the default environment.
  • name (String) Display name of the libsql service.

Optional

NOTE: Write-only arguments are supported in Terraform 1.11 and later.

  • app_name_prefix (String) Prefix of the Dokploy app name. Dokploy appends -<suffix> (six random lowercase characters) at create and never changes the app name afterwards. Defaults to name. Use lowercase letters, digits, dots, underscores, and hyphens; 56 characters at most. A change replaces the resource. After an import the provider derives the value from app_name.
  • command (String) Override the container command. A replica needs it on Dokploy v0.30.5: sqld --db-path iku.db --http-listen-addr 0.0.0.0:8080 --admin-listen-addr 0.0.0.0:5000 --primary-grpc-url http://<primary app_name>:5001. Do not add --grpc-listen-addr to a replica command; sqld rejects it next to --primary-grpc-url.
  • cpu_limit (String) Hard CPU limit in nano-CPUs, as a whole number in a string: "1000000000" is one CPU, "500000000" half a CPU. Dokploy reads the value with parseInt, so a Docker-style suffix such as 512m deploys as 512 bytes and a fraction such as 0.5 sets no limit. Use a whole number.
  • cpu_reservation (String) Reserved CPU in nano-CPUs, as a whole number in a string: "250000000" is a quarter CPU. Dokploy reads the value with parseInt, so a Docker-style suffix such as 512m deploys as 512 bytes and a fraction such as 0.5 sets no limit. Use a whole number.
  • database_password (String, Sensitive) LibSQL database password. Set this attribute or database_password_wo.
  • database_password_wo (String, Sensitive, Write-only) Write-only form of database_password. Terraform keeps it out of the plan and the state. It needs Terraform 1.11 or later. Set exactly one of database_password and database_password_wo. A new value reaches the server only when database_password_wo_version changes.
  • database_password_wo_version (Number) Version of database_password_wo. Change it to send the current database_password_wo value to the server. A version change starts a redeploy. It needs database_password_wo.
  • deploy_on_change (Boolean) Deploy after a create, and after a change to an attribute that starts a deploy. Defaults to true.
  • deployment_timeout (String) The maximum wait for a deploy to reach a terminal status, as a Go duration string. Defaults to "15m". On timeout, the apply fails, but the deploy continues on the server.
  • description (String) Free-form description.
  • detach_dokploy_network (Boolean) Detach the shared dokploy-network from this service. Defaults to false. It has an effect only together with network_ids, and it applies on the next deploy.
  • docker_image (String) LibSQL Docker image, for example ghcr.io/tursodatabase/libsql-server:v0.24.32. That tag is also the server default when you omit the attribute, and it exists in the registry.
  • enable_namespaces (Boolean) Enable sqld namespaces, the multi-database mode. Defaults to false.
  • env (String) Extra environment variables in the native Dokploy multiline KEY=value format. Use Terraform sensitive variables for secret values. An omitted value and "" both read back as null. Omit the attribute to clear it.
  • external_admin_port (Number) Host port for the libsql admin interface. Not permitted when sqld_node is replica.
  • external_grpc_port (Number) Host port for the libsql gRPC replication interface. Not permitted when sqld_node is replica.
  • external_port (Number) Host port for the libsql HTTP interface. Not permitted when sqld_node is replica.
  • memory_limit (String) Hard memory limit in bytes, as a whole number in a string: "536870912" is 512 MiB. Dokploy reads the value with parseInt, so a Docker-style suffix such as 512m deploys as 512 bytes and a fraction such as 0.5 sets no limit. Use a whole number.
  • memory_reservation (String) Reserved memory in bytes, as a whole number in a string: "268435456" is 256 MiB. Dokploy reads the value with parseInt, so a Docker-style suffix such as 512m deploys as 512 bytes and a fraction such as 0.5 sets no limit. Use a whole number.
  • network_ids (Set of String) Ids of the Dokploy network records to attach this service to. The attachment applies on the next deploy. Omit it to keep only the default dokploy-network. An empty set is not valid. Omit the attribute instead.
  • replicas (Number) Number of container replicas. Defaults to 1. If swarm.mode is set, Dokploy uses the mode and ignores this attribute. Set replicas or swarm.mode, not both: the provider rejects the pair at plan time.
  • server_id (String) Id of the remote server that runs the service. Defaults to the Dokploy host.
  • sqld_node (String) Topology role: primary or replica. A replica requires sqld_primary_url, and cannot have any external port. On Dokploy v0.30.5 the stored role alone does not make the container replicate; set command as the resource note describes.
  • sqld_primary_url (String) URL of the primary sqld node, for example http://<primary app_name>:5001. Required when sqld_node is replica. The server rejects it when sqld_node is not replica, which includes the default primary. Dokploy passes it to the container as SQLD_PRIMARY_URL, which sqld does not read; see command.
  • swarm (Attributes) The Docker Swarm service specification. Each attribute maps to one Dokploy column and keeps the Docker field names in snake case. Omit the block to write null to every column. A change starts a redeploy when deploy_on_change is true. This service type has no ulimits column, so the provider rejects that attribute. (see nested schema for swarm)

Read-Only

  • app_name (String) Internal Dokploy app name, <app_name_prefix>-<suffix>. The server generates it at create. You cannot set it; set app_name_prefix instead.
  • created_at (String) Creation timestamp from the server.
  • id (String) LibSQL service id.
  • status (String) Service status from Dokploy.

Nested Schema for swarm

Optional:

Nested Schema for swarm.endpoint_spec

Optional:

Nested Schema for swarm.endpoint_spec.ports

Optional:

  • protocol (String) Protocol: tcp, udp, or sctp.
  • publish_mode (String) Publish mode: ingress or host.
  • published_port (Number) Port on the host or on the routing mesh.
  • target_port (Number) Port in the container.

Nested Schema for swarm.health_check

Optional:

  • interval (Number) Time between two checks, in nanoseconds.
  • retries (Number) Number of failed checks after which the container is unhealthy.
  • start_period (Number) Time after the start in which a failed check does not count, in nanoseconds.
  • test (List of String) The check command, for example ["CMD", "curl", "-f", "http://localhost"].
  • timeout (Number) Time after which a check fails, in nanoseconds.

Nested Schema for swarm.mode

Optional:

Nested Schema for swarm.mode.global

Nested Schema for swarm.mode.global_job

Nested Schema for swarm.mode.replicated

Optional:

  • replicas (Number) Number of tasks.

Nested Schema for swarm.mode.replicated_job

Optional:

  • max_concurrent (Number) Maximum number of tasks that run at the same time.
  • total_completions (Number) Number of tasks that must complete.

Nested Schema for swarm.network

Optional:

  • aliases (List of String) Network aliases of the service.
  • driver_opts (Map of String) Driver options of the network attachment.
  • target (String) Name or ID of the network.

Nested Schema for swarm.placement

Optional:

Nested Schema for swarm.placement.platforms

Required:

  • architecture (String) The CPU architecture, for example amd64.
  • os (String) The operating system, for example linux.

Nested Schema for swarm.placement.preferences

Required:

Nested Schema for swarm.placement.preferences.spread

Required:

  • spread_descriptor (String) The node label to spread over, for example node.labels.zone.

Nested Schema for swarm.restart_policy

Optional:

  • condition (String) Condition to restart a task: none, on-failure, or any.
  • delay (Number) Time between two restarts, in nanoseconds.
  • max_attempts (Number) Number of restarts before Swarm stops the attempts.
  • window (Number) Time to wait before Swarm decides that a restart worked, in nanoseconds.

Nested Schema for swarm.rollback_config

Required:

  • order (String) Order of the tasks: start-first or stop-first.
  • parallelism (Number) Number of tasks that roll back at the same time. The value 0 means all tasks at once.

Optional:

  • delay (Number) Time between two batches, in nanoseconds.
  • failure_action (String) Action if a task fails: continue, pause, or rollback.
  • max_failure_ratio (Number) Fraction of failed tasks that the service tolerates, from 0 to 1.
  • monitor (Number) Time to watch each task for a failure after it starts, in nanoseconds.

Nested Schema for swarm.ulimits

Required:

  • hard (Number) The hard limit.
  • name (String) Name of the limit, for example nofile.
  • soft (Number) The soft limit.

Nested Schema for swarm.update_config

Required:

  • order (String) Order of the tasks: start-first or stop-first.
  • parallelism (Number) Number of tasks that update at the same time. The value 0 means all tasks at once.

Optional:

  • delay (Number) Time between two batches, in nanoseconds.
  • failure_action (String) Action if a task fails: continue, pause, or rollback.
  • max_failure_ratio (Number) Fraction of failed tasks that the service tolerates, from 0 to 1.
  • monitor (Number) Time to watch each task for a failure after it starts, in nanoseconds.

Import

Import is supported using the following syntax:

In Terraform v1.5.0 and later, the import block can be used with the id attribute, for example:

terraform
import {
  to = dokploy_libsql.example
  id = "V1StGXR8_Z5jdHi6B-myT"
}

The terraform import command can be used, for example:

shell
terraform import dokploy_libsql.example V1StGXR8_Z5jdHi6B-myT