OpenNebula / terraform-provider-opennebula

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

template_section does not update after VM creation #464

Closed TGM closed 1 year ago

TGM commented 1 year ago

Description

template_section does not update after VM creation

Terraform and Provider version

Terraform v1.3.6 Provider v1.2.2 OpenNebula v6.4.0.1

Affected resources and data sources

template_section

Terraform configuration

template_section {
    name = "RAW"
    elements = {
      data = "<memtune><hard_limit unit='MB'>${var.memory * 1024}</hard_limit></memtune>"
      type = "kvm"
    }
  }

  template_section {
    name = "RAW"
    elements = {
      data = "<memtune><hard_limit unit='MB'>${var.memory * 1024 * 2}</hard_limit></memtune>"
      type = "kvm"
    }
  }

Expected behavior

  + template_section {
      + elements = {
          + "data" = "<memtune><hard_limit unit='MB'>2048</hard_limit></memtune>"
          + "type" = "kvm"
        }
      + name     = "RAW"
    }

Actual behavior

template_section { name = "RAW" elements = { data = "${var.memory 1024 2}" type = "kvm" } }

Steps to Reproduce

  1. Create a new VM and declare the template section.
  2. Update the template_section with extra data and run apply

Debug output

No response

Panic output

No response

Important factoids

No response

References

No response

treywelsh commented 1 year ago

Thanks for reporting this

I'm able to reproduce a problem. It seems I'm able to reproduce a problem with template_section.

I added this to the VM description:

  template_section {
    name= "RAW"
    elements = {
      "data" = "<memtune><hard_limit unit='MB'>256</hard_limit></memtune>"
      "type" = "kvm"
    }
  }

At creation the section RAW is applied, but then the provider is not able to read this section (so it see it as not applied) and the provider shows a diff.

In fact template_section works depending on the name you define. If it's an OpenNebula specific key (like RAW), OpenNebula will add the section in the TEMPLATE. If it's a custom key that OpenNebula doesn't know, it will add the section to the USER_TEMPLATE section of the VM.

The problem is: the reading code of template_section only read sections from USER_TEMPLATE, and ignore section added in TEMPLATE.

There is several ways to fix this, for instance we could add an issue to add a configurable raw section, I'll provide a PR ASAP

treywelsh commented 1 year ago

I just realized: for now it's possible to define a RAW section via the opennebula_template ressource then instantiate the template. It also a little note to myself: there's some existing code if we want to add a raw section to the opennebula_virtual_machine resource