Skip to content

Commit 7ceaa57

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

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
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

+26-15
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1212
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1313
"github.com/ovh/go-ovh/ovh"
14+
"github.com/ovh/terraform-provider-ovh/ovh/helpers"
1415
"github.com/ybriffa/rfc3339"
1516
)
1617

@@ -32,6 +33,7 @@ type CloudProjectDatabaseResponse struct {
3233
Status string `json:"status"`
3334
SubnetId string `json:"subnetId"`
3435
Version string `json:"version"`
36+
Disk CloudProjectDatabaseDisk `json:"disk"`
3537
}
3638

3739
func (s *CloudProjectDatabaseResponse) String() string {
@@ -71,6 +73,7 @@ func (v CloudProjectDatabaseResponse) ToMap() map[string]interface{} {
7173
obj["plan"] = v.Plan
7274
obj["status"] = v.Status
7375
obj["version"] = v.Version
76+
obj["disk"] = v.Disk.ToMap()
7477

7578
return obj
7679
}
@@ -136,7 +139,20 @@ type CloudProjectDatabaseCreateOpts struct {
136139
}
137140

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

142158
type CloudProjectDatabaseNodesPattern struct {
@@ -168,24 +184,18 @@ func (opts *CloudProjectDatabaseCreateOpts) FromResource(d *schema.ResourceData)
168184
opts.NetworkId = nodes[0].NetworkId
169185
opts.SubnetId = nodes[0].SubnetId
170186
opts.Version = d.Get("version").(string)
171-
172-
diskSize, ok := d.Get("disk_size").(int)
173-
if ok {
174-
if diskSize < 0 {
175-
return fmt.Errorf("the disk size needs to be positive"), nil
176-
}
177-
opts.Disk = CloudProjectDatabaseDisk{diskSize}
178-
}
187+
opts.Disk = CloudProjectDatabaseDisk{Size: helpers.GetNilIntPointer(d.Get("disk_size"))}
179188
return nil, opts
180189
}
181190

182191
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"`
192+
AclsEnabled bool `json:"aclsEnabled,omitempty"`
193+
Description string `json:"description,omitempty"`
194+
Flavor string `json:"flavor,omitempty"`
195+
Plan string `json:"plan,omitempty"`
196+
RestApi bool `json:"restApi,omitempty"`
197+
Version string `json:"version,omitempty"`
198+
Disk CloudProjectDatabaseDisk `json:"disk,omitempty"`
189199
}
190200

191201
func (opts *CloudProjectDatabaseUpdateOpts) FromResource(d *schema.ResourceData) (error, *CloudProjectDatabaseUpdateOpts) {
@@ -201,6 +211,7 @@ func (opts *CloudProjectDatabaseUpdateOpts) FromResource(d *schema.ResourceData)
201211
opts.Plan = d.Get("plan").(string)
202212
opts.Flavor = d.Get("flavor").(string)
203213
opts.Version = d.Get("version").(string)
214+
opts.Disk = CloudProjectDatabaseDisk{Size: helpers.GetNilIntPointer(d.Get("disk_size"))}
204215
return nil, opts
205216
}
206217

0 commit comments

Comments
 (0)