-
Notifications
You must be signed in to change notification settings - Fork 131
/
data_cloud_project_database_capabilities.go
156 lines (147 loc) · 4.06 KB
/
data_cloud_project_database_capabilities.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package ovh
import (
"fmt"
"log"
"net/url"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/ovh/terraform-provider-ovh/ovh/helpers"
)
func dataSourceCloudProjectDatabaseCapabilities() *schema.Resource {
return &schema.Resource{
Read: dataSourceCloudProjectDatabaseCapabilitiesRead,
Schema: map[string]*schema.Schema{
"service_name": {
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("OVH_CLOUD_PROJECT_SERVICE", nil),
},
// Computed
"engines": {
Type: schema.TypeSet,
Description: "Database engines available",
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"default_version": {
Type: schema.TypeString,
Description: "Default version used for the engine",
Computed: true,
},
"description": {
Type: schema.TypeString,
Description: "Description of the engine",
Computed: true,
},
"name": {
Type: schema.TypeString,
Description: "Engine name",
Computed: true,
},
"ssl_modes": {
Type: schema.TypeSet,
Description: "SSL modes for this engine",
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"versions": {
Type: schema.TypeSet,
Description: "Versions available for this engine",
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
},
},
"flavors": {
Type: schema.TypeSet,
Description: "Flavors available",
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"core": {
Type: schema.TypeInt,
Description: "Flavor core number",
Computed: true,
},
"memory": {
Type: schema.TypeInt,
Description: "Flavor ram size in GB",
Computed: true,
},
"name": {
Type: schema.TypeString,
Description: "Name of the flavor",
Computed: true,
},
"storage": {
Type: schema.TypeInt,
Description: "Flavor disk size in GB",
Computed: true,
},
},
},
},
"options": {
Type: schema.TypeSet,
Description: "Options available",
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Description: "Name of the option",
Computed: true,
},
"type": {
Type: schema.TypeString,
Description: "Type of the option",
Computed: true,
},
},
},
},
"plans": {
Type: schema.TypeSet,
Description: "Plans available",
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"backup_retention": {
Type: schema.TypeString,
Description: "Automatic backup retention duration",
Computed: true,
},
"description": {
Type: schema.TypeString,
Description: "Description of the plan",
Computed: true,
},
"name": {
Type: schema.TypeString,
Description: "Name of the plan",
Computed: true,
},
},
},
},
},
}
}
func dataSourceCloudProjectDatabaseCapabilitiesRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
serviceName := d.Get("service_name").(string)
capabilitiesEndpoint := fmt.Sprintf("/cloud/project/%s/database/capabilities",
url.PathEscape(serviceName),
)
capabilitiesRes := &CloudProjectDatabaseCapabilitiesResponse{}
log.Printf("[DEBUG] Will read capabilities from project %s", serviceName)
if err := config.OVHClient.Get(capabilitiesEndpoint, capabilitiesRes); err != nil {
return helpers.CheckDeleted(d, err, capabilitiesEndpoint)
}
d.SetId(serviceName)
for k, v := range capabilitiesRes.ToMap() {
d.Set(k, v)
}
log.Printf("[DEBUG] Read capabilities %+v", capabilitiesRes)
return nil
}