Skip to content

Commit

Permalink
Merge pull request #498 from terraform-providers/f-vsphere-drs-vm-ove…
Browse files Browse the repository at this point in the history
…rride-resource

New resource: vsphere_drs_vm_override
  • Loading branch information
vancluever authored May 3, 2018
2 parents 7d10af0 + 63d36ec commit fd3259d
Show file tree
Hide file tree
Showing 7 changed files with 917 additions and 0 deletions.
40 changes: 40 additions & 0 deletions vsphere/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,16 @@ func testGetComputeCluster(s *terraform.State, resourceName string) (*object.Clu
return clustercomputeresource.FromID(vars.client, vars.resourceID)
}

// testGetComputeClusterFromDataSource is a convenience method to fetch a
// compute cluster via the data in a vsphere_compute_cluster data source.
func testGetComputeClusterFromDataSource(s *terraform.State, resourceName string) (*object.ClusterComputeResource, error) {
vars, err := testClientVariablesForResource(s, fmt.Sprintf("data.%s.%s", resourceVSphereComputeClusterName, resourceName))
if err != nil {
return nil, err
}
return clustercomputeresource.FromID(vars.client, vars.resourceID)
}

// testGetComputeClusterProperties is a convenience method that adds an extra
// step to testGetComputeCluster to get the properties of a
// ClusterComputeResource.
Expand All @@ -759,3 +769,33 @@ func testGetComputeClusterProperties(s *terraform.State, resourceName string) (*
}
return clustercomputeresource.Properties(cluster)
}

// testGetComputeClusterDRSVMConfig is a convenience method to fetch a VM's DRS
// override in a (compute) cluster.
func testGetComputeClusterDRSVMConfig(s *terraform.State, resourceName string) (*types.ClusterDrsVmConfigInfo, error) {
vars, err := testClientVariablesForResource(s, fmt.Sprintf("%s.%s", resourceVSphereDRSVMOverrideName, resourceName))
if err != nil {
return nil, err
}

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

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

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

vm, err := virtualmachine.FromUUID(vars.client, vmID)
if err != nil {
return nil, err
}

return resourceVSphereDRSVMOverrideFindEntry(cluster, vm)
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ func newUUIDNotFoundError(s string) *UUIDNotFoundError {
}
}

// IsUUIDNotFoundError returns true if the error is a UUIDNotFoundError.
func IsUUIDNotFoundError(err error) bool {
_, ok := err.(*UUIDNotFoundError)
return ok
}

// FromUUID locates a virtualMachine by its UUID.
func FromUUID(client *govmomi.Client, uuid string) (*object.VirtualMachine, error) {
log.Printf("[DEBUG] Locating virtual machine with UUID %q", uuid)
Expand Down
1 change: 1 addition & 0 deletions vsphere/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func Provider() terraform.ResourceProvider {
"vsphere_datastore_cluster": resourceVSphereDatastoreCluster(),
"vsphere_distributed_port_group": resourceVSphereDistributedPortGroup(),
"vsphere_distributed_virtual_switch": resourceVSphereDistributedVirtualSwitch(),
"vsphere_drs_vm_override": resourceVSphereDRSVMOverride(),
"vsphere_file": resourceVSphereFile(),
"vsphere_folder": resourceVSphereFolder(),
"vsphere_host_port_group": resourceVSphereHostPortGroup(),
Expand Down
Loading

0 comments on commit fd3259d

Please sign in to comment.