Terraform VM deployment failing

Hello Everyone,
Getting below error while trying to deploy VM using terraform.
VM is visible on OpenNebula UI but in LCM State as “BOOT_FAILURE”.
Nothing showing on vcenter for this vm, so it has failed to deploy using terraform.

Fri Feb 4 20:59:22 2022: DEPLOY: ERROR: deploy: Deploy of VM 14 on vCenter cluster QA-Cluster with /var/lib/one/vms/14/deployment.0 failed due to "ManagedObjectNotFound: The object ‘vim.VirtualMachine:’ has already been deleted or has not been completely created"on attempt #0.

terraform file is as below :

terraform {
required_providers {
opennebula = {
source = “OpenNebula/opennebula”
version = “0.4.0”
}
}
}

variable “one_endpoint” {}
variable “one_username” {}
variable “one_password” {}
variable “one_flow_endpoint” {}

provider “opennebula” {
endpoint = “${var.one_endpoint}”
flow_endpoint = “${var.one_flow_endpoint}”
username = “${var.one_username}”
password = “${var.one_password}”
}

#########################################################################

resource “opennebula_image” “CentOS7-clone” {
clone_from_image = 0
name = “CentOS7-clone”
datastore_id = 100
persistent = false
permissions = “660”
group = “oneadmin”
}

#########################################################################

resource “opennebula_virtual_machine” “terraform_test01” {
count = 1
name = “terraform_test01”
cpu = 1
vcpu = 1
memory = 4096
group = “oneadmin”
permissions = “660”

context = {
NETWORK = “YES”
HOSTNAME = “$NAME”
START_SCRIPT =“yum upgrade”
}

graphics {
type = “VNC”
listen = “0.0.0.0”
keymap = “fr”
}

os {
arch = “x86_64”
boot = “disk0”
}

disk {
image_id = opennebula_image.CentOS7-clone.id
size = 204900
target = “vda”
driver = “qcow2”
}

nic {
model = “virtio”
network_id = 7
security_groups = [0]
}

// vmgroup {
// vmgroup_id = 2
// role = “vm-group”
// }

tags = {
environment = “dev”
}

}

output “template_used” {
value = opennebula_image.CentOS7-clone.path
}

Issue resolved after getting rid of opennebula_image resource and using template_id directly in resource “opennebula_virtual_machine”.

Regards,
Dc

1 Like

Hi @dchavan

Sorry for the delay. I am not very active on the Forum.
If you face issue on the terraform provider, do not hesitate to open an issue directly under the provider Github repository:

We didn’t use it a lot with Vcenter so it is highly probable you may face issues with it.
We will be happy to help you.

Regards