A data "nsxt_policy_vm" block will intermittently fail to find VMs in large (1k+) VM environment. Despite the VM existing it returns with:
Error: Error while reading Virtual Machine <GUID>: Could not find Virtual Machine with ID: <GUID>
The error happens intermittently across GUIDs.
Reproduction steps
Have more than 1k VMs
Loop over a terraform plan for a document with a data "nsxt_policy_vm"
Eventually it will fail with Could not find Virtual Machine with ID: <GUID>
Expected behavior
Existing VM with a given ID is found.
Additional context
Tested with NSX-T 3.2.3.
The root cause of this appears to be an inconsistency in how VMs are returned from /policy/api/v1/infra/realized-state/virtual-machines endpoint when the order is not specified with sort_order. When sort_order is not set the results come back in an inconsistent order between calls which breaks the pagination. This can be tested in a large environment with a (roughly) static set of VMs:
a.json and b.json should have the same VMs in the same order, but without sort_order that is not always the case. Please note that it can take quite a few calls to trigger the inconsistency. As the result of this, the slice of VMs that comes back from listAllPolicyVirtualMachines will contain duplicated VMs and will also be missing VMs. Setting the sort order resolves this problem and I will follow up with a PR to add that.
Describe the bug
A
data "nsxt_policy_vm"
block will intermittently fail to find VMs in large (1k+) VM environment. Despite the VM existing it returns with:The error happens intermittently across GUIDs.
Reproduction steps
terraform plan
for a document with adata "nsxt_policy_vm"
Could not find Virtual Machine with ID: <GUID>
Expected behavior
Existing VM with a given ID is found.
Additional context
Tested with NSX-T 3.2.3.
The root cause of this appears to be an inconsistency in how VMs are returned from
/policy/api/v1/infra/realized-state/virtual-machines
endpoint when the order is not specified withsort_order
. Whensort_order
is not set the results come back in an inconsistent order between calls which breaks the pagination. This can be tested in a large environment with a (roughly) static set of VMs:a.json
andb.json
should have the same VMs in the same order, but withoutsort_order
that is not always the case. Please note that it can take quite a few calls to trigger the inconsistency. As the result of this, the slice of VMs that comes back fromlistAllPolicyVirtualMachines
will contain duplicated VMs and will also be missing VMs. Setting the sort order resolves this problem and I will follow up with a PR to add that.