OpenNebula / terraform-provider-opennebula

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

Disk change in VM Template doesn't take effect #491

Closed grossibr closed 5 months ago

grossibr commented 1 year ago

Description

Removing a disk from VM Template in terraform doesn't generate one.template.update in ONe, only a one.template.info request for the diff as there's no if d.HasChange("disk") condition in https://github.com/OpenNebula/terraform-provider-opennebula/blob/master/opennebula/resource_opennebula_template.go#L541C67-L541C67

Terraform and Provider version

Terraform v1.5.1 on darwin_arm64

Affected resources and data sources

opennebula_template

Terraform configuration

resource "opennebula_template" "instance-template" {
  name               = var.instance_template_name
  cpu                = var.cpu
  vcpu               = var.vcpu
  memory             = var.memory_gb * 1024
  permissions        = "660"
  sched_requirements = var.cluster_id
  context = {
    AXC_VMTYPE          = "cf"
    DNS                 = var.dns
    DNS_HOSTNAME        = "YES"
    NETWORK             = "YES"
    REPORT_READY        = "YES"
    SEARCH_DOMAIN       = var.search_domain
    START_SCRIPT_BASE64 = var.start_script_base64
    TOKEN               = "YES"
  }
  cpumodel {
    model = "IvyBridge-IBRS"
  }
  disk {
    dev_prefix = "sd"
    discard    = "unmap"
    image_id   = 11
    size       = 20480
  }
  features {
    guest_agent        = "YES"
    virtio_scsi_queues = "3"
  }
  os {
    arch = "x86_64"
    boot = ""
  }
  raw {
    data = "<console/>"
    type = "kvm"
  }
  graphics {
    listen = "0.0.0.0"
    type   = "VNC"
  }
  nic {
    network_id = var.network_id
    security_groups = [
      0,
    ]
  }
}

Expected behavior

only 20G disk should exist, any other disks in this template should be deleted:

  # module.instance-template["cf"].opennebula_template.instance-template will be updated in-place
  ~ resource "opennebula_template" "instance-template" {
        id                 = "70"
        name               = "cf"
        # (13 unchanged attributes hidden)

      - disk {
          - cache           = "writeback" -> null
          - dev_prefix      = "sd" -> null
          - discard         = "unmap" -> null
          - image_id        = -1 -> null
          - size            = 358400 -> null
          - volatile_format = "raw" -> null
          - volatile_type   = "fs" -> null
        }

        # (7 unchanged blocks hidden)
    }

Actual behavior

Apply completes successfully, reporting template change:

image

and Disk deletion does not take effect in ONe interface: image

Steps to Reproduce

create Template with 2 disks or more, then delete one disk from terraform code and see if it takes effect in ONe console

Debug output

No response

Panic output

No response

Important factoids

No response

References

No response

treywelsh commented 12 months ago

Same for nic section

volodaiy commented 10 months ago

I confirm, same problem. Provider version 1.3, 1.2.2. Terraform version 1.6.4, 1.5.7