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

[dds instance]support 0 value of keep_days and support update backup_strategy #1041

Merged
merged 1 commit into from
Apr 7, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/resources/dds_instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ The following arguments are supported:
* `flavor` - (Required, List, ForceNew) Specifies the flavors information. The structure is described below.
Changing this creates a new instance.

* `backup_strategy` - (Optional, List, ForceNew) Specifies the advanced backup policy. The structure is
described below. Changing this creates a new instance.
* `backup_strategy` - (Optional, List) Specifies the advanced backup policy. The structure is
described below.

* `ssl` - (Optional, Bool) Specifies whether to enable or disable SSL. Defaults to true.

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.14
require (
github.com/hashicorp/errwrap v1.0.0
github.com/hashicorp/terraform-plugin-sdk v1.16.0
github.com/huaweicloud/golangsdk v0.0.0-20210402075152-aba310c2a950
github.com/huaweicloud/golangsdk v0.0.0-20210406114125-0f07278d722c
github.com/jen20/awspolicyequivalence v1.1.0
github.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa // indirect
github.com/stretchr/testify v1.4.0
Expand Down
10 changes: 2 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,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-20210323020602-6d5ee0030244 h1:Jzq3828aWxaRquRxPqv8aG1A6B+LatrIHiD3SMlHpFM=
github.com/huaweicloud/golangsdk v0.0.0-20210323020602-6d5ee0030244/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0=
github.com/huaweicloud/golangsdk v0.0.0-20210329082007-ee3a1fd6c542 h1:rA1o0dd7F2cR/zBe9Fyk7DjjgSv85MM6PdToMabNXq4=
github.com/huaweicloud/golangsdk v0.0.0-20210329082007-ee3a1fd6c542/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0=
github.com/huaweicloud/golangsdk v0.0.0-20210401071036-b8be64ba4002 h1:RxtuAdoAiJI9bScWcXf09sVDAEjP0w4X8zIe5e4pljU=
github.com/huaweicloud/golangsdk v0.0.0-20210401071036-b8be64ba4002/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0=
github.com/huaweicloud/golangsdk v0.0.0-20210402075152-aba310c2a950 h1:Ys3DRL6qJGYL/9mX8gvzSQade5TOJi8COrPyG58HOQs=
github.com/huaweicloud/golangsdk v0.0.0-20210402075152-aba310c2a950/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0=
github.com/huaweicloud/golangsdk v0.0.0-20210406114125-0f07278d722c h1:CwxvUSdetbTeImxmNxmVTLUE+5ryDAf6DLYE47/28Yo=
github.com/huaweicloud/golangsdk v0.0.0-20210406114125-0f07278d722c/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/imdario/mergo v0.3.9 h1:UauaLniWCFHWd+Jp9oCEkTBj8VO/9DKg3PV3VCNMDIg=
github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
Expand Down
24 changes: 18 additions & 6 deletions huaweicloud/resource_huaweicloud_dds_instance_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ func resourceDdsInstanceV3() *schema.Resource {
"backup_strategy": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Expand Down Expand Up @@ -260,13 +259,14 @@ func resourceDdsBackupStrategy(d *schema.ResourceData) instances.BackupStrategy
var backupStrategy instances.BackupStrategy
backupStrategyRaw := d.Get("backup_strategy").([]interface{})
log.Printf("[DEBUG] backupStrategyRaw: %+v", backupStrategyRaw)
startTime := "00:00-01:00"
keepDays := 7
if len(backupStrategyRaw) == 1 {
backupStrategy.StartTime = backupStrategyRaw[0].(map[string]interface{})["start_time"].(string)
backupStrategy.KeepDays = backupStrategyRaw[0].(map[string]interface{})["keep_days"].(int)
} else {
backupStrategy.StartTime = "00:00-01:00"
backupStrategy.KeepDays = 7
startTime = backupStrategyRaw[0].(map[string]interface{})["start_time"].(string)
keepDays = backupStrategyRaw[0].(map[string]interface{})["keep_days"].(int)
}
backupStrategy.StartTime = startTime
backupStrategy.KeepDays = &keepDays
log.Printf("[DEBUG] backupStrategy: %+v", backupStrategy)
return backupStrategy
}
Expand Down Expand Up @@ -497,6 +497,18 @@ func resourceDdsInstanceV3Update(d *schema.ResourceData, meta interface{}) error
opts = append(opts, opt)
}

if d.HasChange("backup_strategy") {
backupStrategy := resourceDdsBackupStrategy(d)
backupStrategy.Period = "1,2,3,4,5,6,7"
opt := instances.UpdateOpt{
Param: "backup_policy",
Value: backupStrategy,
Action: "backups/policy",
Method: "put",
}
opts = append(opts, opt)
}

r := instances.Update(client, d.Id(), opts)
if r.Err != nil {
return fmt.Errorf("Error updating instance from result: %s ", r.Err)
Expand Down
104 changes: 94 additions & 10 deletions huaweicloud/resource_huaweicloud_dds_instance_v3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/huaweicloud/golangsdk/openstack/dds/v3/instances"
)

