terraform-provider-vcd
terraform-provider-vcd copied to clipboard
vcd_vm is powered on before all changes are finished
Hi,
I have deployed some VMs using the vcd_vm resource, but the VMs are always only partially configured and not usable.
Terraform Version
Terraform v1.2.2 on windows_amd64
- provider registry.terraform.io/vmware/vcd v3.6.0
Cloud Director version is 10.3.3
Affected Resource(s)
- vcd_vm
Terraform Configuration Files
provider "vcd" {
user = var.vcd_user
password = var.vcd_password
org = var.vcd_org
url = var.vcd_api_url
allow_unverified_ssl = false
}
resource "vcd_vm" "test-vm" {
name = var.vm_name
vdc = var.vcd_orgvdc
catalog_name = var.vcd_catalog_name
computer_name = var.vm_name
template_name = var.template_name
accept_all_eulas = true
memory = 4096
memory_hot_add_enabled = false
cpus = 2
cpu_cores = 1
cpu_hot_add_enabled = false
expose_hardware_virtualization = false
prevent_update_power_off = true
storage_profile = var.vcd_storage_profile
override_template_disk {
bus_type = "paravirtual"
size_in_mb = "51200"
bus_number = 0
unit_number = 0
iops = 0
}
network {
type = "org"
name = var.vcd_network_name
ip_allocation_mode = "POOL"
is_primary = true
connected = true
}
customization {
enabled = true
change_sid = true
allow_local_admin_password = true
must_change_password_on_first_login = false
auto_generate_password = false
admin_password = var.guest_admin_pass
}
}
Expected Behavior
The VM should be switched on after all changes (CPU, RAM, Harddisk etc.) are done.
Actual Behavior
The VM is switched on immediately after the template is provisioned. Then it will be switched off to make the sizing changes which causes the guest customization to be interrupted.
If I use the vcd_vapp_vm resource instead, everything works as expected.
Steps to Reproduce
-
terraform apply
User Access rights
The user in Cloud Director is in role "Organization Administrator"
Important Factoids
Hi @jl0815
I didn't manage to reproduce the issue. Could you share the logs? If you don't have the logs, could you repeat the operation with the field logging enabled in the provider section?
Hi @vbauzysvmware
attached you can find the go-vcloud-director log and some screenshots from the VCD UIs tasks section. I tested the provisioning against two different VCD installations (Lab and Production), both with the same result.
Kind regards, JL
H @jl0815
Could you provide any more information? this seems odd, as API doesn't have any errors and last action powerOn was success:
<Task ... status="success" operation="Running Virtual Machine ubuntu20(ceb6ec72-5593-45e3-bfd7-d987a868cf8f)" operationName="vappDeploy" serviceNamespace="com.vmware.vcloud" startTime="2022-06-17T06:47:32.246Z" endTime="2022-06-17T06:47:49.692Z" expiryTime="2022-09-15T06:47:32.246Z" cancelRequested="false" name="task" id="urn:vcloud:task:3badaf85-92e6-43a6-a70b-74e261b18bbc" href="https://[VCDFQDN]/api/task/3badaf85-92e6-43a6-a70b-74e261b18bbc" type="application/vnd.vmware.vcloud.task+xml">
maybe you can try a different vApp template?
Hi @vbauzysvmware,
I thought about the problem and checked the vcd-provider logs for differences between vcd_vm and vcd_vapp_vm resource. In VCD there is a checkbox for "Power on" when deploying a VM from template which is enabled by default. With this checkbox enabled the VCD will power on the VM immediately when the VM cloning is done.
I think when using vcd_vm this is enabled as well. There is one line in the log:
InstantiateVmTemplateParams{ XMLName: xml.Name{}, XmlnsOvf: "", Xmlns: "http://www.vmware.com/vcloud/v1.5", Name: "ubuntu20", PowerOn: true, ......
and
<InstantiateVmTemplateParams xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" xmlns="http://www.vmware.com/vcloud/v1.5" name="ubuntu20" powerOn="true">
When looking at the logs for Terraform apply with vcd_vapp_vm it seems that it is set to false.
Btw. there's another issue with the same problem (https://github.com/vmware/terraform-provider-vcd/issues/874)
Hope this helps.