-
Notifications
You must be signed in to change notification settings - Fork 1
/
db_configuration_v1.go
60 lines (48 loc) · 1.66 KB
/
db_configuration_v1.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
package viettelidc
import (
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/db/v1/configurations"
)
func expandDatabaseConfigurationV1Datastore(rawDatastore []interface{}) configurations.DatastoreOpts {
v := rawDatastore[0].(map[string]interface{})
datastore := configurations.DatastoreOpts{
Version: v["version"].(string),
Type: v["type"].(string),
}
return datastore
}
func expandDatabaseConfigurationV1Values(rawValues []interface{}) map[string]interface{} {
values := make(map[string]interface{})
for _, rawValue := range rawValues {
v := rawValue.(map[string]interface{})
name := v["name"].(string)
value := v["value"]
if isStringType, ok := v["string_type"].(bool); !ok || !isStringType {
// check if value can be converted into int
if valueInt, err := strconv.Atoi(value.(string)); err == nil {
value = valueInt
// check if value can be converted into bool
} else if valueBool, err := strconv.ParseBool(value.(string)); err == nil {
value = valueBool
}
}
values[name] = value
}
return values
}
// databaseConfigurationV1StateRefreshFunc returns a resource.StateRefreshFunc that is used to watch
// an cloud database instance.
func databaseConfigurationV1StateRefreshFunc(client *gophercloud.ServiceClient, cgroupID string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
i, err := configurations.Get(client, cgroupID).Extract()
if err != nil {
if _, ok := err.(gophercloud.ErrDefault404); ok {
return i, "DELETED", nil
}
return nil, "", err
}
return i, "ACTIVE", nil
}
}