Error cloning virtual machine

Attempting to use some code from gitlab to clone a template, but getting error:

[INFO] provider.terraform-provider-vsphere_v2.7.0_x5.exe: 2024/03/13 09:55:24 [DEBUG] Cloning virtual machine “/Datacenter/vm/cs-alma-test”: timestamp=…
[ERROR] provider.terraform-provider-vsphere_v2.7.0_x5.exe: Response contains error diagnostic: diagnostic_detail=“” diagnostic_summary=“error cloning virtual machine: ServerFaultCode: Permission to perform this operation was denied.” tf_proto_version=5.4 tf_req_id=75d74d63-92b3-fe82-7f31-cd45214ca310 tf_provider_addr=provider tf_rpc=ApplyResourceChange @caller=github.com/hashicorp/terraform-plugin-go@v0.21.0/tfprotov5/internal/diag/diagnostics.go:62 @module=sdk.proto diagnostic_severity=ERROR tf_resource_type=vsphere_virtual_machine timestamp=2024-03-13T09:55:24.992Z
[DEBUG] State storage *statemgr.Filesystem declined to persist a state snapshot
[ERROR] vertex “vsphere_virtual_machine.vm” error: error cloning virtual machine: ServerFaultCode: Permission to perform this operation was denied.

Confused about the message "Cloning virtual machine “/Datacenter/vm/cs-alma-test” - does this mean it’s looking in the path /Datacenter/vm for the template, or it’s trying to put the clone in /Datacenter/vm? Neither of which is correct…

I’ve now discovered (by using the vsphere.local) credentials that the VM is being created in the datacenter root, rather than the resource pool specified. Terraform plan returns the resource_pool_id correctly:

  • resource “vsphere_virtual_machine” “vm” {
    .
    + resource_pool_id = “resgroup-2252508”

… which I have confirmed with powershell:

Get-Datacenter “datacenter” | Get-Cluster | Get-ResourcePool | select Name, Id

CS Sandbox ResourcePool-resgroup-2252508

… although I have just noticed that “ResourcePool-” is missing in the plan. Odd.