Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

New affinity/anti-affinity rule resources for compute clusters #515

Merged
merged 2 commits into from
May 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions vsphere/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -969,3 +969,56 @@ func testGetComputeClusterVMDependencyRule(s *terraform.State, resourceName stri

return resourceVSphereComputeClusterVMDependencyRuleFindEntry(cluster, name)
}

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

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

clusterID, name, err := resourceVSphereComputeClusterVMAffinityRuleParseID(vars.resourceID)
if err != nil {
return nil, err
}

cluster, err := clustercomputeresource.FromID(vars.client, clusterID)
if err != nil {
return nil, err
}

return resourceVSphereComputeClusterVMAffinityRuleFindEntry(cluster, name)
}

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

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

clusterID, name, err := resourceVSphereComputeClusterVMAntiAffinityRuleParseID(vars.resourceID)
if err != nil {
return nil, err
}

cluster, err := clustercomputeresource.FromID(vars.client, clusterID)
if err != nil {
return nil, err
}

return resourceVSphereComputeClusterVMAntiAffinityRuleFindEntry(cluster, name)
}
54 changes: 28 additions & 26 deletions vsphere/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,32 +88,34 @@ func Provider() terraform.ResourceProvider {
},

ResourcesMap: map[string]*schema.Resource{
"vsphere_compute_cluster": resourceVSphereComputeCluster(),
"vsphere_compute_cluster_host_group": resourceVSphereComputeClusterHostGroup(),
"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_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