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

Problem with simultaneous provisioning of datastore and its images #461

Closed alvarocurt closed 1 year ago

alvarocurt commented 1 year ago

Description

I am currently trying to make a definition with all cluster resources in order to raise them all with only one terraform apply. The problem is that when I create simultaneously a resource for the datastore (ceph in this case) and another one for the image to download from the marketplace, OpenNebula does not have time to measure the available storage in the Ceph and I get this error: │ Error: Failed to create the image │ │ with opennebula_image.imagen, │ on main.tf line 92, in resource "opennebula_image" "imagen": │ 92: resource "opennebula_image" "imagen" { │ │ OpenNebula error [ACTION]: [one.image.allocate] Not enough space in datastore

Of course this error disappears at a second terraform apply, but that's not what I'm looking for What can be done for now to solve this?

Terraform and Provider version

Terraform v1.4.6 on darwin_arm64

Affected resources and data sources

resource "opennebula_datastore" "ceph_image" { name = var.ceph_image_datastore type = "image" cluster_ids = [tonumber(opennebula_cluster.cluster_CPD.id)] bridge_list = var.ceph_pool.libvirt_hosts tags = { "BRIDGE_LIST" = join(" ", var.ceph_pool.libvirt_hosts) "CEPH_HOST" = var.ceph_pool.ceph_mons "CEPH_SECRET" = var.ceph_pool.ceph_secret "POOL_NAME" = var.ceph_pool.ceph_pool "CEPH_USER" = var.ceph_pool.ceph_client "DS_MAD" = "ceph" "TM_MAD" = "ceph" "DISK_TYPE" = "RBD" }

resource "opennebula_image" "imagen" { name = var.image.name path = var.image.path datastore_id = opennebula_datastore.ceph_image.id dev_prefix = "vd" }

Terraform configuration

No response

Expected behavior

Datastore and image created succesfully

Actual behavior

Datastore created but error raised when provisioning the image

Steps to Reproduce

Create an image datastore and create an image in the same file. In the code provided I also previously created a cluster for the datastore, but I think that's not necesary

Debug output

No response

Panic output

No response

Important factoids

No response

References

No response

alvarocurt commented 1 year ago

I solved the problem with a little roundabout as shown before

`resource "null_resource" "espera_datastore" { provisioner "local-exec" { command = "sleep 10" } depends_on = [opennebula_datastore.ceph_image] }

resource "opennebula_image" "imagen" { name = var.image.name path = var.image.path datastore_id = opennebula_datastore.ceph_image.id dev_prefix = "vd" depends_on = [null_resource.espera_datastore] }`

The solution is not perfect and 10s is an arbitrary time. It takes longer than necessary and the optimal solution would be for terraform to know when the oned knows the actual size of the datastore, but for now this will work for me.