Skip to content

cloud Databases Custom backup #553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ovh/data_cloud_project_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ func dataSourceCloudProjectDatabase() *schema.Resource {
},

//Computed
"backup_regions": {
Type: schema.TypeList,
Description: "List of region where backups are pushed",
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"backup_time": {
Type: schema.TypeString,
Description: "Time on which backups start every day",
Expand Down
2 changes: 2 additions & 0 deletions ovh/data_cloud_project_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ func TestAccCloudProjectDatabaseDataSource_basic(t *testing.T) {
{
Config: config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(
"data.ovh_cloud_project_database.db", "backup_regions.#"),
resource.TestCheckResourceAttrSet(
"data.ovh_cloud_project_database.db", "backup_time"),
resource.TestCheckResourceAttrSet(
Expand Down
18 changes: 13 additions & 5 deletions ovh/resource_cloud_project_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,19 @@ func resourceCloudProjectDatabase() *schema.Resource {
},

//Optional/Computed
"backup_regions": {
Type: schema.TypeList,
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",
Optional: true,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"backup_time": {
Type: schema.TypeString,
Description: "Time on which backups start every day",
Optional: true,
Computed: true,
},
"disk_size": {
Type: schema.TypeInt,
Description: "Disk size attributes of the cluster",
Expand All @@ -129,11 +142,6 @@ func resourceCloudProjectDatabase() *schema.Resource {
},

//Computed
"backup_time": {
Type: schema.TypeString,
Description: "Time on which backups start every day",
Computed: true,
},
"created_at": {
Type: schema.TypeString,
Description: "Date of the creation of the cluster",
Expand Down
2 changes: 2 additions & 0 deletions ovh/resource_cloud_project_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ func TestAccCloudProjectDatabase_basic(t *testing.T) {
{
Config: config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(
"ovh_cloud_project_database.db", "backup_regions.#"),
resource.TestCheckResourceAttrSet(
"ovh_cloud_project_database.db", "backup_time"),
resource.TestCheckResourceAttrSet(
Expand Down
47 changes: 38 additions & 9 deletions ovh/types_cloud_project_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ func diagnosticsToError(diags diag.Diagnostics) error {
return nil
}

type CloudProjectDatabaseBackups struct {
Regions []string `json:"regions,omitempty"`
Time string `json:"time,omitempty"`
}

type CloudProjectDatabaseResponse struct {
AclsEnabled bool `json:"aclsEnabled"`
BackupTime string `json:"backupTime"`
Backups CloudProjectDatabaseBackups `json:"backups"`
CreatedAt string `json:"createdAt"`
Description string `json:"description"`
Endpoints []CloudProjectDatabaseEndpoint `json:"endpoints"`
Expand All @@ -55,7 +60,8 @@ func (s *CloudProjectDatabaseResponse) String() string {

func (v CloudProjectDatabaseResponse) ToMap() map[string]interface{} {
obj := make(map[string]interface{})
obj["backup_time"] = v.BackupTime
obj["backup_regions"] = v.Backups.Regions
obj["backup_time"] = v.Backups.Time
obj["created_at"] = v.CreatedAt
obj["description"] = v.Description
obj["id"] = v.Id
Expand Down Expand Up @@ -151,6 +157,7 @@ type CloudProjectDatabaseCreateOpts struct {
Plan string `json:"plan"`
SubnetId string `json:"subnetId,omitempty"`
Version string `json:"version"`
Backups CloudProjectDatabaseBackups `json:"backups,omitempty"`
}

type CloudProjectDatabaseDisk struct {
Expand Down Expand Up @@ -193,17 +200,28 @@ func (opts *CloudProjectDatabaseCreateOpts) FromResource(d *schema.ResourceData)
opts.SubnetId = nodes[0].SubnetId
opts.Version = d.Get("version").(string)
opts.Disk = CloudProjectDatabaseDisk{Size: d.Get("disk_size").(int)}

regions, err := helpers.StringsFromSchema(d, "backup_regions")
if err != nil {
return err, nil
}

opts.Backups = CloudProjectDatabaseBackups{
Regions: regions,
Time: d.Get("backup_time").(string),
}
return nil, opts
}

type CloudProjectDatabaseUpdateOpts struct {
AclsEnabled bool `json:"aclsEnabled,omitempty"`
Description string `json:"description,omitempty"`
Flavor string `json:"flavor,omitempty"`
Plan string `json:"plan,omitempty"`
RestApi bool `json:"restApi,omitempty"`
Version string `json:"version,omitempty"`
Disk CloudProjectDatabaseDisk `json:"disk,omitempty"`
AclsEnabled bool `json:"aclsEnabled,omitempty"`
Description string `json:"description,omitempty"`
Flavor string `json:"flavor,omitempty"`
Plan string `json:"plan,omitempty"`
RestApi bool `json:"restApi,omitempty"`
Version string `json:"version,omitempty"`
Disk CloudProjectDatabaseDisk `json:"disk,omitempty"`
Backups CloudProjectDatabaseBackups `json:"backups,omitempty"`
}

func (opts *CloudProjectDatabaseUpdateOpts) FromResource(d *schema.ResourceData) (error, *CloudProjectDatabaseUpdateOpts) {
Expand All @@ -220,6 +238,17 @@ func (opts *CloudProjectDatabaseUpdateOpts) FromResource(d *schema.ResourceData)
opts.Flavor = d.Get("flavor").(string)
opts.Version = d.Get("version").(string)
opts.Disk = CloudProjectDatabaseDisk{Size: d.Get("disk_size").(int)}

regions, err := helpers.StringsFromSchema(d, "backup_regions")
if err != nil {
return err, nil
}

opts.Backups = CloudProjectDatabaseBackups{
Regions: regions,
Time: d.Get("backup_time").(string),
}

return nil, opts
}

Expand Down
1 change: 1 addition & 0 deletions website/docs/d/cloud_project_database.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ The following attributes are exported:

* `id` - See Argument Reference above.
* `service_name` - See Argument Reference above.
* `backup_regions` - List of region where backups are pushed.
* `backup_time` - Time on which backups start every day.
* `created_at` - Date of the creation of the cluster.
* `description` - Small description of the database service.
Expand Down
7 changes: 6 additions & 1 deletion website/docs/r/cloud_project_database.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,18 @@ The following arguments are supported:

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

* `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

* `backup_time` - Time on which backups start every day.

## Attributes Reference

The following attributes are exported:

* `id` - Public Cloud Database Service ID
* `service_name` - See Argument Reference above.
* `backup_time` - Time on which backups start every day.
* `backup_regions` - See Argument Reference above.
* `backup_time` - See Argument Reference above.
* `created_at` - Date of the creation of the cluster.
* `description` - See Argument Reference above.
* `endpoints` - List of all endpoints objects of the service.
Expand Down