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

dokploy_mariadb (Resource)

A MariaDB database service in a Dokploy environment.

Example Usage

terraform
resource "dokploy_mariadb" "example" {
  name              = "app-db"
  environment_id    = dokploy_project.example.production_environment_id
  database_name     = "app"
  database_user     = "app"
  database_password = var.db_password # use a sensitive variable
  docker_image      = "mariadb:11.4"

  env = <<-EOT
    TZ=UTC
  EOT

  # 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"] }
  # }
}

Schema

Required

  • database_name (String) Name of the MariaDB database.
  • database_user (String) MariaDB 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 database service.

Optional

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

  • 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.
  • 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.
  • args (List of String) Arguments for the container command, in order. A change starts a redeploy. An empty list is not valid. Omit the attribute instead.
  • command (String) Override the container command. A change starts a redeploy.
  • 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 or a fraction such as 0.5 is not valid: the provider rejects it at plan time, because Dokploy would deploy 512m as 512 bytes and 0.5 as no limit. A change starts a redeploy.
  • 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 or a fraction such as 0.5 is not valid: the provider rejects it at plan time, because Dokploy would deploy 512m as 512 bytes and 0.5 as no limit. A change starts a redeploy.
  • database_password (String, Sensitive) MariaDB password. A change starts a redeploy. 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.
  • database_root_password (String, Sensitive) MariaDB root password. If unset, the server generates one. A change starts a redeploy.
  • database_root_password_wo (String, Sensitive, Write-only) Write-only form of database_root_password. Terraform keeps it out of the plan and the state. It needs Terraform 1.11 or later. Do not set it together with database_root_password. A new value reaches the server only when database_root_password_wo_version changes.
  • database_root_password_wo_version (Number) Version of database_root_password_wo. Change it to send the current database_root_password_wo value to the server. A version change starts a redeploy. It needs database_root_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) MariaDB Docker image, for example mariadb:11.4. If you omit it, the server default applies. The server default mariadb:6 does not exist on Docker Hub. A first apply without this attribute creates the record and then fails the deploy, because deploy_on_change defaults to true. Set an explicit tag that exists, for example mariadb:11.4.
  • 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_port (Number) Host port for MariaDB. If unset, the database stays internal.
  • 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 or a fraction such as 0.5 is not valid: the provider rejects it at plan time, because Dokploy would deploy 512m as 512 bytes and 0.5 as no limit. A change starts a redeploy.
  • 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 or a fraction such as 0.5 is not valid: the provider rejects it at plan time, because Dokploy would deploy 512m as 512 bytes and 0.5 as no limit. A change starts a redeploy.
  • 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. A change starts a redeploy. 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.
  • 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. (see nested schema for swarm)

Read-Only

  • created_at (String) Creation timestamp from the server.
  • id (String) MariaDB 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_mariadb.example
  id = "V1StGXR8_Z5jdHi6B-myT"
}

The terraform import command can be used, for example:

shell
terraform import dokploy_mariadb.example V1StGXR8_Z5jdHi6B-myT