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] AZ switchover and backup strategy fix in resource/opentelekomcloud_rds_instance_v3 #2194

Merged
merged 2 commits into from Jun 21, 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: 2 additions & 0 deletions docs/resources/rds_instance_v3.md
Expand Up @@ -434,6 +434,8 @@ The `restore_point` block supports:

In addition to the arguments listed above, the following computed attributes are exported:

* `availability_zones` - Indicates the instance AZs.

* `created` - Indicates the creation time.

* `nodes` - Indicates the instance nodes information. Structure is documented below.
Expand Down
Expand Up @@ -28,6 +28,7 @@ func TestAccRdsInstanceV3_importBasic(t *testing.T) {
ImportStateVerifyIgnore: []string{
"db",
"availability_zone",
"tags",
},
},
},
Expand Down
Expand Up @@ -178,6 +178,7 @@ func TestAccRdsInstanceV3HA(t *testing.T) {
resource.TestCheckResourceAttr(instanceV3ResourceName, "ha_replication_mode", "semisync"),
resource.TestCheckResourceAttr(instanceV3ResourceName, "volume.0.type", "ULTRAHIGH"),
resource.TestCheckResourceAttr(instanceV3ResourceName, "db.0.type", "MySQL"),
resource.TestCheckResourceAttr(instanceV3ResourceName, "availability_zones.#", "2"),
),
},
},
Expand Down
Expand Up @@ -182,20 +182,17 @@ func ResourceRdsInstanceV3() *schema.Resource {
Type: schema.TypeList,
Computed: true,
Optional: true,
ForceNew: false,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"start_time": {
Type: schema.TypeString,
Required: true,
ForceNew: false,
},
"keep_days": {
Type: schema.TypeInt,
Computed: true,
Optional: true,
ForceNew: false,
},
},
},
Expand Down Expand Up @@ -282,6 +279,13 @@ func ResourceRdsInstanceV3() *schema.Resource {
Type: schema.TypeBool,
Optional: true,
},
"availability_zones": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
}
}
Expand Down Expand Up @@ -370,6 +374,7 @@ func resourceRdsInstanceV3Create(ctx context.Context, d *schema.ResourceData, me
dbPortString = ""
}

datastore := resourceRDSDataStore(d)
var r *instances.CreateRds
if _, ok := d.GetOk("restore_point"); ok {
restoreOpts := backups.RestoreToNewOpts{
Expand All @@ -396,7 +401,7 @@ func resourceRdsInstanceV3Create(ctx context.Context, d *schema.ResourceData, me
} else {
createOpts := instances.CreateRdsOpts{
Name: d.Get("name").(string),
Datastore: resourceRDSDataStore(d),
Datastore: datastore,
Ha: resourceRDSHa(d),
ConfigurationId: d.Get("param_group_id").(string),
Port: dbPortString,
Expand Down Expand Up @@ -465,6 +470,22 @@ func resourceRdsInstanceV3Create(ctx context.Context, d *schema.ResourceData, me
}
}

var backupOpts backups.UpdateOpts

// 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.StartTime = backupRaw.StartTime
backupOpts.Period = "1,2,3,4,5,6,7"
backupOpts.InstanceId = d.Id()
log.Printf("[DEBUG] Backup Strategy Opts: %#v", backupOpts)

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

clientCtx := common.CtxWithClient(ctx, client, keyClientV3)

ip := getPublicIP(d)
Expand Down Expand Up @@ -1080,7 +1101,7 @@ func resourceRdsInstanceV3Read(ctx context.Context, d *schema.ResourceData, meta
fmterr.Errorf("RDSv3 instance expects 1 or 2 nodes, but got %d", n)
}

if err := d.Set("availability_zone", availabilityZones); err != nil {
if err := d.Set("availability_zones", availabilityZones); err != nil {
return diag.FromErr(err)
}

Expand Down
6 changes: 6 additions & 0 deletions releasenotes/notes/rdsv3-switchover-fix-3cf96ef10cb26c1d.yaml
@@ -0,0 +1,6 @@
---
fixes:
- |
**[RDS]** Fix forcing update after switchover by storing `azs` in computed attribute `availability_zones` in ``resource/opentelekomcloud_rds_instance_v3`` (`#2194 <https://github.com/opentelekomcloud/terraform-provider-opentelekomcloud/pull/2194>`_)
- |
**[RDS]** Temporary fix for PostrgeSQL failed `backup_strategy` setting of `start_time` in ``resource/opentelekomcloud_rds_instance_v3`` (`#2194 <https://github.com/opentelekomcloud/terraform-provider-opentelekomcloud/pull/2194>`_)