-
Notifications
You must be signed in to change notification settings - Fork 8
/
vsan_datastore_subresource.go
68 lines (63 loc) · 2.41 KB
/
vsan_datastore_subresource.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2023 Broadcom. All Rights Reserved.
// SPDX-License-Identifier: MPL-2.0
package datastores
import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
validationutils "github.com/vmware/terraform-provider-vcf/internal/validation"
"github.com/vmware/vcf-sdk-go/models"
)
// VsanDatastoreSchema this helper function extracts the vSAN Datastore schema, so that
// it's made available for both workload domain and cluster creation.
func VsanDatastoreSchema() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"datastore_name": {
Type: schema.TypeString,
Required: true,
Description: "vSAN datastore name used for cluster creation",
ValidateFunc: validation.NoZeroValues,
},
"license_key": {
Type: schema.TypeString,
Optional: true,
Sensitive: true,
Description: "vSAN license key to be used",
ValidateFunc: validation.NoZeroValues,
},
"failures_to_tolerate": {
Type: schema.TypeInt,
Optional: true,
Description: "Number of ESXi host failures to tolerate in the vSAN cluster. One of 0, 1, or 2.",
ValidateFunc: validation.IntBetween(0, 2),
},
"dedup_and_compression_enabled": {
Type: schema.TypeBool,
Optional: true,
Description: "Enable vSAN deduplication and compression",
},
},
}
}
func TryConvertToVsanDatastoreSpec(object map[string]interface{}) (*models.VSANDatastoreSpec, error) {
if object == nil {
return nil, fmt.Errorf("cannot convert to VSANDatastoreSpec, object is nil")
}
datastoreName := object["datastore_name"].(string)
if len(datastoreName) == 0 {
return nil, fmt.Errorf("cannot convert to VSANDatastoreSpec, datastore_name is required")
}
result := &models.VSANDatastoreSpec{}
result.DatastoreName = &datastoreName
licenseKey := object["license_key"].(string)
result.LicenseKey = licenseKey
if dedupAndCompressionEnabled, ok := object["dedup_and_compression_enabled"]; ok && !validationutils.IsEmpty(dedupAndCompressionEnabled) {
result.DedupAndCompressionEnabled = dedupAndCompressionEnabled.(bool)
}
if failuresToTolerate, ok := object["failures_to_tolerate"]; ok && !validationutils.IsEmpty(failuresToTolerate) {
failuresToTolerateInt := int32(failuresToTolerate.(int))
result.FailuresToTolerate = &failuresToTolerateInt
}
return result, nil
}