Deploying HarperDB Docker container on Linode VM using Terraform and cloud-init
This blog post is a small update to the excellent post guys from HarperDB wrote – https://www.harperdb.io/development/tutorials/deploying-harperdb-on-digital-ocean-linode-with-terraform
Since Linode now support cloud-init and metadata service, I decided to extend their example by using cloud-init to do the installation of Docker Engine and HarperDB container.
All you need to do to get HarperDB running is to copy all of these files in the same folder while making sure to keep the filenames the same (harperdb.yaml at least).
After that, simply run Terraform init, then Terraform apply and in 2-3 minutes you should have your HarperDB instance up and running.
terraform init
terraform apply -var="token=YourLinodeToken"
harperdb.yaml
#cloud-config
runcmd:
- sudo apt-get update
- sudo apt-get install -yq ca-certificates curl gnupg lsb-release
- sudo install -m 0755 -d /etc/apt/keyrings
- for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
- sudo chmod a+r /etc/apt/keyrings/docker.gpg
- echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
- sudo apt-get update
- sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
- sudo mkdir /home/harperdb
- sudo chmod 777 /home/harperdb
- sudo docker run -d -v /home/harperdb:/home/harperdb/hdb -e HDB_ADMIN_USERNAME=HDB_ADMIN -e HDB_ADMIN_PASSWORD=password -p 9925:9925 -p 9926:9926 harperdb/harperdb
compute.tf
resource "linode_instance" "harperdb" {
image = "linode/ubuntu22.04"
region = "nl-ams" #Pick The region you want
type = "g6-standard-1"
root_pass = "YourRootPassword!" #Change this :D
metadata {
user_data = base64encode(file("${path.module}/harperdb.yaml"))
}
}
resource "linode_firewall" "harperdb_firewall" {
label = "harperdb"
inbound {
label = "ssh"
action = "ACCEPT"
protocol = "TCP"
ports = "22"
ipv4 = ["0.0.0.0/0"]
ipv6 = ["::/0"]
}
inbound {
label = "harperdb"
action = "ACCEPT"
protocol = "TCP"
ports = "9925-9926"
ipv4 = ["0.0.0.0/0"]
ipv6 = ["::/0"]
}
inbound_policy = "DROP"
outbound_policy = "ACCEPT"
linodes = [linode_instance.harperdb.id]
}
terraform {
required_providers {
linode = {
source = "linode/linode"
}
}
}
provider "linode" {
token = var.token
}
variable "token" {
default = ""
type = string
}
Alex.