Skip to content

Commit

Permalink
r/datastore_cluster_vm_anti_affinity_rule: New resource
Browse files Browse the repository at this point in the history
This contains the full CRUD/tests/docs for the
vsphere_datastore_cluster_vm_anti_affinity_rule resource.

One thing to note here - during testing, it was found that a
virtual_machine_ids length of less than 2 is essentially a no-op on the
cluster, resulting in no rules created. This was causing issues where
the apply was succeeding but not rule was being returned, resulting in
odd errors post-creation. In addition to this, we cannot restrict this
with MinItems, as there currently seems to be an issue calculating the
length of a glob of computed values - ie:
vsphere_virtual_machine.vm.*.id, even when the count in
vsphere_virtual_machine is static.

If I'm assuming correctly, this is because when the computed/unknown
value is seen, the entire field becomes unknown with a length of 1,
regardless of if the final length is known beforehand.

Further reading can be found at:
hashicorp/terraform#14677 (comment)
  • Loading branch information
vancluever committed May 10, 2018
1 parent 54b1f22 commit 596fba8
Show file tree
Hide file tree
Showing 7 changed files with 1,087 additions and 29 deletions.
28 changes: 28 additions & 0 deletions vsphere/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1022,3 +1022,31 @@ func testGetComputeClusterVMAntiAffinityRule(s *terraform.State, resourceName st

return resourceVSphereComputeClusterVMAntiAffinityRuleFindEntry(cluster, name)
}

