Skip to content

Commit 8351a67

Browse files
gitmknanonymous
andauthored
feat: Non-multi-AZ supports modifying the number of replicas (#1969)
* feat: Non-multi-AZ supports modifying the number of replicas * feat: add changelog --------- Co-authored-by: anonymous <anonymous@mail.org>
1 parent 0d3a9c4 commit 8351a67

File tree

6 files changed

+109
-7
lines changed

6 files changed

+109
-7
lines changed

.changelog/1969.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_redis_instance: Non-multi-AZ supports modifying the number of replicas
3+
```

tencentcloud/basic_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,15 @@ const (
10321032
defaultCrsGroupId = "crs-rpl-orfiwmn5"
10331033
)
10341034

1035+
const DefaultCrsVar = `
1036+
variable "vpc_id" {
1037+
default = "` + defaultCrsVpcId + `"
1038+
}
1039+
variable "subnet_id" {
1040+
default = "` + defaultCrsSubnetId + `"
1041+
}
1042+
`
1043+
10351044
// End of CRS
10361045

10371046
const (

tencentcloud/resource_tc_redis_instance.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func resourceTencentCloudRedisInstance() *schema.Resource {
128128
Type: schema.TypeInt,
129129
Optional: true,
130130
Default: 1,
131-
Description: "The number of instance copies. This is not required for standalone and master slave versions and must equal to count of `replica_zone_ids`.",
131+
Description: "The number of instance copies. This is not required for standalone and master slave versions and must equal to count of `replica_zone_ids`, Non-multi-AZ does not require `replica_zone_ids`.",
132132
},
133133
"replica_zone_ids": {
134134
Type: schema.TypeList,
@@ -1157,6 +1157,28 @@ func resourceRedisNodeSetModify(ctx context.Context, service *RedisService, d *s
11571157
}
11581158
}
11591159

1160+
// Non-Multi-AZ modification redis_replicas_num
1161+
if d.HasChange("redis_replicas_num") && len(oz) == 0 && len(nz) == 0 {
1162+
_, replica := d.GetChange("redis_replicas_num")
1163+
redisReplicasNum := replica.(int)
1164+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
1165+
_, err := service.UpgradeInstance(ctx, id, memSize, shardNum, redisReplicasNum, nil)
1166+
if err != nil {
1167+
// Upgrade memory will cause instance lock and cannot acknowledge by polling status, wait until lock release
1168+
return retryError(err, redis.FAILEDOPERATION_UNKNOWN, redis.FAILEDOPERATION_SYSTEMERROR)
1169+
}
1170+
return nil
1171+
})
1172+
if err != nil {
1173+
return err
1174+
}
1175+
1176+
err = service.CheckRedisUpdateOk(ctx, id)
1177+
if err != nil {
1178+
return err
1179+
}
1180+
}
1181+
11601182
return nil
11611183
}
11621184

tencentcloud/resource_tc_redis_instance_test.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,31 @@ func TestAccTencentCloudRedisInstance_Cluster(t *testing.T) {
311311
})
312312
}
313313

314+
// go test -i; go test -test.run TestAccTencentCloudRedisInstance_ReplicasNum -v
315+
func TestAccTencentCloudRedisInstance_ReplicasNum(t *testing.T) {
316+
resource.Test(t, resource.TestCase{
317+
PreCheck: func() { testAccPreCheck(t) },
318+
Providers: testAccProviders,
319+
CheckDestroy: testAccTencentCloudRedisInstanceDestroy,
320+
Steps: []resource.TestStep{
321+
{
322+
Config: testAccRedisReplicasNum,
323+
Check: resource.ComposeAggregateTestCheckFunc(
324+
testAccTencentCloudRedisInstanceExists("tencentcloud_redis_instance.redis_instance_replicas"),
325+
resource.TestCheckResourceAttr("tencentcloud_redis_instance.redis_instance_replicas", "redis_replicas_num", "1"),
326+
),
327+
},
328+
{
329+
Config: testAccRedisReplicasNumUp,
330+
Check: resource.ComposeAggregateTestCheckFunc(
331+
testAccTencentCloudRedisInstanceExists("tencentcloud_redis_instance.redis_instance_replicas"),
332+
resource.TestCheckResourceAttr("tencentcloud_redis_instance.redis_instance_replicas", "redis_replicas_num", "2"),
333+
),
334+
},
335+
},
336+
})
337+
}
338+
314339
func TestAccTencentCloudRedisInstance_Prepaid(t *testing.T) {
315340
resource.Test(t, resource.TestCase{
316341
PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_PREPAY) },
@@ -744,3 +769,46 @@ resource "tencentcloud_redis_instance" "redis_instance_test" {
744769
}
745770
`
746771
}
772+
773+
const testAccRedisReplicasNum = DefaultCrsVar + `
774+
resource "tencentcloud_redis_instance" "redis_instance_replicas" {
775+
auto_renew_flag = 0
776+
availability_zone = "ap-guangzhou-6"
777+
charge_type = "POSTPAID"
778+
password = "test12345789"
779+
mem_size = 4096
780+
name = "terraform_test_replicas"
781+
port = 6379
782+
project_id = 0
783+
redis_replicas_num = 1
784+
redis_shard_num = 3
785+
replicas_read_only = false
786+
security_groups = [
787+
"sg-edmur627",
788+
]
789+
subnet_id = var.subnet_id
790+
type_id = 7
791+
vpc_id = var.vpc_id
792+
}`
793+
794+
const testAccRedisReplicasNumUp = DefaultCrsVar + `
795+
resource "tencentcloud_redis_instance" "redis_instance_replicas" {
796+
auto_renew_flag = 0
797+
availability_zone = "ap-guangzhou-6"
798+
charge_type = "POSTPAID"
799+
password = "test12345789"
800+
mem_size = 4096
801+
name = "terraform_test_replicas"
802+
port = 6379
803+
project_id = 0
804+
redis_replicas_num = 2
805+
redis_shard_num = 3
806+
replicas_read_only = false
807+
security_groups = [
808+
"sg-edmur627",
809+
]
810+
subnet_id = var.subnet_id
811+
tags = {}
812+
type_id = 7
813+
vpc_id = var.vpc_id
814+
}`

