DigitalOcean Terraform Module
Provision a Flo node on DigitalOcean with Terraform — droplet, firewall, cloud-init, and optional cluster wiring.
The terraform-digitalocean-flo module provisions a production-ready Flo node on DigitalOcean. It handles the droplet, firewall, cloud-init installation, and optional cluster formation in a single terraform apply.
Registry: floruntime/flo/digitalocean
Quick Start
module "flo" {
source = "floruntime/flo/digitalocean"
version = "~> 0.0.1"
ssh_key_ids = [data.digitalocean_ssh_key.main.id]
# The firewall opens only SSH unless you name who may connect.
api_allowed_cidrs = ["203.0.113.0/24"]
}
output "endpoint" { value = module.flo.listen_endpoint }
output "dashboard_tunnel" { value = module.flo.dashboard_ssh_tunnel }
terraform init
terraform apply
# Point the CLI at your new node
flo -e "$(terraform output -raw listen_endpoint)" kv set hello world
The Quick Start leaves flo_version unset, so a droplet installs the newest release. In production, pin it to a tag from Releases, e.g. flo_version = "v0.1.0-dev.13", so every droplet runs the same build. The module installs the release's .deb, so the release must ship packages (v0.1.0-dev.13 or later).
What It Provisions
| Resource | Purpose |
|---|---|
| Droplet | Ubuntu 24.04 LTS, configurable size/region |
| Firewall | Inbound rules for SSH, wire protocol, dashboard, and cluster ports |
| Cloud-init | Installs the release's .deb, writes flo.toml, starts flo.service |
| Project attachment | Optional — adds the droplet to a DigitalOcean project |
The cloud-init script runs once per droplet. It:
- Downloads the release's
.debfor the droplet's architecture (flo_version, or the newest release), checks its sha256, and installs it. The package brings/usr/bin/flo, theflosystem user,/var/lib/floand theflo.serviceunit - Mounts the block-storage volume at
/var/lib/flo, if there is one - Writes
/etc/flo/flo.tomlfrom the module inputs - Adds the restart backoff to the unit as a drop-in
- Enables and starts
flo.service
Port Layout
Flo derives all secondary ports from listen_port:
| Service | Default | Formula |
|---|---|---|
| Wire protocol | 9000 | listen_port |
| Prometheus metrics | 9001 | listen_port + 1 |
| Dashboard / REST API | 9002 | listen_port + 2 |
| Peer port (Raft between members) | 9500 | listen_port + 500 |
The firewall automatically opens the correct ports based on your settings:
- SSH — gated by
ssh_allowed_cidrs; the only port open by default - Wire protocol — open when
api_allowed_cidrsnames any ranges (default[]) - Dashboard — open when
enable_dashboard = trueanddashboard_allowed_cidrsnames any ranges (default[]) - Metrics — open only when
expose_metrics = true - Peer port — open when
cluster_enabled = true, gated bycluster_allowed_cidrs
Single Node
The simplest deployment — one droplet with all defaults:
terraform {
required_version = ">= 1.5.0"
required_providers {
digitalocean = { source = "digitalocean/digitalocean", version = ">= 2.40" }
}
}
variable "do_token" { type = string, sensitive = true }
variable "ssh_key_name" { type = string }
provider "digitalocean" {
token = var.do_token
}
data "digitalocean_ssh_key" "main" {
name = var.ssh_key_name
}
module "flo" {
source = "floruntime/flo/digitalocean"
version = "~> 0.0.1"
ssh_key_ids = [data.digitalocean_ssh_key.main.id]
environment = "prod"
region = "lon1"
api_allowed_cidrs = ["203.0.113.0/24"] # where your clients connect from
}
output "ipv4_address" { value = module.flo.ipv4_address }
output "listen_endpoint" { value = module.flo.listen_endpoint }
output "dashboard_ssh_tunnel" { value = module.flo.dashboard_ssh_tunnel }
output "dashboard_url" { value = module.flo.dashboard_url }terraform apply -var-file=variables.tfvars
flo -e "$(terraform output -raw listen_endpoint)" kv set hello world
# The dashboard listens on loopback: forward it, then open it
$(terraform output -raw dashboard_ssh_tunnel) &
open "$(terraform output -raw dashboard_url)"
3-Node Cluster
Provision three droplets: node 1 is the first member, nodes 2 and 3 join it
at its peer port. A reserved IP
for node 1 keeps the seed address stable from the first apply. Every member
proves the same cluster_secret, and a cluster runs one shard. The provider,
the variables and data.digitalocean_ssh_key.main are declared as in the
single-node example above, plus
variable "cluster_secret" { type = string, sensitive = true }, set to what
flo server secret prints. The
cluster_first_member input arrives with module version 0.1.0.
locals {
node_ids = [1, 2, 3]
listen_port = 9000
peer_port = local.listen_port + 500
}
# Reserve a stable IP for each node
resource "digitalocean_reserved_ip" "node" {
for_each = toset([for id in local.node_ids : tostring(id)])
region = "lon1"
}
module "flo" {
for_each = toset([for id in local.node_ids : tostring(id)])
source = "floruntime/flo/digitalocean"
version = "~> 0.1.0"
ssh_key_ids = [data.digitalocean_ssh_key.main.id]
environment = "prod"
region = "lon1"
listen_port = local.listen_port
shards = 1
cluster_enabled = true
cluster_node_id = tonumber(each.key)
cluster_first_member = each.key == "1"
cluster_seeds = each.key == "1" ? [] : ["${digitalocean_reserved_ip.node["1"].ip_address}:${local.peer_port}"]
cluster_secret = var.cluster_secret
api_allowed_cidrs = ["203.0.113.0/24"] # where your clients connect from
}
# Attach each reserved IP to its droplet
resource "digitalocean_reserved_ip_assignment" "node" {
for_each = module.flo
ip_address = digitalocean_reserved_ip.node[each.key].ip_address
droplet_id = each.value.droplet_id
}
output "endpoints" {
value = {
for id, m in module.flo :
id => { listen = "${digitalocean_reserved_ip.node[id].ip_address}:${local.listen_port}" }
}
}
After apply, point your CLI at any node:
flo -e "$(terraform output -json endpoints | jq -r '."1".listen')" \
kv set cluster ok
Node 1 leads a group of one until nodes 2 and 3 have joined it; a restarted member keeps its role from its own data, so the same configuration applies on every later apply.
Configuration Reference
Required
| Variable | Type | Description |
|---|---|---|
ssh_key_ids | list(string) | DigitalOcean SSH key IDs or fingerprints. At least one required. |
Naming & Placement
| Variable | Type | Default | Description |
|---|---|---|---|
environment | string | "dev" | Label used in droplet name and tags |
region | string | "lon1" | DigitalOcean region slug |
droplet_size | string | "s-2vcpu-4gb" | Droplet size. Flo benefits from multiple vCPUs (one shard per CPU) |
image | string | "ubuntu-24-04-x64" | Base image slug |
tags | list(string) | [] | Extra droplet tags |
project_id | string | "" | Optional DO project ID |
Droplet Features
| Variable | Type | Default | Description |
|---|---|---|---|
enable_backups | bool | false | Weekly droplet backups |
enable_monitoring | bool | true | DO monitoring agent |
enable_ipv6 | bool | true | Enable IPv6 |
Firewall
| Variable | Type | Default | Description |
|---|---|---|---|
create_firewall | bool | true | Create a DO firewall. Disable if you manage firewalls externally |
ssh_allowed_cidrs | list(string) | ["0.0.0.0/0", "::/0"] | CIDRs allowed to reach SSH |
api_allowed_cidrs | list(string) | [] | CIDRs allowed to reach the wire-protocol port and extra_inbound_tcp_ports. Empty opens nothing |
dashboard_allowed_cidrs | list(string) | [] | CIDRs allowed to reach the dashboard. Empty opens nothing; also needs dashboard_bind_address = "0.0.0.0" |
metrics_allowed_cidrs | list(string) | ["0.0.0.0/0", "::/0"] | CIDRs for Prometheus (only when expose_metrics = true) |
expose_metrics | bool | false | Open the metrics port on the firewall |
cluster_allowed_cidrs | list(string) | ["0.0.0.0/0", "::/0"] | CIDRs allowed to reach the peer port. Restrict to the cluster's network |
extra_inbound_tcp_ports | list(number) | [] | Additional TCP ports to open |
Flo Installation
| Variable | Type | Default | Description |
|---|---|---|---|
flo_version | string | "" | Release whose .deb to install. Empty = latest. Pin in production |
Flo Runtime
| Variable | Type | Default | Description |
|---|---|---|---|
listen_port | number | 9000 | Wire-protocol port. Metrics = +1, Dashboard = +2 |
bind_address | string | "0.0.0.0" | Bind address for the wire listener |
shards | number | 0 | Number of shards. 0 = auto-detect from CPU count |
durability | string | "async_flush" | Storage durability: sync or async_flush |
hot_buffer_capacity | number | 0 | In-memory hot buffer size in bytes. 0 = default |
log_level | string | "info" | Log level |
enable_metrics | bool | true | Enable Prometheus metrics endpoint |
enable_dashboard | bool | true | Enable dashboard HTTP API + web UI |
dashboard_bind_address | string | "127.0.0.1" | Bind address for the dashboard. On loopback, reach it through dashboard_ssh_tunnel |
Cluster
| Variable | Type | Default | Description |
|---|---|---|---|
cluster_enabled | bool | false | Make this droplet a cluster member (first member or joiner) |
cluster_first_member | bool | false | This droplet starts the cluster and leads alone until others join; leave cluster_seeds empty |
cluster_node_id | number | 0 | This node's id in the cluster (1, 2, 3, …). 0 derives one from hostname and port, which collides on cloned images |
cluster_seeds | list(string) | [] | Peer ports of members to join (host:listen_port + 500); required unless cluster_first_member = true |
cluster_secret | string (sensitive) | "" | The secret every member proves at the peer port, made by flo server secret; required when cluster_enabled = true |
Persistent Storage
By default Flo writes to the droplet's root disk, which means a terraform apply -replace=... wipes all data. Set volume_size > 0 to provision a DigitalOcean block-storage volume, attach it at boot, and mount it at /var/lib/flo. The volume carries prevent_destroy = true, so it survives droplet replacement.
| Variable | Type | Default | Description |
|---|---|---|---|
volume_size | number | 0 | Volume size in GB. 0 keeps data on the root disk |
volume_name | string | "" | Volume name. Empty auto-derives <droplet>-data |
volume_filesystem_type | string | "ext4" | Filesystem for new volumes: ext4 or xfs. Re-attached volumes keep their existing filesystem |
module "flo" {
source = "floruntime/flo/digitalocean"
version = "~> 0.0.2"
ssh_key_ids = [data.digitalocean_ssh_key.main.id]
volume_size = 50 # GB — survives droplet replacement
}
Outputs
| Output | Description |
|---|---|
droplet_id | DigitalOcean droplet ID |
droplet_name | Droplet name |
ipv4_address | Public IPv4 address |
ipv4_address_private | Private VPC IPv4 address |
ipv6_address | Public IPv6 address (empty if disabled) |
urn | Droplet URN |
listen_endpoint | host:port for the CLI and SDKs |
dashboard_url | Dashboard URL: the tunnel's local end while bound to loopback (empty when disabled) |
dashboard_ssh_tunnel | ssh -N -L command that forwards the loopback dashboard (empty when disabled or not on loopback) |
metrics_endpoint | Prometheus metrics URL (empty when disabled) |
peer_endpoint | host:peer_port — what joining nodes list in cluster_seeds |
raft_port | Peer port (listen_port + 500) |
firewall_id | Firewall ID (empty when create_firewall = false) |
volume_id | Volume ID (empty when volume_size = 0) |
volume_name | Volume name (empty when volume_size = 0) |
volume_urn | Volume URN (empty when volume_size = 0) |
Operational Notes
Service management
Flo runs as the flo system user under systemd:
ssh root@$(terraform output -raw ipv4_address)
# View logs
journalctl -u flo -f
# Restart
systemctl restart flo
# Check status
systemctl status flo
Crash loop
If the server fails 10 times within an hour, systemd stops restarting it and leaves flo failed (systemctl status flo). Between attempts it backs off from 5 s to 2 minutes. Read why it failed:
journalctl -u flo -n 200
A server that can't use its data directory (written by an older Flo, after an upgrade that changed the format) exits with code 78, and systemd doesn't restart it. There is no migration: run flo server wipe --data-dir /var/lib/flo --yes as the flo user (it deletes the node's data), then start it.
A panic during log replay happens again on every start until its cause is fixed, so restarting without a fix just loops again. Once fixed:
systemctl reset-failed flo && systemctl start flo
Data directory
Data lives in /var/lib/flo (owned by flo:flo, mode 0750). The packaged unit has ProtectSystem=strict with only ReadWritePaths=/var/lib/flo, so Flo cannot write elsewhere on the filesystem. When volume_size > 0, that path is the mount point for the attached block-storage volume; cloud-init formats blank volumes and adds an /etc/fstab entry with nofail,discard so the mount survives reboots.
Rolling config changes
Cloud-init runs only on first boot. To roll a new config:
In-place (no droplet replacement):
ssh root@<ip> 'vim /etc/flo/flo.toml && systemctl restart flo'
Immutable (replace the droplet):
terraform apply -replace=module.flo.digitalocean_droplet.this
Resizing
To resize a running droplet:
terraform apply -var="droplet_size=s-4vcpu-8gb"
This triggers a DO resize (which power-cycles the droplet). No data loss — Flo replays its log on restart.
Dashboard security
The dashboard exposes administrative APIs and has no authentication yet. By
default it binds to 127.0.0.1 and the firewall opens nothing for it. Reach it
through an SSH tunnel:
ssh -N -L 9002:127.0.0.1:9002 root@<droplet> # or: $(terraform output -raw dashboard_ssh_tunnel)
open http://127.0.0.1:9002
To serve it on the network instead, open it deliberately and keep the range narrow:
dashboard_bind_address = "0.0.0.0"
dashboard_allowed_cidrs = ["203.0.113.5/32"]
Metrics scraping
The metrics port is not opened on the firewall by default. To scrape Prometheus metrics externally:
expose_metrics = true
metrics_allowed_cidrs = ["10.0.0.0/16"] # only your VPC
Or scrape locally via the DigitalOcean monitoring agent (which runs on-loopback).
Upgrading Flo
Nodes built from different op tables can't link, and a server refuses clients built from another table (see Versions). So upgrade every node at once, not one droplet at a time: stop flo on every droplet, upgrade it, then start every node, and upgrade the CLI and SDKs your clients use with it.
# On every droplet first
ssh root@<ip> 'systemctl stop flo'
# Then, on every droplet, check and install the new package and start it.
# --force-confold keeps the module's flo.toml over the package's default.
ssh root@<ip> 'b=https://github.com/floruntime/flo/releases/download/<tag> &&
curl -fsSL -O "$b/flo_<version>_amd64.deb" -O "$b/flo_<version>_amd64.deb.sha256" &&
sha256sum -c flo_<version>_amd64.deb.sha256 &&
apt-get install -y -o Dpkg::Options::=--force-confold ./flo_<version>_amd64.deb'
ssh root@<ip> 'systemctl start flo'
A droplet created by an earlier version of the module installed flo with install.sh and wrote its own /etc/systemd/system/flo.service, which overrides the package's unit: installing the .deb there succeeds while the old /usr/local/bin/flo keeps running. Replace such droplets, or first run rm /etc/systemd/system/flo.service /usr/local/bin/flo && systemctl daemon-reload, and move a custom data_dir to /var/lib/flo.
For a clean rebuild, bump flo_version and replace the droplet:
terraform apply -var="flo_version=<tag>" -replace=module.flo.digitalocean_droplet.this
Publishing to the Terraform Registry
The module is designed for the public Terraform Registry. It lives in its own repo at github.com/floruntime/terraform-digitalocean-flo and follows the terraform-<PROVIDER>-<NAME> naming convention. Once pushed and tagged, the registry discovers it automatically — consumers reference it as:
source = "floruntime/flo/digitalocean"
version = "~> 0.0.1"
Next Steps
- Configuration reference — understand
flo.toml - Clustering — how members join, replicate and fail over
- Docker deployment — run Flo with Docker Compose