Skip to content
Pipelines and Pizza 🍕
Go back

Managing Nutanix with Terraform: Automating Your Private Cloud

3 min read

Nutanix has become a heavy-hitter in the enterprise data center, delivering hyper-converged infrastructure with flexibility and power. But too often, admins get stuck in the UI or hand-crafted scripts to manage their clusters and workloads. Wouldn’t it be great to bring modern infrastructure-as-code practices to Nutanix? That’s where Terraform shines.

In this post, I’ll outline how to harness the power of the Nutanix Terraform Provider to automate Nutanix cluster, VM, and other resource management — with code you can version and share.


Why Terraform for Nutanix?

  • Consistency: Reusable modules, Git-driven change control, drift detection and remediation
  • Speed: Deploy or change infrastructure in seconds or minutes, not hours
  • Audit & Rollback: Changes tracked and version controlled
  • Scalability: Manage one or 100 clusters/workloads consistently

Getting Started

Install Terraform

Follow HashiCorp’s instructions for your OS.

terraform -v

Terraform Structure

your-terraform-repo/
├── main.tf
├── provider.tf
├── variables.tf
├── terraform.tfvars
├── README.md
├── modules/
└── outputs.tf

Configure the Nutanix Provider

Reference the latest Nutanix provider in your configuration:

provider.tf

terraform {
  required_providers {
    nutanix = {
      source = "nutanix/nutanix"
      version = "2.3.1"
    }
  }
}

provider "nutanix" {
  username   = "admin"
  password   = "your-password"
  endpoint   = "10.10.10.10"
  insecure   = true
}

After configuration, initialize your terraform environment:

terraform init

Example 1: Listing Clusters

data "nutanix_clusters_v2" "clusters" {
}

data "nutanix_clusters_v2" "filtered-cls"{
  filter = "name eq 'cluster-1'"
}

Example 2: Deploy a Virtual Machine

resource "nutanix_virtual_machine_v2" "vm-2"{
    name= "example-vm-2"
    description =  "vm desc"
    num_cores_per_socket = 1
    num_sockets = 1
    cluster {
        ext_id = "1cefd0f5-6d38-4c9b-a07c-bdd2db004224"
    }
    disks{
        disk_address{
            bus_type = "SCSI"
            index = 0
        }
        backing_info{
            vm_disk{
              reference {
                image_reference {
                  image_ext_id = "59ec786c-4311-4225-affe-68b65c5ebf10"
                  }
                }
                disk_size_bytes = 20 * pow(1024, 3) # 20 GB
                storage_container{
                    ext_id = "1cefd0f5-6d38-4c9b-a07c-bdd2db004224"
                }
            }
        }
    }
    boot_config {
        uefi_boot {
            boot_order = ["NETWORK", "DISK", "CDROM", ]
        }
    }
}

Note: Replace UUIDs with your actual values from Prism.


Example 3: Create an Image

resource "nutanix_images_v2" "img-1" {
  name        = "test-image"
  description = "img desc"
  type        = "ISO_IMAGE"
  source {
    url_source {
      url = "http://archive.ubuntu.com/ubuntu/dists/bionic/main/installer-amd64/current/images/netboot/mini.iso"
    }
  }
}

Common Pitfalls & Tips

  • Provider Incompatibility: Ensure your Nutanix cluster’s Prism Central/Element software matches the required API version.
  • Security: Never check in passwords or PATs. Use sensitive variables or secrets managers.
  • UUIDs: Most Nutanix resources are managed by UUID, not name. Use data sources to look these up dynamically.
  • Modularity: Use modules for common setups, like template VMs and standard subnets.

Conclusion

Terraform plus the Nutanix Provider lets you bring cloud-like automation and repeatability to your on-premises datacenter. With code, you can create, update, and destroy VMs, manage clusters, images, networking, and more.

Ready to start managing Nutanix the DevOps way? Dust off your code editor, grab a slice, and turn infrastructure into repeatable code!


References