Skip to content

Commit 0d724ea

Browse files
authored
cloud Databases Custom backup (#553)
* add aditional backup regions field
1 parent 8127f3a commit 0d724ea

7 files changed

+68
-15
lines changed

ovh/data_cloud_project_database.go

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ func dataSourceCloudProjectDatabase() *schema.Resource {
3131
},
3232

3333
//Computed
34+
"backup_regions": {
35+
Type: schema.TypeList,
36+
Description: "List of region where backups are pushed",
37+
Computed: true,
38+
Elem: &schema.Schema{Type: schema.TypeString},
39+
},
3440
"backup_time": {
3541
Type: schema.TypeString,
3642
Description: "Time on which backups start every day",

ovh/data_cloud_project_database_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ func TestAccCloudProjectDatabaseDataSource_basic(t *testing.T) {
5454
{
5555
Config: config,
5656
Check: resource.ComposeTestCheckFunc(
57+
resource.TestCheckResourceAttrSet(
58+
"data.ovh_cloud_project_database.db", "backup_regions.#"),
5759
resource.TestCheckResourceAttrSet(
5860
"data.ovh_cloud_project_database.db", "backup_time"),
5961
resource.TestCheckResourceAttrSet(

ovh/resource_cloud_project_database.go

+13-5
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,19 @@ func resourceCloudProjectDatabase() *schema.Resource {
108108
},
109109

110110
//Optional/Computed
111+
"backup_regions": {
112+
Type: schema.TypeList,
113+
Description: "List of region where backups are pushed. Not more than 1 regions for MongoDB. Not more than 2 regions for the other engines with one being the same as the nodes[].region field",
114+
Optional: true,
115+
Computed: true,
116+
Elem: &schema.Schema{Type: schema.TypeString},
117+
},
118+
"backup_time": {
119+
Type: schema.TypeString,
120+
Description: "Time on which backups start every day",
121+
Optional: true,
122+
Computed: true,
123+
},
111124
"disk_size": {
112125
Type: schema.TypeInt,
113126
Description: "Disk size attributes of the cluster",
@@ -129,11 +142,6 @@ func resourceCloudProjectDatabase() *schema.Resource {
129142
},
130143

131144
//Computed
132-
"backup_time": {
133-
Type: schema.TypeString,
134-
Description: "Time on which backups start every day",
135-
Computed: true,
136-
},
137145
"created_at": {
138146
Type: schema.TypeString,
139147
Description: "Date of the creation of the cluster",

ovh/resource_cloud_project_database_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ func TestAccCloudProjectDatabase_basic(t *testing.T) {
106106
{
107107
Config: config,
108108
Check: resource.ComposeTestCheckFunc(
109+
resource.TestCheckResourceAttrSet(
110+
"ovh_cloud_project_database.db", "backup_regions.#"),
109111
resource.TestCheckResourceAttrSet(
110112
"ovh_cloud_project_database.db", "backup_time"),
111113
resource.TestCheckResourceAttrSet(

ovh/types_cloud_project_database.go

+38-9
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,14 @@ func diagnosticsToError(diags diag.Diagnostics) error {
2727
return nil
2828
}
2929

30+
type CloudProjectDatabaseBackups struct {
31+
Regions []string `json:"regions,omitempty"`
32+
Time string `json:"time,omitempty"`
33+
}
34+
3035
type CloudProjectDatabaseResponse struct {
3136
AclsEnabled bool `json:"aclsEnabled"`
32-
BackupTime string `json:"backupTime"`
37+
Backups CloudProjectDatabaseBackups `json:"backups"`
3338
CreatedAt string `json:"createdAt"`
3439
Description string `json:"description"`
3540
Endpoints []CloudProjectDatabaseEndpoint `json:"endpoints"`
@@ -55,7 +60,8 @@ func (s *CloudProjectDatabaseResponse) String() string {
5560

5661
func (v CloudProjectDatabaseResponse) ToMap() map[string]interface{} {
5762
obj := make(map[string]interface{})
58-
obj["backup_time"] = v.BackupTime
63+
obj["backup_regions"] = v.Backups.Regions
64+
obj["backup_time"] = v.Backups.Time
5965
obj["created_at"] = v.CreatedAt
6066
obj["description"] = v.Description
6167
obj["id"] = v.Id
@@ -151,6 +157,7 @@ type CloudProjectDatabaseCreateOpts struct {
151157
Plan string `json:"plan"`
152158
SubnetId string `json:"subnetId,omitempty"`
153159
Version string `json:"version"`
160+
Backups CloudProjectDatabaseBackups `json:"backups,omitempty"`
154161
}
155162

156163
type CloudProjectDatabaseDisk struct {
@@ -193,17 +200,28 @@ func (opts *CloudProjectDatabaseCreateOpts) FromResource(d *schema.ResourceData)
193200
opts.SubnetId = nodes[0].SubnetId
194201
opts.Version = d.Get("version").(string)
195202
opts.Disk = CloudProjectDatabaseDisk{Size: d.Get("disk_size").(int)}
203+
204+
regions, err := helpers.StringsFromSchema(d, "backup_regions")
205+
if err != nil {
206+
return err, nil
207+
}
208+
209+
opts.Backups = CloudProjectDatabaseBackups{
210+
Regions: regions,
211+
Time: d.Get("backup_time").(string),
212+
}
196213
return nil, opts
197214
}
198215

199216
type CloudProjectDatabaseUpdateOpts struct {
200-
AclsEnabled bool `json:"aclsEnabled,omitempty"`
201-
Description string `json:"description,omitempty"`
202-
Flavor string `json:"flavor,omitempty"`
203-
Plan string `json:"plan,omitempty"`
204-
RestApi bool `json:"restApi,omitempty"`
205-
Version string `json:"version,omitempty"`
206-
Disk CloudProjectDatabaseDisk `json:"disk,omitempty"`
217+
AclsEnabled bool `json:"aclsEnabled,omitempty"`
218+
Description string `json:"description,omitempty"`
219+
Flavor string `json:"flavor,omitempty"`
220+
Plan string `json:"plan,omitempty"`
221+
RestApi bool `json:"restApi,omitempty"`
222+
Version string `json:"version,omitempty"`
223+
Disk CloudProjectDatabaseDisk `json:"disk,omitempty"`
224+
Backups CloudProjectDatabaseBackups `json:"backups,omitempty"`
207225
}
208226

209227
func (opts *CloudProjectDatabaseUpdateOpts) FromResource(d *schema.ResourceData) (error, *CloudProjectDatabaseUpdateOpts) {
@@ -220,6 +238,17 @@ func (opts *CloudProjectDatabaseUpdateOpts) FromResource(d *schema.ResourceData)
220238
opts.Flavor = d.Get("flavor").(string)
221239
opts.Version = d.Get("version").(string)
222240
opts.Disk = CloudProjectDatabaseDisk{Size: d.Get("disk_size").(int)}
241+
242+
regions, err := helpers.StringsFromSchema(d, "backup_regions")
243+
if err != nil {
244+
return err, nil
245+
}
246+
247+
opts.Backups = CloudProjectDatabaseBackups{
248+
Regions: regions,
249+
Time: d.Get("backup_time").(string),
250+
}
251+
223252
return nil, opts
224253
}
225254

website/docs/d/cloud_project_database.html.markdown

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ The following attributes are exported:
4141

4242
* `id` - See Argument Reference above.
4343
* `service_name` - See Argument Reference above.
44+
* `backup_regions` - List of region where backups are pushed.
4445
* `backup_time` - Time on which backups start every day.
4546
* `created_at` - Date of the creation of the cluster.
4647
* `description` - Small description of the database service.

website/docs/r/cloud_project_database.html.markdown

+6-1
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,18 @@ The following arguments are supported:
231231

232232
* `version` - (Required) The version of the engine in which the service should be deployed
233233

234+
* `backup_regions` - List of region where backups are pushed. Not more than 1 regions for MongoDB. Not more than 2 regions for the other engines with one being the same as the nodes[].region field
235+
236+
* `backup_time` - Time on which backups start every day.
237+
234238
## Attributes Reference
235239

236240
The following attributes are exported:
237241

238242
* `id` - Public Cloud Database Service ID
239243
* `service_name` - See Argument Reference above.
240-
* `backup_time` - Time on which backups start every day.
244+
* `backup_regions` - See Argument Reference above.
245+
* `backup_time` - See Argument Reference above.
241246
* `created_at` - Date of the creation of the cluster.
242247
* `description` - See Argument Reference above.
243248
* `endpoints` - List of all endpoints objects of the service.

0 commit comments

Comments
 (0)