OpenNebula / terraform-provider-opennebula

Terraform provider for OpenNebula
https://www.terraform.io/docs/providers/opennebula/
Mozilla Public License 2.0
61 stars 53 forks source link

Introduce `opennebula_virtual_machine_disk_attachment` to prevent issues when replacing image #525

Open frousselet opened 5 months ago

frousselet commented 5 months ago

Description

The issue:

Currently, an image is attached to a VM via an attribute (disk).

It's fine until we need to replace the image (for example in order to upgrade the the OS). In this case, the provider is not able to detach the disk by itself since a disk is an attribute.

A solution:

To fix this, a disk attachment should be an attribute:

Let's imagine a new resource called opennebula_virtual_machine_disk_attachment. It as (at least) 2 attributes: the image ID and the VM id. If one of both attributes changes, the disk attachment is forced recreated.

That means, if I change the image, its ID changes, so the attachement is recreated.

Another way would be to destroy-recreate the entire VM (but I'm quite sure this is not what we want here... 🤷🏻‍♂️).

New or affected resources and data sources

opennebula_virtual_machine (r+d): Deprecate disk attribute OpenNebula_virtual_machine_disk_attachment (r+d)

Potential terraform configuration

resource "opennebula_image" "my" {

  # ...

  clone_from_image = data.opennebula_image.ubuntu.id

  # ...

}

resource "opennebula_virtual_machine" "my" {

  # ...

  # Deprecated
  # disk {
  #   image_id = opennebula_image.my.id
  #   target   = "vda"
  # }

  # ...

}

resource "opennebula_virtual_machine_disk_attachment" "my" {
  vm_id = opennebula_virtual_machine.my.id
  image_id = opennebula_image.my.id
  target = "vda"
  # and same attributes as the old disk attribute
}

References

No response

treywelsh commented 5 months ago

Similar to older work (not merged): issue: https://github.com/OpenNebula/terraform-provider-opennebula/issues/318 PR: https://github.com/OpenNebula/terraform-provider-opennebula/pull/323