Skip to content

Commit 1773cc8

Browse files
authored
Merge pull request #333 from Galiley/set_disk_size_on_cluster_creation
Add disk in database resource creation
2 parents 9448af0 + 184179f commit 1773cc8

5 files changed

+50
-7
lines changed

ovh/data_cloud_project_database.go

+10
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,16 @@ func dataSourceCloudProjectDatabase() *schema.Resource {
157157
Description: "Version of the engine deployed on the cluster",
158158
Computed: true,
159159
},
160+
"disk_size": {
161+
Type: schema.TypeInt,
162+
Description: "Disk size attributes of the cluster",
163+
Computed: true,
164+
},
165+
"disk_type": {
166+
Type: schema.TypeString,
167+
Description: "Disk type attributes of the cluster",
168+
Computed: true,
169+
},
160170
},
161171
}
162172
}

ovh/resource_cloud_project_database.go

+11
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,17 @@ func resourceCloudProjectDatabase() *schema.Resource {
180180
Description: "Current status of the cluster",
181181
Computed: true,
182182
},
183+
"disk_size": {
184+
Type: schema.TypeInt,
185+
Description: "Disk size attributes of the cluster",
186+
Optional: true,
187+
ValidateFunc: validateCloudProjectDatabaseDiskSize,
188+
},
189+
"disk_type": {
190+
Type: schema.TypeString,
191+
Description: "Disk type attributes of the cluster",
192+
Computed: true,
193+
},
183194
},
184195
}
185196
}

ovh/types_cloud_project_database.go

+23-7
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,8 @@ 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_size"] = v.Disk.Size
76+
obj["disk_type"] = v.Disk.Type
7477

7578
return obj
7679
}
@@ -129,11 +132,22 @@ type CloudProjectDatabaseCreateOpts struct {
129132
Description string `json:"description,omitempty"`
130133
NetworkId string `json:"networkId,omitempty"`
131134
NodesPattern CloudProjectDatabaseNodesPattern `json:"nodesPattern,omitempty"`
135+
Disk CloudProjectDatabaseDisk `json:"disk,omitempty"`
132136
Plan string `json:"plan"`
133137
SubnetId string `json:"subnetId,omitempty"`
134138
Version string `json:"version"`
135139
}
136140

141+
type CloudProjectDatabaseDisk struct {
142+
Type string `json:"type,omitempty"`
143+
Size int `json:"size,omitempty"`
144+
}
145+
146+
func validateCloudProjectDatabaseDiskSize(v interface{}, k string) (ws []string, errors []error) {
147+
errors = validateIsSupEqual(v.(int), 0)
148+
return
149+
}
150+
137151
type CloudProjectDatabaseNodesPattern struct {
138152
Flavor string `json:"flavor"`
139153
Number int `json:"number"`
@@ -163,17 +177,18 @@ func (opts *CloudProjectDatabaseCreateOpts) FromResource(d *schema.ResourceData)
163177
opts.NetworkId = nodes[0].NetworkId
164178
opts.SubnetId = nodes[0].SubnetId
165179
opts.Version = d.Get("version").(string)
166-
180+
opts.Disk = CloudProjectDatabaseDisk{Size: d.Get("disk_size").(int), Type: d.Get("disk_type").(string)}
167181
return nil, opts
168182
}
169183

170184
type CloudProjectDatabaseUpdateOpts struct {
171-
AclsEnabled bool `json:"aclsEnabled,omitempty"`
172-
Description string `json:"description,omitempty"`
173-
Flavor string `json:"flavor,omitempty"`
174-
Plan string `json:"plan,omitempty"`
175-
RestApi bool `json:"restApi,omitempty"`
176-
Version string `json:"version,omitempty"`
185+
AclsEnabled bool `json:"aclsEnabled,omitempty"`
186+
Description string `json:"description,omitempty"`
187+
Flavor string `json:"flavor,omitempty"`
188+
Plan string `json:"plan,omitempty"`
189+
RestApi bool `json:"restApi,omitempty"`
190+
Version string `json:"version,omitempty"`
191+
Disk CloudProjectDatabaseDisk `json:"disk,omitempty"`
177192
}
178193

179194
func (opts *CloudProjectDatabaseUpdateOpts) FromResource(d *schema.ResourceData) (error, *CloudProjectDatabaseUpdateOpts) {
@@ -189,6 +204,7 @@ func (opts *CloudProjectDatabaseUpdateOpts) FromResource(d *schema.ResourceData)
189204
opts.Plan = d.Get("plan").(string)
190205
opts.Flavor = d.Get("flavor").(string)
191206
opts.Version = d.Get("version").(string)
207+
opts.Disk = CloudProjectDatabaseDisk{Size: d.Get("disk_size").(int), Type: d.Get("disk_type").(string)}
192208
return nil, opts
193209
}
194210

website/docs/d/cloud_project_database.html.markdown

+2
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,5 @@ The following attributes are exported:
6868
* `plan` - Plan of the cluster.
6969
* `status` - Current status of the cluster.
7070
* `version` - The version of the engine in which the service should be deployed
71+
* `disk_size` - The disk size (in GB) of the database service.
72+
* `disk_type` - The disk type of the database service.

website/docs/r/cloud_project_database.html.markdown

+4
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ The following arguments are supported:
207207

208208
* `opensearch_acls_enabled` - (Optional) Defines whether the ACLs are enabled on an OpenSearch cluster
209209

210+
* `disk_size` - (Optional) The disk size (in GB) of the database service.
211+
210212
* `plan` - (Required) Plan of the cluster.
211213
Enum: "essential", "business", "enterprise".
212214

@@ -243,6 +245,8 @@ The following attributes are exported:
243245
* `plan` - See Argument Reference above.
244246
* `status` - Current status of the cluster.
245247
* `version` - See Argument Reference above.
248+
* `disk_size` - See Argument Reference above.
249+
* `disk_type` - Defines the disk type of the database service.
246250

247251
## Timeouts
248252

0 commit comments

Comments
 (0)