Skip to content

Commit

Permalink
support updating backup_strategy in opengauss
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason-Zhang9309 committed Jan 19, 2021
1 parent 8fa8608 commit 18aee15
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 11 deletions.
7 changes: 3 additions & 4 deletions docs/resources/gaussdb_opengauss_instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ The following arguments are supported:
* `datastore` - (Optional, List, ForceNew) Specifies the datastore information. Structure is documented below.
Changing this parameter will create a new resource.

* `backup_strategy` - (Optional, List, ForceNew) Specifies the advanced backup policy. Structure is documented below.
Changing this parameter will create a new resource.
* `backup_strategy` - (Optional, List) Specifies the advanced backup policy. Structure is documented below.

* `ha` - (Optional, List, ForceNew) Specifies the HA information. Structure is documented below.
Changing this parameter will create a new resource.
Expand Down Expand Up @@ -123,13 +122,13 @@ The `ha` block supports:

The `backup_strategy` block supports:

* `start_time` - (Required, String, ForceNew) Specifies the backup time window. Automated backups
* `start_time` - (Required, String) Specifies the backup time window. Automated backups
will be triggered during the backup time window. It must be a valid value in
the "hh:mm-HH:MM" format. The current time is in the UTC format.
The HH value must be 1 greater than the hh value. The values of mm and MM
must be the same and must be set to 00, 15, 30 or 45. Example value: 08:15-09:15, 23:00-00:00.

* `keep_days` - (Optional, Int, ForceNew) Specifies the number of days to retain the generated
* `keep_days` - (Optional, Int) Specifies the number of days to retain the generated
backup files. The value ranges from 0 to 732.
If this parameter is set to 0, the automated backup policy is not set.
If this parameter is not transferred, the automated backup policy is enabled by default.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/hashicorp/errwrap v1.0.0
github.com/hashicorp/go-cleanhttp v0.5.1
github.com/hashicorp/terraform-plugin-sdk v1.13.0
github.com/huaweicloud/golangsdk v0.0.0-20210116064800-601b4de34229
github.com/huaweicloud/golangsdk v0.0.0-20210118061029-b3a40d772e0a
github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a
github.com/mitchellh/go-homedir v1.1.0
github.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb h1:b5rjCoWHc7eqmAS
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1vq2e6IsrXKrZit1bv/TDYFGMp4BQ=
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
github.com/huaweicloud/golangsdk v0.0.0-20210116064800-601b4de34229 h1:tbgMbWp2CbIxSb6/YVXLjSnliKDzz5luUjEavpD1jZE=
github.com/huaweicloud/golangsdk v0.0.0-20210116064800-601b4de34229/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0=
github.com/huaweicloud/golangsdk v0.0.0-20210118061029-b3a40d772e0a h1:0T/imzv2jl8yzmeqVIsZ/A/R/kTiDTVqdU+gUBMBWnE=
github.com/huaweicloud/golangsdk v0.0.0-20210118061029-b3a40d772e0a/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0=
github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a h1:FyS/ubzBR5xJlnJGRTwe7GUHpJOR4ukYK3y+LFNffuA=
github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a/go.mod h1:uoIMjNxUfXi48Ci40IXkPRbghZ1vbti6v9LCbNqRgHY=
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
Expand Down
26 changes: 23 additions & 3 deletions huaweicloud/resource_huaweicloud_gaussdb_opengauss_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/huaweicloud/golangsdk"
"github.com/huaweicloud/golangsdk/openstack/opengauss/v3/backups"
"github.com/huaweicloud/golangsdk/openstack/opengauss/v3/instances"
)

Expand Down Expand Up @@ -162,20 +163,17 @@ func resourceOpenGaussInstance() *schema.Resource {
"backup_strategy": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"start_time": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"keep_days": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
},
},
},
Expand Down Expand Up @@ -686,5 +684,27 @@ func resourceOpenGaussInstanceUpdate(d *schema.ResourceData, meta interface{}) e
}
log.Printf("[DEBUG] Successfully updated instance %s", instanceId)

if d.HasChange("backup_strategy") {
backupRaw := d.Get("backup_strategy").([]interface{})
rawMap := backupRaw[0].(map[string]interface{})
keep_days := rawMap["keep_days"].(int)

updateOpts := backups.UpdateOpts{
KeepDays: &keep_days,
StartTime: rawMap["start_time"].(string),
// Fixed to "1,2,3,4,5,6,7"
Period: "1,2,3,4,5,6,7",
// Fixed to "30"
DifferentialPeriod: "30",
}

log.Printf("[DEBUG] Update backup_strategy: %#v", updateOpts)

err = backups.Update(client, d.Id(), updateOpts).ExtractErr()
if err != nil {
return fmt.Errorf("Error updating backup_strategy: %s", err)
}
}

return resourceOpenGaussInstanceRead(d, meta)
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ func TestAccOpenGaussInstance_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "name", rName),
),
},
{
Config: testAccOpenGaussInstanceConfig_back_strategy_update(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckOpenGaussInstanceExists(resourceName, &instance),
resource.TestCheckResourceAttr(resourceName, "backup_strategy.0.start_time", "08:30-09:30"),
resource.TestCheckResourceAttr(resourceName, "backup_strategy.0.keep_days", "8"),
),
},
},
})
}
Expand Down Expand Up @@ -116,3 +124,41 @@ resource "huaweicloud_gaussdb_opengauss_instance" "test" {
}
`, testAccVpcConfig_Base(rName), rName)
}

func testAccOpenGaussInstanceConfig_back_strategy_update(rName string) string {
return fmt.Sprintf(`
%s
data "huaweicloud_networking_secgroup" "test" {
name = "default"
}
resource "huaweicloud_gaussdb_opengauss_instance" "test" {
name = "%s"
password = "Test@123"
flavor = "gaussdb.opengauss.ee.dn.m6.2xlarge.8.in"
vpc_id = huaweicloud_vpc.test.id
subnet_id = huaweicloud_vpc_subnet.test.id
availability_zone = "cn-north-4a,cn-north-4a,cn-north-4a"
security_group_id = data.huaweicloud_networking_secgroup.test.id
ha {
mode = "enterprise"
replication_mode = "sync"
consistency = "strong"
}
volume {
type = "ULTRAHIGH"
size = 40
}
backup_strategy {
start_time = "08:30-09:30"
keep_days = 8
}
sharding_num = 1
coordinator_num = 2
}
`, testAccVpcConfig_Base(rName), rName)
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ github.com/hashicorp/terraform-svchost/auth
github.com/hashicorp/terraform-svchost/disco
# github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d
github.com/hashicorp/yamux
# github.com/huaweicloud/golangsdk v0.0.0-20210116064800-601b4de34229
# github.com/huaweicloud/golangsdk v0.0.0-20210118061029-b3a40d772e0a
## explicit
github.com/huaweicloud/golangsdk
github.com/huaweicloud/golangsdk/internal
Expand Down Expand Up @@ -331,6 +331,7 @@ github.com/huaweicloud/golangsdk/openstack/networking/v2/ports
github.com/huaweicloud/golangsdk/openstack/networking/v2/routes
github.com/huaweicloud/golangsdk/openstack/networking/v2/subnets
github.com/huaweicloud/golangsdk/openstack/obs
github.com/huaweicloud/golangsdk/openstack/opengauss/v3/backups
github.com/huaweicloud/golangsdk/openstack/opengauss/v3/instances
github.com/huaweicloud/golangsdk/openstack/rds/v1/datastores
github.com/huaweicloud/golangsdk/openstack/rds/v1/flavors
Expand Down

0 comments on commit 18aee15

Please sign in to comment.