// testGetDatastoreClusterVMAntiAffinityRule is a convenience method to fetch a
// VM anti-affinity rule from a datastore cluster.
func testGetDatastoreClusterVMAntiAffinityRule(s *terraform.State, resourceName string) (*types.ClusterAntiAffinityRuleSpec, error) {
vars, err := testClientVariablesForResource(
s,
fmt.Sprintf("%s.%s", resourceVSphereDatastoreClusterVMAntiAffinityRuleName, resourceName),
)
if err != nil {
return nil, err
}

if vars.resourceID == "" {
return nil, errors.New("resource ID is empty")
}

podID, key, err := resourceVSphereDatastoreClusterVMAntiAffinityRuleParseID(vars.resourceID)
if err != nil {
return nil, err
}

pod, err := storagepod.FromID(vars.client, podID)
if err != nil {
return nil, err
}

return resourceVSphereDatastoreClusterVMAntiAffinityRuleFindEntry(pod, key)
}
2 changes: 1 addition & 1 deletion vsphere/internal/helper/storagepod/storage_pod_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func Create(f *object.Folder, name string) (*object.StoragePod, error) {
// ApplyDRSConfiguration takes a types.StorageDrsConfigSpec and applies it
// against the specified StoragePod.
func ApplyDRSConfiguration(client *govmomi.Client, pod *object.StoragePod, spec types.StorageDrsConfigSpec) error {
log.Printf("[DEBUG] Applying storage DRS configuration against datastore clsuter %q", pod.InventoryPath)
log.Printf("[DEBUG] Applying storage DRS configuration against datastore cluster %q", pod.InventoryPath)
mgr := object.NewStorageResourceManager(client.Client)
ctx, cancel := context.WithTimeout(context.Background(), provider.DefaultAPITimeout)
defer cancel()
Expand Down
57 changes: 29 additions & 28 deletions vsphere/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,34 +88,35 @@ func Provider() terraform.ResourceProvider {
},

ResourcesMap: map[string]*schema.Resource{
"vsphere_compute_cluster": resourceVSphereComputeCluster(),
"vsphere_compute_cluster_host_group": resourceVSphereComputeClusterHostGroup(),
"vsphere_compute_cluster_vm_affinity_rule": resourceVSphereComputeClusterVMAffinityRule(),
"vsphere_compute_cluster_vm_anti_affinity_rule": resourceVSphereComputeClusterVMAntiAffinityRule(),
"vsphere_compute_cluster_vm_dependency_rule": resourceVSphereComputeClusterVMDependencyRule(),
"vsphere_compute_cluster_vm_group": resourceVSphereComputeClusterVMGroup(),
"vsphere_compute_cluster_vm_host_rule": resourceVSphereComputeClusterVMHostRule(),
"vsphere_custom_attribute": resourceVSphereCustomAttribute(),
"vsphere_datacenter": resourceVSphereDatacenter(),
"vsphere_datastore_cluster": resourceVSphereDatastoreCluster(),
"vsphere_distributed_port_group": resourceVSphereDistributedPortGroup(),
"vsphere_distributed_virtual_switch": resourceVSphereDistributedVirtualSwitch(),
"vsphere_drs_vm_override": resourceVSphereDRSVMOverride(),
"vsphere_dpm_host_override": resourceVSphereDPMHostOverride(),
"vsphere_file": resourceVSphereFile(),
"vsphere_folder": resourceVSphereFolder(),
"vsphere_ha_vm_override": resourceVSphereHAVMOverride(),
"vsphere_host_port_group": resourceVSphereHostPortGroup(),
"vsphere_host_virtual_switch": resourceVSphereHostVirtualSwitch(),
"vsphere_license": resourceVSphereLicense(),
"vsphere_tag": resourceVSphereTag(),
"vsphere_tag_category": resourceVSphereTagCategory(),
"vsphere_virtual_disk": resourceVSphereVirtualDisk(),
"vsphere_virtual_machine": resourceVSphereVirtualMachine(),
"vsphere_nas_datastore": resourceVSphereNasDatastore(),
"vsphere_storage_drs_vm_override": resourceVSphereStorageDrsVMOverride(),
"vsphere_vmfs_datastore": resourceVSphereVmfsDatastore(),
"vsphere_virtual_machine_snapshot": resourceVSphereVirtualMachineSnapshot(),
"vsphere_compute_cluster": resourceVSphereComputeCluster(),
"vsphere_compute_cluster_host_group": resourceVSphereComputeClusterHostGroup(),
"vsphere_compute_cluster_vm_affinity_rule": resourceVSphereComputeClusterVMAffinityRule(),
"vsphere_compute_cluster_vm_anti_affinity_rule": resourceVSphereComputeClusterVMAntiAffinityRule(),
"vsphere_compute_cluster_vm_dependency_rule": resourceVSphereComputeClusterVMDependencyRule(),
"vsphere_compute_cluster_vm_group": resourceVSphereComputeClusterVMGroup(),
"vsphere_compute_cluster_vm_host_rule": resourceVSphereComputeClusterVMHostRule(),
"vsphere_custom_attribute": resourceVSphereCustomAttribute(),
"vsphere_datacenter": resourceVSphereDatacenter(),
"vsphere_datastore_cluster": resourceVSphereDatastoreCluster(),
"vsphere_datastore_cluster_vm_anti_affinity_rule": resourceVSphereDatastoreClusterVMAntiAffinityRule(),
"vsphere_distributed_port_group": resourceVSphereDistributedPortGroup(),
"vsphere_distributed_virtual_switch": resourceVSphereDistributedVirtualSwitch(),
"vsphere_drs_vm_override": resourceVSphereDRSVMOverride(),
"vsphere_dpm_host_override": resourceVSphereDPMHostOverride(),
"vsphere_file": resourceVSphereFile(),
"vsphere_folder": resourceVSphereFolder(),
"vsphere_ha_vm_override": resourceVSphereHAVMOverride(),
"vsphere_host_port_group": resourceVSphereHostPortGroup(),
"vsphere_host_virtual_switch": resourceVSphereHostVirtualSwitch(),
"vsphere_license": resourceVSphereLicense(),
"vsphere_tag": resourceVSphereTag(),
"vsphere_tag_category": resourceVSphereTagCategory(),
"vsphere_virtual_disk": resourceVSphereVirtualDisk(),
"vsphere_virtual_machine": resourceVSphereVirtualMachine(),
"vsphere_nas_datastore": resourceVSphereNasDatastore(),
"vsphere_storage_drs_vm_override": resourceVSphereStorageDrsVMOverride(),
"vsphere_vmfs_datastore": resourceVSphereVmfsDatastore(),
"vsphere_virtual_machine_snapshot": resourceVSphereVirtualMachineSnapshot(),
},

DataSourcesMap: map[string]*schema.Resource{
Expand Down
Loading

0 comments on commit 596fba8

Please sign in to comment.