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

RDS: Fix keep_days zero values #2263

Merged
merged 2 commits into from Aug 14, 2023
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: 1 addition & 1 deletion go.mod
Expand Up @@ -14,7 +14,7 @@ require (
github.com/jinzhu/copier v0.3.5
github.com/keybase/go-crypto v0.0.0-20200123153347-de78d2cb44f4
github.com/mitchellh/go-homedir v1.1.0
github.com/opentelekomcloud/gophertelekomcloud v0.7.1-0.20230810152808-2b43da3080c2
github.com/opentelekomcloud/gophertelekomcloud v0.7.1-0.20230811193149-628a36fe3732
github.com/unknwon/com v1.0.1
golang.org/x/crypto v0.1.0
golang.org/x/sync v0.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -154,8 +154,8 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLA
github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce h1:RPclfga2SEJmgMmz2k+Mg7cowZ8yv4Trqw9UsJby758=
github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/opentelekomcloud/gophertelekomcloud v0.7.1-0.20230810152808-2b43da3080c2 h1:zII8WprAPQiHqE6ZU7w8fNl05JLUvxJ4ZpQjsK7SRXU=
github.com/opentelekomcloud/gophertelekomcloud v0.7.1-0.20230810152808-2b43da3080c2/go.mod h1:9Deb3q2gJvq5dExV+aX+iO+G+mD9Zr9uFt+YY9ONmq0=
github.com/opentelekomcloud/gophertelekomcloud v0.7.1-0.20230811193149-628a36fe3732 h1:JR1pt7wzwZdpBrwtULQMbww72WsPAcwRkQu8RPyfCYo=
github.com/opentelekomcloud/gophertelekomcloud v0.7.1-0.20230811193149-628a36fe3732/go.mod h1:9Deb3q2gJvq5dExV+aX+iO+G+mD9Zr9uFt+YY9ONmq0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
Expand Up @@ -37,7 +37,7 @@ func TestAccRdsInstanceV3Basic(t *testing.T) {
resource.TestCheckResourceAttr(instanceV3ResourceName, "db.0.type", "PostgreSQL"),
resource.TestCheckResourceAttr(instanceV3ResourceName, "db.0.port", "8635"),
resource.TestCheckResourceAttr(instanceV3ResourceName, "volume.0.size", "40"),
resource.TestCheckResourceAttr(instanceV3ResourceName, "backup_strategy.0.keep_days", "1"),
resource.TestCheckResourceAttr(instanceV3ResourceName, "backup_strategy.0.keep_days", "0"),
resource.TestCheckResourceAttr(instanceV3ResourceName, "tags.muh", "value-create"),
resource.TestCheckResourceAttr(instanceV3ResourceName, "tags.kuh", "value-create"),
resource.TestCheckResourceAttr(instanceV3ResourceName, "lower_case_table_names", "0"),
Expand Down Expand Up @@ -412,7 +412,7 @@ resource "opentelekomcloud_rds_instance_v3" "instance" {
flavor = "rds.pg.c2.large"
backup_strategy {
start_time = "08:00-09:00"
keep_days = 1
keep_days = 0
}
tags = {
muh = "value-create"
Expand Down
Expand Up @@ -494,7 +494,7 @@ func resourceRdsInstanceV3Create(ctx context.Context, d *schema.ResourceData, me
// workaround for https://jira.tsi-dev.otc-service.com/browse/BM-2388
if strings.ToLower(datastore.Type) == "postgresql" && common.HasFilledOpt(d, "backup_strategy") {
backupRaw := resourceRDSBackupStrategy(d)
backupOpts.KeepDays = backupRaw.KeepDays
backupOpts.KeepDays = &backupRaw.KeepDays
backupOpts.StartTime = backupRaw.StartTime
backupOpts.Period = "1,2,3,4,5,6,7"
backupOpts.InstanceId = d.Id()
Expand Down Expand Up @@ -806,14 +806,16 @@ func resourceRdsInstanceV3Update(ctx context.Context, d *schema.ResourceData, me

if d.HasChange("backup_strategy") {
backupRaw := resourceRDSBackupStrategy(d)
updateBackupOpts.KeepDays = backupRaw.KeepDays
updateBackupOpts.StartTime = backupRaw.StartTime
updateBackupOpts.Period = "1,2,3,4,5,6,7"
updateBackupOpts.InstanceId = d.Id()
log.Printf("[DEBUG] updateOpts: %#v", updateBackupOpts)

if err = backups.Update(client, updateBackupOpts); err != nil {
return fmterr.Errorf("error updating OpenTelekomCloud RDSv3 Instance: %s", err)
if backupRaw.KeepDays != 0 {
updateBackupOpts.KeepDays = &backupRaw.KeepDays
updateBackupOpts.StartTime = backupRaw.StartTime
updateBackupOpts.Period = "1,2,3,4,5,6,7"
updateBackupOpts.InstanceId = d.Id()
log.Printf("[DEBUG] updateOpts: %#v", updateBackupOpts)

if err = backups.Update(client, updateBackupOpts); err != nil {
return fmterr.Errorf("error updating OpenTelekomCloud RDSv3 Instance: %s", err)
}
}
}

Expand Down Expand Up @@ -1125,8 +1127,15 @@ func resourceRdsInstanceV3Read(ctx context.Context, d *schema.ResourceData, meta

var backupStrategyList []map[string]interface{}
backupStrategy := make(map[string]interface{})
backupStrategy["start_time"] = rdsInstance.BackupStrategy.StartTime
backupStrategy["keep_days"] = rdsInstance.BackupStrategy.KeepDays
// if `keep_days` is set to 0 backend returns empty `start_time`
// which forces instance update
if backupStrategy["keep_days"] != 0 {
backupStrategy["start_time"] = rdsInstance.BackupStrategy.StartTime
} else {
backupRaw := resourceRDSBackupStrategy(d)
backupStrategy["start_time"] = backupRaw.StartTime
}
backupStrategyList = append(backupStrategyList, backupStrategy)
if err := d.Set("backup_strategy", backupStrategyList); err != nil {
return fmterr.Errorf("error setting backup strategy: %s", err)
Expand Down
4 changes: 4 additions & 0 deletions releasenotes/notes/rds_keepdays_fix-0b7e43557198bb23.yaml
@@ -0,0 +1,4 @@
---
fixes:
- |
**[RDS]** RDS `keep_days` zero value fix for ``resource/opentelekomcloud_rds_instance_v3`` (`#2263 <https://github.com/opentelekomcloud/terraform-provider-opentelekomcloud/pull/2263>`_)