Skip to content

Bug: Update of Guest Customization lead to delete and recreate of virtual machine resource. #1108

@GrayScorpion82

Description

@GrayScorpion82

Issue

Nutanix Cluster Information

Prism Central Version: pc.7.5.0.5
AOS Version: 7.5.0.5

Terraform Version

Terraform: v1.14.2
Provider: registry.terraform.io/nutanix/nutanix v2.4.0

Affected Resources

nutanix_virtual_machine_v2

Terraform Configuration Files

Create:

variable "cluster_ext_id" {
  description = "ext id of the cluster"
  type        = string
}

data "template_file" "cloud_init" {
  template = file("./files/cloud-init")
  vars = {
    vm_pw = "my_password"
  }
}

resource "nutanix_images_v2" "image" {
  name        = "tf_my_complex_image_ubuntu"
  description = "Description of a complex image."
  type        = "ISO_IMAGE"
  source {
    url_source {
      url = "https://cloud-images.ubuntu.com/releases/24.04/release/ubuntu-24.04-server-cloudimg-amd64.img"
    }
  }
  cluster_location_ext_ids = [var.cluster_ext_id]
}

resource "nutanix_virtual_machine_v2" "vm" {
  name                 = "tf_my_custom_vm"
  description          = "simple vm desc"
  num_cores_per_socket = 8
  num_sockets          = 1
  memory_size_bytes    = 4 * pow(1024, 3) # 4 GB 

  cluster {
    ext_id = var.cluster_ext_id
  }

  guest_customization {
    config {
      cloud_init {
        cloud_init_script {
          user_data {
            value = base64encode("${data.template_file.cloud_init.rendered}")
          }
        }
      }
    }
  }

  disks {
    disk_address {
      bus_type = "SCSI"
      index    = 0
    }
    backing_info {
      vm_disk {
        data_source {
          reference {
            image_reference {
              image_ext_id = nutanix_images_v2.image.ext_id
            }
          }
        }
        disk_size_bytes = 20 * pow(1024, 3) # 20 GB
      }
    }
  }

  boot_config {
    uefi_boot {
      boot_order = ["NETWORK", "DISK", "CDROM"]
    }
  }
}

Update:

variable "vm_ext_id" {
  description = "The ext id of a virtual machine"
  type        = string
}

data "template_file" "cloud_init" {
  template = file("./files/updated-cloud-init")
  vars = {
    vm_pw = "my_password"
  }
}

resource "nutanix_virtual_machine_v2" "vm" {
  name                 = "tf_my_updated_vm"
  description          = "unknown"
  num_cores_per_socket = 1
  num_sockets          = 1
  cluster {
    ext_id = "unknown"
  }

  guest_customization {
    config {
      cloud_init {
        cloud_init_script {
          user_data {
            value = base64encode("${data.template_file.cloud_init.rendered}")
          }
        }
      }
    }
  } 

  lifecycle {
    ignore_changes = [description, num_cores_per_socket, num_sockets, cluster, cd_roms, disks]
  }
}

import {
  id = var.vm_ext_id
  to = nutanix_virtual_machine_v2.vm
}

Debug Output

N/A

Panic Output

Expected Behaviour

When running an update for a cloud-init script, in this case change the contents of a file on the VM, it is expected that the contents of the file is changed.

Note: nutanix_virtual_machine destroys and recreates the VM in this scenario.

Actual Behaviour

Updating the cloud init does not seem to do anything. It does not give any errors or warnings, it says that the update was ok. But nothing actually happens on the VM.

CRUDI Operations

Create

✔️

Update

Steps To Reproduce

  1. Create separate main.tf files with the tf configs above.
  2. Issue terraform apply on the Create tf file
  3. Issue terraform apply on the Update tf file

Important Factors

Original cloud-init script:

#cloud-config
users:
  - name: ubuntu
    sudo: ALL=(ALL) NOPASSWD:ALL
    groups: [sudo]
    lock_passwd: false
    plain_text_passwd: ${vm_pw}
    type: text
    shell: /bin/bash

write_files:
  - path: /home/ubuntu/test
    content: test

Updated cloud-init script:

#cloud-config
users:
  - name: ubuntu
    sudo: ALL=(ALL) NOPASSWD:ALL
    groups: [sudo]
    lock_passwd: false
    plain_text_passwd: ${vm_pw}
    type: text
    shell: /bin/bash

write_files:
  - path: /home/ubuntu/test
    content: updated

Metadata

Metadata

Labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions