TerraformPilot

DevOps

Terraform for Nutanix AHV: HCI VM Automation

Automate Nutanix AHV with Terraform: nutanix/nutanix provider, VM provisioning, categories, and Prism Central infrastructure as code.

LLuca Berton1 min read

Nutanix AHV is the KVM-derived hypervisor that ships with Nutanix HCI. The official nutanix/nutanix Terraform provider drives Prism Central — VMs, categories, projects, images, and self-service blueprints — declaratively.

Provider

#
terraform {
  required_providers {
    nutanix = {
      source  = "nutanix/nutanix"
      version = "~> 2.0"
    }
  }
}
 
provider "nutanix" {
  username = var.username
  password = var.password
  endpoint = var.prism_central_ip
  insecure = false
  port     = 9440
}

VM with Cloud-Init

#
data "nutanix_cluster" "this" { name = "Acme-PROD" }
data "nutanix_subnet" "this"  { subnet_name = "vlan-100" }
data "nutanix_image" "ubuntu" { image_name = "ubuntu-24.04-cloud" }
 
resource "nutanix_virtual_machine" "web" {
  name                 = "web-1"
  cluster_uuid         = data.nutanix_cluster.this.metadata.uuid
  num_vcpus_per_socket = 2
  num_sockets          = 1
  memory_size_mib      = 4096
 
  disk_list {
    data_source_reference = {
      kind = "image"
      uuid = data.nutanix_image.ubuntu.id
    }
  }
 
  nic_list {
    subnet_uuid = data.nutanix_subnet.this.metadata.uuid
  }
 
  guest_customization_cloud_init_user_data = base64encode(<<-EOT
    #cloud-config
    hostname: web-1
    users:
      - name: ubuntu
        ssh_authorized_keys:
          - ${chomp(file("~/.ssh/id_ed25519.pub"))}
  EOT
  )
}

Categories for Policy

#
resource "nutanix_category_key" "env" {
  name        = "Environment"
  description = "Deployment environment"
}
 
resource "nutanix_category_value" "prod" {
  name  = nutanix_category_key.env.name
  value = "Production"
}

Best Practices

#
  • Pin VM images — Prism's image library can rotate underneath you.
  • Cloud-init user-data over remote-exec — cleaner and faster.
  • Categories drive policy in Flow / Calm — model them in Terraform.
  • Use Projects to scope multi-team self-service.
#
#Terraform#Nutanix AHV#Prism Central#HCI#Hyperconverged

Share this article