func TestAccDDSV3Instance_basic(t *testing.T) {
var instance instances.Instance
rName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(5))
resourceName := "huaweicloud_dds_instance.instance"

resource.ParallelTest(t, resource.TestCase{
Expand All @@ -19,13 +21,24 @@ func TestAccDDSV3Instance_basic(t *testing.T) {
CheckDestroy: testAccCheckDDSV3InstanceDestroy,
Steps: []resource.TestStep{
{
Config: TestAccDDSInstanceV3Config_basic,
Config: testAccDDSInstanceV3Config_basic(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckDDSV3InstanceExists(resourceName, &instance),
resource.TestCheckResourceAttr(resourceName, "name", "dds-instance"),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "ssl", "true"),
resource.TestCheckResourceAttr(resourceName, "tags.foo", "bar"),
resource.TestCheckResourceAttr(resourceName, "tags.owner", "terraform"),
resource.TestCheckResourceAttr(resourceName, "backup_strategy.0.start_time", "08:00-09:00"),
resource.TestCheckResourceAttr(resourceName, "backup_strategy.0.keep_days", "8"),
),
},
{
Config: testAccDDSInstanceV3Config_updateBackupStrategy(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckDDSV3InstanceExists(resourceName, &instance),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "backup_strategy.0.start_time", "00:00-01:00"),
resource.TestCheckResourceAttr(resourceName, "backup_strategy.0.keep_days", "7"),
),
},
},
Expand Down Expand Up @@ -100,22 +113,32 @@ func testAccCheckDDSV3InstanceExists(n string, instance *instances.Instance) res
}
}

var TestAccDDSInstanceV3Config_basic = fmt.Sprintf(`
func testAccDDSInstanceV3Config_basic(rName string) string {
return fmt.Sprintf(`
data "huaweicloud_availability_zones" "test" {}

data "huaweicloud_vpc" "test" {
name = "vpc-default"
}

data "huaweicloud_vpc_subnet" "test" {
name = "subnet-default"
}

resource "huaweicloud_networking_secgroup" "secgroup_acc" {
name = "secgroup_acc"
name = "%s"
}

resource "huaweicloud_dds_instance" "instance" {
name = "dds-instance"
name = "%s"
datastore {
type = "DDS-Community"
version = "3.4"
storage_engine = "wiredTiger"
}
region = "%s"
availability_zone = "%s"
vpc_id = "%s"
subnet_id = "%s"
availability_zone = data.huaweicloud_availability_zones.test.names[0]
vpc_id = data.huaweicloud_vpc.test.id
subnet_id = data.huaweicloud_vpc_subnet.test.id
security_group_id = huaweicloud_networking_secgroup.secgroup_acc.id
password = "Test@123"
mode = "Sharding"
Expand Down Expand Up @@ -147,4 +170,65 @@ resource "huaweicloud_dds_instance" "instance" {
foo = "bar"
owner = "terraform"
}
}`, HW_REGION_NAME, HW_AVAILABILITY_ZONE, HW_VPC_ID, HW_NETWORK_ID)
}`, rName, rName)
}

func testAccDDSInstanceV3Config_updateBackupStrategy(rName string) string {
return fmt.Sprintf(`
data "huaweicloud_availability_zones" "test" {}

data "huaweicloud_vpc" "test" {
name = "vpc-default"
}

data "huaweicloud_vpc_subnet" "test" {
name = "subnet-default"
}

resource "huaweicloud_networking_secgroup" "secgroup_acc" {
name = "%s"
}

resource "huaweicloud_dds_instance" "instance" {
name = "%s"
datastore {
type = "DDS-Community"
version = "3.4"
storage_engine = "wiredTiger"
}
availability_zone = data.huaweicloud_availability_zones.test.names[0]
vpc_id = data.huaweicloud_vpc.test.id
subnet_id = data.huaweicloud_vpc_subnet.test.id
security_group_id = huaweicloud_networking_secgroup.secgroup_acc.id
password = "Test@123"
mode = "Sharding"

flavor {
type = "mongos"
num = 2
spec_code = "dds.mongodb.c3.medium.4.mongos"
}
flavor {
type = "shard"
num = 2
storage = "ULTRAHIGH"
size = 20
spec_code = "dds.mongodb.c3.medium.4.shard"
}
flavor {
type = "config"
num = 1
storage = "ULTRAHIGH"
size = 20
spec_code = "dds.mongodb.c3.large.2.config"
}
backup_strategy {
start_time = "00:00-01:00"
keep_days = "7"
}
tags = {
foo = "bar"
owner = "terraform"
}
}`, rName, rName)
}

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

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,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-20210402075152-aba310c2a950
# github.com/huaweicloud/golangsdk v0.0.0-20210406114125-0f07278d722c
## explicit
github.com/huaweicloud/golangsdk
github.com/huaweicloud/golangsdk/internal
Expand Down