skip to content
wihan/dev
markdown
browse the dokploy docs

dokploy_server (Resource)

A remote server that Dokploy manages over SSH. Services reference it through their server_id attribute, and Dokploy then builds and runs them on that machine instead of on the Dokploy host.

~> This resource stores the server record only. It does not run the setup that installs Docker and the Dokploy agent on the machine. After the first apply, open Settings > Servers in the Dokploy UI and run Setup Server. The setup is a long job over SSH, and the provider does not model it.

~> Dokploy does not test the SSH connection on create or update. A wrong ip_address, port, username, or ssh_key_id applies successfully and fails at setup time.

Example Usage

terraform
# A remote worker that Dokploy manages over SSH. The record needs a key that
# the root user on the machine accepts.
resource "dokploy_ssh_key" "deploy" {
  name        = "deploy"
  public_key  = file("~/.ssh/dokploy.pub")
  private_key = file("~/.ssh/dokploy")
}

resource "dokploy_server" "worker" {
  name        = "worker-1"
  description = "Runs the production services"
  ip_address  = "203.0.113.10"
  ssh_key_id  = dokploy_ssh_key.deploy.id
  # port, username, server_type, and enable_docker_cleanup keep the Dokploy
  # defaults: 22, root, deploy, true.
}

# After the first apply, open Settings > Servers in Dokploy and run
# "Setup Server": that installs Docker on the machine. The provider does not
# run the setup. Services then run on the worker through server_id:
resource "dokploy_postgres" "db" {
  name           = "db"
  environment_id = dokploy_project.app.production_environment_id
  server_id      = dokploy_server.worker.id
}

# A build server only builds images. Set the SSH port and user when they
# differ from the defaults.
resource "dokploy_server" "builder" {
  name        = "builder"
  ip_address  = "203.0.113.11"
  port        = 2222
  username    = "ubuntu"
  server_type = "build"
  ssh_key_id  = dokploy_ssh_key.deploy.id
}

Schema

Required

  • ip_address (String) IP address or hostname that Dokploy connects to over SSH.
  • name (String) Display name. Dokploy does not enforce a unique name.

Optional

  • command (String) Command that the setup runs on the server instead of the default installation. Omit it for the standard setup. If you remove it from the configuration, the provider clears it on the server.
  • description (String) Free-text description. If you remove it from the configuration, the provider clears it on the server.
  • enable_docker_cleanup (Boolean) Run the daily Docker cleanup on the server. Defaults to true, the Dokploy default.
  • port (Number) SSH port. Defaults to 22.
  • server_type (String) deploy for a server that runs services, or build for a server that only builds images. Defaults to deploy.
  • ssh_key_id (String) Id of the dokploy_ssh_key that Dokploy authenticates with. Omit it to store the record without a key; the setup then cannot run until you set one.
  • username (String) SSH user. Defaults to root, the user that the Dokploy setup script expects.

Read-Only

  • app_name (String) Internal name that Dokploy generates for the server.
  • created_at (String) Creation timestamp from the server.
  • id (String) Server id. The server_id attribute of a service references it.
  • organization_id (String) Id of the organization that owns the server.

Import

Import is supported using the following syntax:

The terraform import command can be used, for example:

shell
terraform import dokploy_server.worker cnWbR6INlpglaAu8MML5X