Skip to content

Commit

Permalink
feat(rdb): add backup_same_region attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Monitob committed Apr 6, 2022
1 parent deaa2c0 commit 14f2eb1
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 103 deletions.
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

0 comments on commit 14f2eb1

Please sign in to comment.