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

Reservation AR_ID cannot be set to 0 #512

Closed sk4zuzu closed 6 months ago

sk4zuzu commented 6 months ago

Description

ARs in OpenNebula for any VNET are numbered starting from 0. Setting the IP parameter in the reservation template requires also AR_ID to be provided. In the current implementation setting reservation_ar_id=0 is just the same as implying reservation_ar_id=null, thus the reservation_first_ip parameter cannot be with the first AR in a VNET. This is not reflected in unit tests as the AR used there is never the first one (AR_ID=0).

Terraform and Provider version

Terraform v1.6.5
on linux_amd64
+ provider registry.terraform.io/opennebula/opennebula v1.3.1

Affected resources and data sources

opennebula_virtual_network

Terraform configuration

resource "opennebula_virtual_network" "example" {
  name                 = "virtual-network"
  reservation_vnet     = 394
  reservation_size     = 5
  reservation_ar_id    = 0 # here
  reservation_first_ip = "172.16.100.105"
}

Expected behavior

Reservation is created without errors.

Actual behavior

OpenNebula returns error:

╷
│ Error: Failed to reserve network addresses
│
│   with opennebula_virtual_network.example,
│   on main.tf line 17, in resource "opennebula_virtual_network" "example":
│   17: resource "opennebula_virtual_network" "example" {
│
│ Virtual network (ID: 1) reservation: OpenNebula error [ACTION]: [one.vn.reserve] AR_ID must be specified for IP/MAC based reservations
╵

The AR_ID is actually missing from the reservation template.

Steps to Reproduce

It's just enough the take any VNET and try to create reservation with both reservation_first_ip="A.B.C.D" and reservation_ar_id=0.

Debug output

Not sure if this is required, the issue is really easy to reproduce.

Panic output

N/A

Important factoids

N/A

References

https://docs.opennebula.io/stable/integration_and_development/system_interfaces/api.html#one-vn-reserve