OpenNebula / terraform-provider-opennebula

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

Add `opennebula_user_quota` resource #448

Closed frousselet closed 1 year ago

frousselet commented 1 year ago

Description

I am facing an issue where using quotas in opennebula_user applies only in one of our two zones, and detects drift when creating resources without defining a quota.

Instead of using an attribute, I suggest to add a new resource opennebula_user_quota to be able to select the zone where the quotas will apply.

In the HCL bellow, all opennebula_user_quota > scope conflict with each others.

units, running_units, size, running_size, leases are optional. If not set, the value is -1, meaning .

Since a quota doesn't have any ID in the OpenNebula side, there is no way to import. Even if the quota exists, terraforming a new one will override it.

In the same way, there is no data source, but quotas might be returned when fetching opennebula_user as usual.

New or affected resources and data sources

Potential terraform configuration

resource "opennebula_user" "hw" {
  name = "My User"

  # quotas {} # Deprecated
}

resource "opennebula_user_quota" "vm" {
  user_id = opennebula_user.hw.id

  scope         = "vm"
  units         = 8    # Number of units
  running_units = 8    # Number of running units
}

resource "opennebula_user_quota" "cpu" {
  user_id = opennebula_user.hw.id

  scope         = "cpu"
  units         = 16    # Number of units
  running_units = 16    # Number of running units
}

resource "opennebula_user_quota" "memory" {
  user_id = opennebula_user.hw.id

  scope        = "memory"
  size         = 16384     # Size in MB
  running_size = 16384     # Size of running memory in MB
}

resource "opennebula_user_quota" "system_disks" {
  user_id = opennebula_user.hw.id

  scope         = "system_disks"
  size         = 20480            # Size in MB
}

resource "opennebula_user_quota" "image" {
  user_id = opennebula_user.hw.id

  scope    = "image"
  image_id = 100          # Only if scope=image
  units    = 2            # Number of units
}

resource "opennebula_user_quota" "network" {
  user_id = opennebula_user.hw.id

  scope    = "network"
  units    = 1            # Number of units
}

resource "opennebula_user_quota" "datastore" {
  user_id = opennebula_user.hw.id

  scope        = "datastore"
  datastore_id = 100          # Only if scope=datastore
  units        = 1            # Number of units
  size         = 10240        # Size in MB. Only available if scope=datastore
}

References

447