Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

New resource: vsphere_compute_cluster_host_group #508

Merged
merged 5 commits into from
May 10, 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
27 changes: 26 additions & 1 deletion vsphere/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ func testGetHostFromDataSource(s *terraform.State, resourceName string) (*object
}

// testGetComputeClusterVMGroup is a convenience method to fetch a virtual
// machine group override in a (compute) cluster.
// machine group in a (compute) cluster.
func testGetComputeClusterVMGroup(s *terraform.State, resourceName string) (*types.ClusterVmGroup, error) {
vars, err := testClientVariablesForResource(s, fmt.Sprintf("%s.%s", resourceVSphereComputeClusterVMGroupName, resourceName))
if err != nil {
Expand All @@ -894,3 +894,28 @@ func testGetComputeClusterVMGroup(s *terraform.State, resourceName string) (*typ

return resourceVSphereComputeClusterVMGroupFindEntry(cluster, name)
}

// testGetComputeClusterHostGroup is a convenience method to fetch a host group
// in a (compute) cluster.
func testGetComputeClusterHostGroup(s *terraform.State, resourceName string) (*types.ClusterHostGroup, error) {
vars, err := testClientVariablesForResource(s, fmt.Sprintf("%s.%s", resourceVSphereComputeClusterHostGroupName, resourceName))
if err != nil {
return nil, err
}

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

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

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

return resourceVSphereComputeClusterHostGroupFindEntry(cluster, name)
}
15 changes: 14 additions & 1 deletion vsphere/internal/helper/structure/structure_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func SliceStringsToInterfaces(s []string) []interface{} {
}

// SliceInterfacesToManagedObjectReferences converts an interface slice into a
// slice of ManagedObjectReferences with the type of t
// slice of ManagedObjectReferences with the type of t.
func SliceInterfacesToManagedObjectReferences(s []interface{}, t string) []types.ManagedObjectReference {
var d []types.ManagedObjectReference
for _, v := range s {
Expand All @@ -59,6 +59,19 @@ func SliceInterfacesToManagedObjectReferences(s []interface{}, t string) []types
return d
}

// SliceStringsToManagedObjectReferences converts a string slice into a slice
// of ManagedObjectReferences with the type of t.
func SliceStringsToManagedObjectReferences(s []string, t string) []types.ManagedObjectReference {
var d []types.ManagedObjectReference
for _, v := range s {
d = append(d, types.ManagedObjectReference{
Type: t,
Value: v,
})
}
return d
}

// MergeSchema merges the map[string]*schema.Schema from src into dst. Safety
// against conflicts is enforced by panicing.
func MergeSchema(dst, src map[string]*schema.Schema) {
Expand Down
1 change: 1 addition & 0 deletions vsphere/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func Provider() terraform.ResourceProvider {

ResourcesMap: map[string]*schema.Resource{
"vsphere_compute_cluster": resourceVSphereComputeCluster(),
"vsphere_compute_cluster_host_group": resourceVSphereComputeClusterHostGroup(),
"vsphere_compute_cluster_vm_group": resourceVSphereComputeClusterVMGroup(),
"vsphere_custom_attribute": resourceVSphereCustomAttribute(),
"vsphere_datacenter": resourceVSphereDatacenter(),
Expand Down
Loading