Skip to content

Commit a1a7147

Browse files
committed
Add disk size in cluster update resource
1 parent 9deb0ac commit a1a7147

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

ovh/resource_cloud_project_database.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,10 @@ func resourceCloudProjectDatabase() *schema.Resource {
181181
Computed: true,
182182
},
183183
"disk_size": {
184-
Type: schema.TypeInt,
185-
Description: "Disk size attributes of the cluster",
186-
Optional: true,
184+
Type: schema.TypeInt,
185+
Description: "Disk size attributes of the cluster",
186+
Optional: true,
187+
ValidateFunc: validateCloudProjectDatabaseDiskSize,
187188
},
188189
},
189190
}

ovh/types_cloud_project_database.go

+28-11
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type CloudProjectDatabaseResponse struct {
3232
Status string `json:"status"`
3333
SubnetId string `json:"subnetId"`
3434
Version string `json:"version"`
35+
Disk CloudProjectDatabaseDisk `json:"disk"`
3536
}
3637

3738
func (s *CloudProjectDatabaseResponse) String() string {
@@ -71,6 +72,7 @@ func (v CloudProjectDatabaseResponse) ToMap() map[string]interface{} {
7172
obj["plan"] = v.Plan
7273
obj["status"] = v.Status
7374
obj["version"] = v.Version
75+
obj["disk"] = v.Disk.ToMap()
7476

7577
return obj
7678
}
@@ -136,7 +138,20 @@ type CloudProjectDatabaseCreateOpts struct {
136138
}
137139

138140
type CloudProjectDatabaseDisk struct {
139-
Size int `json:"size"`
141+
Type string `json:"type,omitempty"`
142+
Size *int `json:"size,omitempty"`
143+
}
144+
145+
func (cpdd *CloudProjectDatabaseDisk) ToMap() map[string]interface{} {
146+
obj := make(map[string]interface{})
147+
obj["size"] = cpdd.Size
148+
obj["type"] = cpdd.Type
149+
return obj
150+
}
151+
152+
func validateCloudProjectDatabaseDiskSize(v interface{}, k string) (ws []string, errors []error) {
153+
errors = validateIsSupEqual(v.(int), 0)
154+
return
140155
}
141156

142157
type CloudProjectDatabaseNodesPattern struct {
@@ -171,21 +186,19 @@ func (opts *CloudProjectDatabaseCreateOpts) FromResource(d *schema.ResourceData)
171186

172187
diskSize, ok := d.Get("disk_size").(int)
173188
if ok {
174-
if diskSize < 0 {
175-
return fmt.Errorf("the disk size needs to be positive"), nil
176-
}
177-
opts.Disk = CloudProjectDatabaseDisk{diskSize}
189+
opts.Disk = CloudProjectDatabaseDisk{Size: &diskSize}
178190
}
179191
return nil, opts
180192
}
181193

182194
type CloudProjectDatabaseUpdateOpts struct {
183-
AclsEnabled bool `json:"aclsEnabled,omitempty"`
184-
Description string `json:"description,omitempty"`
185-
Flavor string `json:"flavor,omitempty"`
186-
Plan string `json:"plan,omitempty"`
187-
RestApi bool `json:"restApi,omitempty"`
188-
Version string `json:"version,omitempty"`
195+
AclsEnabled bool `json:"aclsEnabled,omitempty"`
196+
Description string `json:"description,omitempty"`
197+
Flavor string `json:"flavor,omitempty"`
198+
Plan string `json:"plan,omitempty"`
199+
RestApi bool `json:"restApi,omitempty"`
200+
Version string `json:"version,omitempty"`
201+
Disk CloudProjectDatabaseDisk `json:"disk,omitempty"`
189202
}
190203

191204
func (opts *CloudProjectDatabaseUpdateOpts) FromResource(d *schema.ResourceData) (error, *CloudProjectDatabaseUpdateOpts) {
@@ -201,6 +214,10 @@ func (opts *CloudProjectDatabaseUpdateOpts) FromResource(d *schema.ResourceData)
201214
opts.Plan = d.Get("plan").(string)
202215
opts.Flavor = d.Get("flavor").(string)
203216
opts.Version = d.Get("version").(string)
217+
diskSize, ok := d.Get("disk_size").(int)
218+
if ok {
219+
opts.Disk = CloudProjectDatabaseDisk{Size: &diskSize}
220+
}
204221
return nil, opts
205222
}
206223

0 commit comments

Comments
 (0)