vmware / terraform-provider-vcd

Terraform VMware Cloud Director provider
https://www.terraform.io/docs/providers/vcd/
Mozilla Public License 2.0
146 stars 112 forks source link

vcd_vm_internal_disk index when creating #1068

Open C-F-A opened 1 year ago

C-F-A commented 1 year ago

Hello,

When creating Internel Disks the order of creation seems to be random and it cannot be ensured that the order of disks happens in as defined in the TF files. Is it somehow possible to ensure a defined ordering ot the internal disks?

Terraform Version

Terraform v1.4.6

Affected Resource(s)

vcd_vm_internal_disk

Terraform Configuration Files

resource "vcd_vm_internal_disk" "vm1_disk1" {
  vapp_name   = vcd_vapp.APP1.name
  vm_name     = vcd_vapp_vm.vm1.name
  bus_type    = "paravirtual"
  size_in_mb  = "57344"
  bus_number  = 0
  unit_number = 0
}
resource "vcd_vm_internal_disk" "vm1_disk2" {
  vapp_name   = vcd_vapp.APP1.name
  vm_name     = vcd_vapp_vm.vm1.name
  bus_type    = "paravirtual"
  size_in_mb  = "46080"
  bus_number  = 1
  unit_number = 1
}

Expected Behavior

In vCloud Director the Disks are sorted by the Index (and this is important to our installation scripts in the VM itself). The Discs should be created in order as defined in .TF file: vm1_disk1 having Index 0 vm1_disk2 having Index 1 after creation.

Actual Behavior

Disk creation seems to happen randomly or parallell and it is not ensured that first defined disk gets Index 0 assigned. Result was in some VM's (others were correct): vm1_disk2 having Index 0 vm1_disk1 having Index 1

Steps to Reproduce

  1. terraform apply
dataclouder commented 1 year ago

Hi, Thanks for submitting this issue. The order of execution is defined by Terraform, since every disk is a separate resource, and both have the same dependencies.

You can affect such behavior by adding a dependency of your own. For example, if you want vm1_disk1 to be processed before vm1_disk2, you can change the definition as follows:

resource "vcd_vm_internal_disk" "vm1_disk1" {
  vapp_name   = vcd_vapp.APP1.name
  vm_name     = vcd_vapp_vm.vm1.name
  bus_type    = "paravirtual"
  size_in_mb  = "57344"
  bus_number  = 0
  unit_number = 0
}
resource "vcd_vm_internal_disk" "vm1_disk2" {
  vapp_name   = vcd_vapp.APP1.name
  vm_name     = vcd_vapp_vm.vm1.name
  bus_type    = "paravirtual"
  size_in_mb  = "46080"
  bus_number  = 1
  unit_number = 1
  depends_on  = [vcd_vm_internal_disk.vm1_disk1]   # <<<<<<-----------
}

Now that disk2 depends on disk1, disk1 will be created first. HTH

danielmasur commented 2 weeks ago

Using depends_on works for me.