Hi John,
I went ahead with the vRO route, something new so let's try!
I've followed your blog and did the following:
1.) Create a new workflow "VM Post-Provisioning"
2.) Create inputProperties of type Properties and outputs, etc as described in your blog.
3.) Scriptable task Get VM Object
4.) Use the following script for # 3
// Javascript: Get VM Object
// Inputs: inputProperties (Properties)
var name = inputProperties.resourceNames[0]
var vms = VcPlugin.getAllVirtualMachines(null, name)
System.log("Found VM object: " + vms[0])
vm = vms[0]
5.) Add another scriptable task - Enable VBS
// Input: inputProperties from vRA
var name = inputProperties.resourceNames[0]
var vms = VcPlugin.getAllVirtualMachines(null, name)
vm = vms[0]
var bootOpts = new VcVirtualMachineBootOptions()
var flags = new VcVirtualMachineFlagInfo()
var firmwareType = new VcGuestOsDescriptorFirmwareType()
var spec = new VcVirtualMachineConfigSpec()
bootOpts.efiSecureBootEnabled = true;
flags.vbsEnabled = true;
flags.vvtdEnabled = true;
spec.firmware = firmwareType.efi;
spec.nestedHVEnabled = true;
spec.bootOptions = bootOpts;
spec.flags = flags;
vm.reconfigVM_Task(spec)
6.) Set subscription and link to workflow.
7.) Add the vCenter Server instance to vRO so that part is done.
Next I create the VM via Cloud Assembly the VM gets created but when I check the vRO workflow I see the following error in log:
-------
2022-04-10 17:06:02.362 -04:00INFO__item_stack:/item1
2022-04-10 17:06:02.556 -04:00INFOFound VM object: DynamicWrapper (Instance) : [VcVirtualMachine]-[class com.vmware.o11n.plugin.vsphere_gen.VirtualMachine_Wrapper] -- VALUE : Stub: moRef = (ManagedObjectReference: type = VirtualMachine, value = vm-731293, serverGuid = null), binding = https://vcenter.mydomain.com:443/sdk
2022-04-10 17:06:02.681 -04:00INFO__item_stack:/item2
2022-04-10 17:06:03.667 -04:00ERRORUnable to create object : VcGuestOsDescriptorFirmwareType : com.vmware.vim.binding.vim.vm.GuestOsDescriptor$FirmwareType
2022-04-10 17:06:03.684 -04:00ERRORWorkflow execution stack:
***
item: 'VM-PostProvisioning/item2', state: 'failed', business state: 'null', exception: 'Unable to create object : VcGuestOsDescriptorFirmwareType : com.vmware.vim.binding.vim.vm.GuestOsDescriptor$FirmwareType'
workflow: 'VM-PostProvisioning' (69e17978-0ab6-4ff3-a294-de8339bc8d49)
| 'attribute': name=vm type=VC:VirtualMachine value=dunes://service.dunes.ch/CustomSDKObject?id='vcenter.mydomain.com%2Cid:vm-731293'&dunesName='VC:VirtualMachine'
| 'input': name=inputProperties type=Properties value={9:42:addresses=Array#[31:Array#[20:string#172.4.9.16]]
11:30:componentId=string#Cloud_vSphere_Machine_1
With the above errors I've decided to comment the firmware references in the script and run it again via Cloud Assembly
// Input: inputProperties from vRA
var name = inputProperties.resourceNames[0]
var vms = VcPlugin.getAllVirtualMachines(null, name)
vm = vms[0]
var bootOpts = new VcVirtualMachineBootOptions()
var flags = new VcVirtualMachineFlagInfo()
// var firmwareType = new VcGuestOsDescriptorFirmwareType()
var spec = new VcVirtualMachineConfigSpec()
bootOpts.efiSecureBootEnabled = true;
flags.vbsEnabled = true;
flags.vvtdEnabled = true;
//spec.firmware = firmwareType.efi;
spec.nestedHVEnabled = true;
spec.bootOptions = bootOpts;
spec.flags = flags;
vm.reconfigVM_Task(spec)
This time the workflow run was successfully, log shows the following:
2022-04-10 23:31:52.347 -04:00INFO__item_stack:/item1
2022-04-10 23:31:52.509 -04:00INFOFound VM object: DynamicWrapper (Instance) : [VcVirtualMachine]-[class com.vmware.o11n.plugin.vsphere_gen.VirtualMachine_Wrapper] -- VALUE : Stub: moRef = (ManagedObjectReference: type = VirtualMachine, value = vm-731294, serverGuid = null), binding = https://vcenter.mydomain.com:443/sdk 2022-04-10 23:31:52.714 -04:00INFO__item_stack:/item2
2022-04-10 23:31:53.781 -04:00INFO__item_stack:/item0
-------------------------
Even though the workflow runs successfully once the firmware lines were commented VBS isn't enabled. One thing to note is that VBS can not be enabled while the VM is running. I have connected to vCenter via PowerCLI and ran the script against the VM that Cloud Assembly created and the script works and VBS gets enabled. The same lines that are being executed by vRO are working when I run them from PowerCLI while the VM is powered off.
I am wondering if there is a way to debug this, maybe the workflow/script is executed while the VM is running, if that's the case then the script will fail, we can only enable VBS when the VM is powered off. I not sure if we could run the workflow directly against the VM to verify that works?
I have also changed the subscription to computer initial power on but same result, it's runs successfully but VBS is not enabled.
Thanks again for the help!