Skip to content

Commit

Permalink
feat(GaussDBforNoSQL): gaussdb redis instance support az detail (#5760)
Browse files Browse the repository at this point in the history
  • Loading branch information
houpeng80 authored Oct 26, 2024
1 parent 5d7fe05 commit 178a17d
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 50 deletions.
15 changes: 15 additions & 0 deletions docs/resources/gaussdb_redis_instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ The following arguments are supported:
* `mode` - (Optional, String, ForceNew) Specifies the instance type. Value options: **Cluster**, **Replication**.
Defaults to **Cluster**.

* `availability_zone_detail` - (Optional, List, ForceNew) Specifies Multi-AZ details of the active/standby instance.
The system ignores this parameter if single-AZ deployment is selected. Currently, only GeminiDB Redis instances are
supported.

The [availability_zone_detail](#availability_zone_detail_struct) structure is documented below.

* `security_group_id` - (Optional, String) Specifies the security group ID. Required if the selected subnet doesn't
enable network ACL.

Expand Down Expand Up @@ -130,6 +136,15 @@ The following arguments are supported:

* `auto_renew` - (Optional, String) Specifies whether auto renew is enabled. Valid values are "true" and "false".

<a name="availability_zone_detail_struct"></a>
The `availability_zone_detail` block supports:

* `primary_availability_zone` - (Required, String, ForceNew) Specifies the primary AZ, it must be a single AZ and be
different from the standby AZ. Changing this parameter will create a new resource.

* `secondary_availability_zone` - (Required, String, ForceNew) Specifies the standby AZ, it must be a single AZ and be
different from the primary AZ. Changing this parameter will create a new resource.

The `datastore` block supports:

* `engine` - (Required, String, ForceNew) Specifies the database engine. Only "redis" is supported now.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
github.com/GehirnInc/crypt v0.0.0-20200316065508-bb7000b8a962
github.com/chnsz/golangsdk v0.0.0-20241021022005-6dc73cc7acbd
github.com/chnsz/golangsdk v0.0.0-20241024112204-a96c8484ffa3
github.com/hashicorp/go-cleanhttp v0.5.2
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-uuid v1.0.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6
github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/chnsz/golangsdk v0.0.0-20241021022005-6dc73cc7acbd h1:0FrN2gktEeGLxlMns89c0LnKdUzytgXY6l8KOtpeMr0=
github.com/chnsz/golangsdk v0.0.0-20241021022005-6dc73cc7acbd/go.mod h1:Erm4hDWxXgAdbkG3+hhJFgRzEL1TvvcroWzw2Gax4uI=
github.com/chnsz/golangsdk v0.0.0-20241024112204-a96c8484ffa3 h1:afaYCtfr7XhRkJQd2UupmTst+/ProhdVdp6tE616mdg=
github.com/chnsz/golangsdk v0.0.0-20241024112204-a96c8484ffa3/go.mod h1:Erm4hDWxXgAdbkG3+hhJFgRzEL1TvvcroWzw2Gax4uI=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestAccGaussRedisInstance_withReplication(t *testing.T) {
testAccCheckGaussRedisInstanceExists(resourceName, &instance),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "node_num", "2"),
resource.TestCheckResourceAttr(resourceName, "volume_size", "16"),
resource.TestCheckResourceAttr(resourceName, "volume_size", "2"),
resource.TestCheckResourceAttr(resourceName, "status", "normal"),
resource.TestCheckResourceAttr(resourceName, "port", "8888"),
resource.TestCheckResourceAttr(resourceName, "ssl", "true"),
Expand Down Expand Up @@ -312,25 +312,26 @@ data "huaweicloud_vpc_subnet" "test" {
name = "subnet-default"
}
data "huaweicloud_gaussdb_nosql_flavors" "test" {
vcpus = 2
engine = "redis"
availability_zone = data.huaweicloud_availability_zones.test.names[0]
}
data "huaweicloud_gaussdb_redis_flavors" "test" {}
resource "huaweicloud_gaussdb_redis_instance" "test" {
name = "%[2]s"
password = "Huangwei!120521"
flavor = data.huaweicloud_gaussdb_nosql_flavors.test.flavors[0].name
volume_size = 16
flavor = data.huaweicloud_gaussdb_redis_flavors.test.flavors[0].spec_code
volume_size = 2
vpc_id = data.huaweicloud_vpc.test.id
subnet_id = data.huaweicloud_vpc_subnet.test.id
node_num = 2
port = 8888
ssl = true
mode = "Replication"
security_group_id = huaweicloud_networking_secgroup.test.id
availability_zone = data.huaweicloud_availability_zones.test.names[0]
availability_zone = keys(data.huaweicloud_gaussdb_redis_flavors.test.flavors[0].az_status)[1]
availability_zone_detail{
primary_availability_zone = split(",", keys(data.huaweicloud_gaussdb_redis_flavors.test.flavors[0].az_status)[1])[0]
secondary_availability_zone = split(",", keys(data.huaweicloud_gaussdb_redis_flavors.test.flavors[0].az_status)[1])[1]
}
}
`, common.TestSecGroup(rName), rName)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,26 @@ func ResourceGaussRedisInstanceV3() *schema.Resource {
Default: "Cluster",
ForceNew: true,
},
"availability_zone_detail": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"primary_availability_zone": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"secondary_availability_zone": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
},
},
},
"security_group_id": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -277,6 +297,20 @@ func ResourceGaussRedisInstanceV3() *schema.Resource {
}
}

func resourceGaussRedisBackupStrategy(d *schema.ResourceData) *instances.BackupStrategyOpt {
if _, ok := d.GetOk("backup_strategy"); ok {
opt := &instances.BackupStrategyOpt{
StartTime: d.Get("backup_strategy.0.start_time").(string),
}
// The default value of keepdays is 7, but empty value of keepdays will be converted to 0.
if v, ok := d.GetOk("backup_strategy.0.keep_days"); ok {
opt.KeepDays = strconv.Itoa(v.(int))
}
return opt
}
return nil
}

func resourceGaussRedisDataStore(d *schema.ResourceData) instances.DataStore {
var db instances.DataStore

Expand All @@ -294,16 +328,16 @@ func resourceGaussRedisDataStore(d *schema.ResourceData) instances.DataStore {
return db
}

func resourceGaussRedisBackupStrategy(d *schema.ResourceData) *instances.BackupStrategyOpt {
if _, ok := d.GetOk("backup_strategy"); ok {
opt := &instances.BackupStrategyOpt{
StartTime: d.Get("backup_strategy.0.start_time").(string),
}
// The default value of keepdays is 7, but empty value of keepdays will be converted to 0.
if v, ok := d.GetOk("backup_strategy.0.keep_days"); ok {
opt.KeepDays = strconv.Itoa(v.(int))
func resourceGaussRedisAvailabilityZoneDetail(d *schema.ResourceData) *instances.AvailabilityZoneDetailOpt {
if v, ok := d.GetOk("availability_zone_detail"); ok {
availabilityZoneDetail := v.([]interface{})[0]
if detail, ok := availabilityZoneDetail.(map[string]interface{}); ok {
opt := &instances.AvailabilityZoneDetailOpt{
PrimaryAvailabilityZone: detail["primary_availability_zone"].(string),
SecondaryAvailabilityZone: detail["secondary_availability_zone"].(string),
}
return opt
}
return opt
}
return nil
}
Expand Down Expand Up @@ -367,17 +401,18 @@ func resourceGaussRedisInstanceV3Create(ctx context.Context, d *schema.ResourceD
}

createOpts := instances.CreateGeminiDBOpts{
Name: d.Get("name").(string),
Region: region,
AvailabilityZone: d.Get("availability_zone").(string),
VpcId: d.Get("vpc_id").(string),
SubnetId: d.Get("subnet_id").(string),
SecurityGroupId: d.Get("security_group_id").(string),
EnterpriseProjectId: cfg.GetEnterpriseProjectID(d),
Mode: d.Get("mode").(string),
Flavor: resourceGaussRedisFlavor(d),
DataStore: resourceGaussRedisDataStore(d),
BackupStrategy: resourceGaussRedisBackupStrategy(d),
Name: d.Get("name").(string),
Region: region,
AvailabilityZone: d.Get("availability_zone").(string),
AvailabilityZoneDetail: resourceGaussRedisAvailabilityZoneDetail(d),
VpcId: d.Get("vpc_id").(string),
SubnetId: d.Get("subnet_id").(string),
SecurityGroupId: d.Get("security_group_id").(string),
EnterpriseProjectId: cfg.GetEnterpriseProjectID(d),
Mode: d.Get("mode").(string),
Flavor: resourceGaussRedisFlavor(d),
DataStore: resourceGaussRedisDataStore(d),
BackupStrategy: resourceGaussRedisBackupStrategy(d),
}

if port, ok := d.GetOk("port"); ok {
Expand Down

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 @@ -13,7 +13,7 @@ github.com/apparentlymart/go-cidr/cidr
# github.com/apparentlymart/go-textseg/v13 v13.0.0
## explicit; go 1.16
github.com/apparentlymart/go-textseg/v13/textseg
# github.com/chnsz/golangsdk v0.0.0-20241021022005-6dc73cc7acbd
# github.com/chnsz/golangsdk v0.0.0-20241024112204-a96c8484ffa3
## explicit; go 1.14
github.com/chnsz/golangsdk
github.com/chnsz/golangsdk/auth
Expand Down

0 comments on commit 178a17d

Please sign in to comment.