TerraformPilot

DevOps

Terraform for TrueNAS Scale: ZFS NAS Automation

Automate TrueNAS Scale (Linux ZFS) with Terraform: dariusbakunas/truenas provider, datasets, NFS / SMB shares, snapshots, and replication.

LLuca Berton1 min read

TrueNAS Scale is iXsystems' Linux + ZFS appliance OS, with Kubernetes-based apps and replication. The community dariusbakunas/truenas Terraform provider drives the REST API to create datasets, shares, snapshots, and replication jobs.

Provider

#
terraform {
  required_providers {
    truenas = {
      source  = "dariusbakunas/truenas"
      version = "~> 0.13"
    }
  }
}
 
provider "truenas" {
  api_key = var.truenas_api_key
  base_url = "https://${var.truenas_host}/api/v2.0"
}

Dataset + NFS Share

#
resource "truenas_dataset" "media" {
  pool        = "tank"
  name        = "media"
  compression = "lz4"
  recordsize  = "1M"
  atime       = "OFF"
}
 
resource "truenas_share_nfs" "media" {
  paths      = [truenas_dataset.media.mountpoint]
  comment    = "media share"
  hosts      = ["10.0.0.0/24"]
  maproot_user  = "root"
  maproot_group = "wheel"
}

Snapshot Task

#
resource "truenas_pool_snapshottask" "media_daily" {
  dataset       = truenas_dataset.media.id
  recursive     = true
  lifetime_value = 14
  lifetime_unit  = "DAY"
  naming_schema = "auto-%Y-%m-%d_%H-%M"
  schedule {
    minute = "0"
    hour   = "2"
  }
}

Best Practices

#
  • Snapshot first, share second — every important dataset gets a snap task.
  • recordsize=1M for media, default 128 K for general purpose.
  • API key in HCP Vault Secrets — TrueNAS API keys are powerful.
  • Replication target in different building — TrueNAS replication is excellent and fully Terraform-driven.
#
#Terraform#TrueNAS#ZFS#NAS#iXsystems

Share this article