Blog/Deploy a DGX Spark with Terraform
Developer tools · November 2026

Deploy a DGX Spark with Terraform

By Samuel Seidel · Published November 24, 2026 · 5 min read

Our Terraform provider, gpuwerkcom/gpuwerk, deploys a dedicated DGX Spark from a config file and terminates it with terraform destroy. This post covers when that is worth the setup, the smallest config that works, and the one setting that keeps a forgotten experiment from running all weekend. Every attribute is in the Terraform guide; this is the short version.

Why manage a GPU from Terraform at all?

If you deploy one Spark a month and SSH in by hand, the console is quicker and we would keep using it. Terraform pays off when the machine is part of something you repeat:

The provider talks to the same public API as the console (documented in the API reference), so anything it deploys also shows up in the console, and the reverse works through terraform import.

A minimal configuration

Create an API key in the console under API keys, with the read and instances scopes. Add ssh_keys only if Terraform should register your SSH key too: a key with that scope can give itself root on every instance the account deploys afterwards, so keep it as safe as the account. Then export it; the provider reads the variable by itself, which keeps the key out of your files and state.

export GPUWERK_API_KEY=sy_key_...

The whole configuration is one provider, one SSH key and one Spark:

terraform {
  required_providers {
    gpuwerk = {
      source = "gpuwerkcom/gpuwerk"
    }
  }
}

# Reads GPUWERK_API_KEY.
provider "gpuwerk" {}

resource "gpuwerk_ssh_key" "laptop" {
  name       = "laptop"
  public_key = file("~/.ssh/id_ed25519.pub")
}

resource "gpuwerk_instance" "spark" {
  name                 = "train-1"
  type                 = "spark-1x"
  ssh_key_id           = gpuwerk_ssh_key.laptop.id
  max_lifetime_minutes = 180
}

output "ssh" {
  value = "ssh -p ${gpuwerk_instance.spark.ssh_port} ${gpuwerk_instance.spark.ssh_user}@${gpuwerk_instance.spark.ssh_host}"
}
terraform init
terraform apply
$(terraform output -raw ssh)

apply waits until the instance is running (set wait_for_running = false to return straight away) and then prints the SSH command. Billing starts with the deploy, at the rate of the instance type, which the instance's rate attribute shows. No SSH key yet? Create one first.

For CI, the attributes ssh_host, ssh_port and ssh_user are what your job script needs, and a terraform_data resource with remote-exec provisioners can copy code in and start it once the machine is up.

Set max_lifetime_minutes on anything you might forget

The config above sets max_lifetime_minutes = 180. The API terminates the instance 180 minutes after the deploy, whatever Terraform does, and deletes the workspace. That matters most in the cases where your own cleanup does not run: a CI runner that dies halfway through the job, a laptop that goes to sleep during apply, a Friday experiment nobody remembers on Monday.

Pick a limit with headroom over the longest run you expect, because when it fires the workspace is gone. If a job writes results you want to keep, copy them off the machine as a step of the job itself, not as an afterthought.

terraform destroy ends billing

terraform destroy

This terminates the instance: billing ends and its workspace is deleted. We keep no copy of a workspace, so copy anything you need out of /workspace first (Get your files out shows how).

There is no stop or start in the provider, on purpose. A stopped instance is still billed, so a Terraform setup that "parks" machines between runs would quietly keep charging. The provider only deploys and terminates. If you want the same environment next time, keep it in the config and the image rather than on a parked machine.

One more thing to read before every apply: changing type, image, region or most other inputs replaces the instance. Terraform terminates it, deploys a new one, and the old workspace is gone. terraform plan marks this as "must be replaced".

Spark Clusters: spark-2x to spark-8x

For a model or a training job that does not fit one Spark, set the type to spark-2x up to spark-8x. That deploys a Spark Cluster of that many cabled machines as one instance, with the same lifecycle as a single Spark: one apply deploys all of them and one destroy terminates all of them.

resource "gpuwerk_instance" "cluster" {
  name                 = "moe-eval"
  type                 = "spark-4x"
  max_lifetime_minutes = 240
}

The gpuwerk_instance_types data source lists the types you can deploy and needs no API key. Setup, limits and measured speeds are in the guides on a two-Spark cluster and 4 or 8 nodes.

Spark images are ARM64

The DGX Spark is built on NVIDIA's GB10, and its images are ARM64: dgx-os (the default), ubuntu, or a model image such as qwen3-coder-30b, set with image. Containers and wheels you bring have to be arm64 builds. An amd64-only image fails to start with an "exec format error", which is what usually happens the first time a pipeline that builds on an x86 runner meets a Spark. In CI, build for the right platform explicitly:

docker buildx build --platform linux/arm64 -t registry.example.com/eval:latest --push .

The Docker and NGC containers guide covers arm64 images, what DGX OS ships and a compose file that works on a Spark.

Where to go next

Related pages

Top up from $5, billed per minute

Deploy your first Spark from Terraform.

A dedicated DGX Spark in Europe, North America or East Asia. Create an API key in the console, then run terraform apply.

Create account Read the Terraform guide