website/docs/r/redis_instance.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ The following arguments are supported:
8686
* `prepaid_period` - (Optional, Int) The tenancy (time unit is month) of the prepaid instance, NOTE: it only works when charge_type is set to `PREPAID`. Valid values are `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `10`, `11`, `12`, `24`, `36`.
8787
* `project_id` - (Optional, Int) Specifies which project the instance should belong to.
8888
* `recycle` - (Optional, Int) Original intranet IPv4 address retention time: unit: day, value range: `0`, `1`, `2`, `3`, `7`, `15`.
89-
* `redis_replicas_num` - (Optional, Int) The number of instance copies. This is not required for standalone and master slave versions and must equal to count of `replica_zone_ids`.
89+
* `redis_replicas_num` - (Optional, Int) The number of instance copies. This is not required for standalone and master slave versions and must equal to count of `replica_zone_ids`, Non-multi-AZ does not require `replica_zone_ids`.
9090
* `redis_shard_num` - (Optional, Int) The number of instance shard, default is 1. This is not required for standalone and master slave versions.
9191
* `replica_zone_ids` - (Optional, List: [`Int`]) ID of replica nodes available zone. This is not required for standalone and master slave versions. NOTE: Removing some of the same zone of replicas (e.g. removing 100001 of [100001, 100001, 100002]) will pick the first hit to remove.
9292
* `replicas_read_only` - (Optional, Bool) Whether copy read-only is supported, Redis 2.8 Standard Edition and CKV Standard Edition do not support replica read-only, turn on replica read-only, the instance will automatically read and write separate, write requests are routed to the primary node, read requests are routed to the replica node, if you need to open replica read-only, the recommended number of replicas >=2.

website/tencentcloud.erb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2947,22 +2947,22 @@
29472947
<a href="/docs/providers/tencentcloud/d/tse_access_address.html">tencentcloud_tse_access_address</a>
29482948
</li>
29492949
<li>
2950-
<a href="/docs/providers/tencentcloud/d/tse_nacos_replicas.html">tencentcloud_tse_nacos_replicas</a>
2950+
<a href="/docs/providers/tencentcloud/d/tse_gateway_canary_rules.html">tencentcloud_tse_gateway_canary_rules</a>
29512951
</li>
29522952
<li>
2953-
<a href="/docs/providers/tencentcloud/d/tse_zookeeper_replicas.html">tencentcloud_tse_zookeeper_replicas</a>
2953+
<a href="/docs/providers/tencentcloud/d/tse_gateway_nodes.html">tencentcloud_tse_gateway_nodes</a>
29542954
</li>
29552955
<li>
2956-
<a href="/docs/providers/tencentcloud/d/tse_zookeeper_server_interfaces.html">tencentcloud_tse_zookeeper_server_interfaces</a>
2956+
<a href="/docs/providers/tencentcloud/d/tse_nacos_replicas.html">tencentcloud_tse_nacos_replicas</a>
29572957
</li>
29582958
<li>
29592959
<a href="/docs/providers/tencentcloud/d/tse_nacos_server_interfaces.html">tencentcloud_tse_nacos_server_interfaces</a>
29602960
</li>
29612961
<li>
2962-
<a href="/docs/providers/tencentcloud/d/tse_gateway_nodes.html">tencentcloud_tse_gateway_nodes</a>
2962+
<a href="/docs/providers/tencentcloud/d/tse_zookeeper_replicas.html">tencentcloud_tse_zookeeper_replicas</a>
29632963
</li>
29642964
<li>
2965-
<a href="/docs/providers/tencentcloud/d/tse_gateway_canary_rules.html">tencentcloud_tse_gateway_canary_rules</a>
2965+
<a href="/docs/providers/tencentcloud/d/tse_zookeeper_server_interfaces.html">tencentcloud_tse_zookeeper_server_interfaces</a>
29662966
</li>
29672967
</ul>
29682968
</li>

0 commit comments

Comments
 (0)