Skip to content
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

feat(rdb): add backup_same_region attribute #1184

Merged
merged 2 commits into from
Apr 6, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/resources/rdb_instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ The following arguments are supported:

- `backup_schedule_retention` - (Optional) Backup schedule retention in days.

- `backup_same_region` - (Optional) Boolean to store logical backups in the same region as the database instance.

- `settings` - Map of engine settings to be set.

- `tags` - (Optional) The tags associated with the Database Instance.
Expand Down
16 changes: 16 additions & 0 deletions scaleway/resource_rdb_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ func resourceScalewayRdbInstance() *schema.Resource {
Computed: true,
Description: "Backup schedule retention in days",
},
"backup_same_region": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "Boolean to store logical backups in the same region as the database instance",
},
"user_name": {
Type: schema.TypeString,
ForceNew: true,
Expand Down Expand Up @@ -315,6 +321,12 @@ func resourceScalewayRdbInstanceCreate(ctx context.Context, d *schema.ResourceDa
Region: region,
InstanceID: res.ID,
}

backupSameRegion, backupSameRegionExist := d.GetOk("backup_same_region")
if backupSameRegionExist {
updateReq.BackupSameRegion = expandBoolPtr(backupSameRegion)
}

updateReq.IsBackupScheduleDisabled = scw.BoolPtr(d.Get("disable_backup").(bool))
if backupScheduleFrequency, okFrequency := d.GetOk("backup_schedule_frequency"); okFrequency {
updateReq.BackupScheduleFrequency = scw.Uint32Ptr(uint32(backupScheduleFrequency.(int)))
Expand Down Expand Up @@ -372,6 +384,7 @@ func resourceScalewayRdbInstanceRead(ctx context.Context, d *schema.ResourceData
_ = d.Set("disable_backup", res.BackupSchedule.Disabled)
_ = d.Set("backup_schedule_frequency", int(res.BackupSchedule.Frequency))
_ = d.Set("backup_schedule_retention", int(res.BackupSchedule.Retention))
_ = d.Set("backup_same_region", res.BackupSameRegion)
_ = d.Set("user_name", d.Get("user_name").(string)) // user name and
_ = d.Set("password", d.Get("password").(string)) // password are immutable
_ = d.Set("tags", res.Tags)
Expand Down Expand Up @@ -442,6 +455,9 @@ func resourceScalewayRdbInstanceUpdate(ctx context.Context, d *schema.ResourceDa
if d.HasChange("backup_schedule_retention") {
req.BackupScheduleRetention = scw.Uint32Ptr(uint32(d.Get("backup_schedule_retention").(int)))
}
if d.HasChange("backup_same_region") {
req.BackupSameRegion = expandBoolPtr(d.Get("backup_same_region"))
}
if d.HasChange("tags") {
req.Tags = scw.StringsPtr(expandStrings(d.Get("tags")))
}
Expand Down
2 changes: 2 additions & 0 deletions scaleway/resource_rdb_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ func TestAccScalewayRdbInstance_BackupSchedule(t *testing.T) {
disable_backup = false
backup_schedule_frequency = 24
backup_schedule_retention = 7
backup_same_region = true
user_name = "my_initial_user"
password = "thiZ_is_v&ry_s3cret"
region = "nl-ams"
Expand All @@ -479,6 +480,7 @@ func TestAccScalewayRdbInstance_BackupSchedule(t *testing.T) {
resource.TestCheckResourceAttr("scaleway_rdb_instance.main", "disable_backup", "false"),
resource.TestCheckResourceAttr("scaleway_rdb_instance.main", "backup_schedule_frequency", "24"),
resource.TestCheckResourceAttr("scaleway_rdb_instance.main", "backup_schedule_retention", "7"),
resource.TestCheckResourceAttr("scaleway_rdb_instance.main", "backup_same_region", "true"),
),
},
}})
Expand Down