vatesfr / terraform-provider-xenorchestra

Xen Orchestra provider for Terraform
MIT License
154 stars 32 forks source link

Make 'sizes'in MiB, GiB, TiB #203

Open TheFrisianClause opened 2 years ago

TheFrisianClause commented 2 years ago

Currently I am setting up the sizes of my memory and disk(s), and when I used the terraform provider for lets say vSphere. I had to adjust the sizes in either MiB, GiB or TiB. But in Xenorchestra I have to put everything in 'Bytes'. Why is that?

Is there a way to add support for MiB, GiB and TiB?

4censord commented 2 years ago

Currently I am setting up the sizes of my memory and disk(s), and when I used the terraform provider for lets say vSphere. I had to adjust the sizes in either MiB, GiB or TiB.

Two possibilitys:

But in Xenorchestra I have to put everything in 'Bytes'. Why is that?

The Xen-orchestra apis expect bytes, so it was the natural choice.

Is there a way to add support for MiB, GiB and TiB?

Neither HCL [0] nor terraform [1] implement support for those directly.

So for supporting different measurements i see three ways:

something like this:

data "convert_size" "10GiB" {
    count = 10
    unit = "GiB"
}
data "convert_size" "8GiB" {
    count = 8
    unit = "GiB"
}

resource "xenorchestra_vm" "vm" {
    memory_max = data.convert_size.8GiB.bytes
    disk {
        size             = data.convert_size.10GiB.bytes
    }
}
ddelnano commented 2 years ago

It seems that Hashicorp sentinel supports something similar to this. Unfortunately that is only an enterprise feature.

I would prefer the data source or similar route because I don't think introducing a backwards incompatible change or additional resource arguments is worth the inconvenience. I also believe that this data source doesn't need to be contained within this provider since it's more generic than that.

Another interim solution would be to define local variables and reference those to do the multiplication for you.

locals {
  kib = 1024
  mib = 1024 * kib
  gib = 1024 * mib
}

resource "xenorchestra_vm" "vm" {
    memory_max = data.convert_size.8GiB.bytes
    disk {
        size  = 10 * local.gib
    }
}

I tried searching terraform's issue tracker to see if it was possible for a provider to export "constants" or something similar to the locals above. I'd like to research if the community is doing anything there as well.

TheFrisianClause commented 2 years ago

Yeah I understand the points of you guys. But look at it from a persons perspective. I for instance have to continually grab an calculator to see for example how much 1024 MiB is in bytes. While in for instance vSphere or Telmate I can define the amount in MiB (even this would be a huge improvement). It's just time consuming to continually look for how many bytes a certain amount of KiB, MiB, GiB or TiB is, if you know where I am coming from.