I like to keep things simple because I think simple is easy to understand. In college I had an instructor that always told the class K.I.S.S (keep it simple stupid). Anyway, this weekend I started to play with Terraform and the Nutanix Provider for the first time. My goal was to build a simple main.tf that anyone could understand and use as a template for learning. Below is my main.tf working with Terrafrom 0.11.3 and Nutanix Provider 1.0.0. This main.tf creates a simple CentOS VM and uses cloud-init for user data. This main.tf connects to Nutanix Prism Central rather than Prism Element.
Review Docs https://www.terraform.io/docs/providers/nutanix/index.html
Install Terraform
sudo yum -y update sudo yum -y install wget unzip wget https://releases.hashicorp.com/terraform/0.11.13/terraform_0.11.13_linux_amd64.zip sudo unzip ./terraform_0.11.13_linux_amd64.zip -d /usr/local/bin/
Create the main.tf and .conf file for cloud-init. If you don’t want to use cloud-init then comment out guest_customization_cloud_init_user_data. In the below example mine is called devmin.conf.
Example main.tf
provider "nutanix" { username = "admin" password = "XXXXXXX" endpoint = "127.0.0.1" insecure = true port = 9440 } #uuid of target cluster VM is to be deployed on data "nutanix_cluster" "cluster" { cluster_id = "0005842b-4b74-b4fb-0000-000000014a60" } #change count to deploy number of VMs resource "nutanix_virtual_machine" "devmin-terraform-deploy" { count= "1" name = "devmin-terraform-deploy-${count.index + 1}" description = "devmin-terraform-deploy" num_vcpus_per_socket = 4 num_sockets = 1 memory_size_mib = 4096 #cloud-init guest_customization_cloud_init_user_data ="${base64encode("${file("devmin.conf")}")}" cluster_reference = { kind = "cluster" uuid = "${data.nutanix_cluster.cluster.cluster_id}" } #vlan from acli net.list nic_list = [{ subnet_reference = { kind = "subnet" uuid = "0f4ece03-7d4f-4303-b36d-80493150847d" } }] #gold/master disk image from acli image.list disk_list = [{ data_source_reference = [{ kind = "image" uuid = "08c16f61-1f83-4884-8215-70bcc57bac8f" }] }] }
Try it out
In the directory where main.tf exists run the below. Note: that “terraform init” will download the Nutanix Provider.
terraform init terraform plan terraform apply
I am doing terraform for AWS and GCP for a while, but recently I joined a new company which use Nutanix. This really helped me but I got question here. How can we manage terraform states in Nutanix?.