Skip to content

Commit bcb4173

Browse files
tongyimingmikatong
andauthored
update redis_shard_num (#1111)
* update redis_shard_num * fix redis datasource testcast * forward compatible * update doc Co-authored-by: mikatong <mikatong@tencent.com>
1 parent 7c30ad9 commit bcb4173

File tree

4 files changed

+65
-6
lines changed

4 files changed

+65
-6
lines changed

tencentcloud/data_source_tc_redis_instances_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ resource "tencentcloud_redis_instance" "redis_instance_test" {
5454
mem_size = 8192
5555
name = "terraform_test"
5656
port = 6379
57-
5857
tags = {
5958
"test" = "test"
6059
}

tencentcloud/resource_tc_redis_instance.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,8 @@ func resourceTencentCloudRedisInstance() *schema.Resource {
117117
"redis_shard_num": {
118118
Type: schema.TypeInt,
119119
Optional: true,
120-
ForceNew: true,
121-
Default: 1,
122-
Description: "The number of instance shard. This is not required for standalone and master slave versions.",
120+
Computed: true,
121+
Description: "The number of instance shard, default is 1. This is not required for standalone and master slave versions.",
123122
},
124123
"redis_replicas_num": {
125124
Type: schema.TypeInt,
@@ -283,7 +282,10 @@ func resourceTencentCloudRedisInstanceCreate(d *schema.ResourceData, meta interf
283282
redisName := d.Get("name").(string)
284283
redisType := d.Get("type").(string)
285284
typeId := int64(d.Get("type_id").(int))
286-
redisShardNum := d.Get("redis_shard_num").(int)
285+
var redisShardNum int = 1
286+
if v, ok := d.GetOk("redis_shard_num"); ok {
287+
redisShardNum = v.(int)
288+
}
287289
redisReplicasNum := d.Get("redis_replicas_num").(int)
288290
password := d.Get("password").(string)
289291
noAuth := d.Get("no_auth").(bool)

tencentcloud/resource_tc_redis_instance_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,30 @@ func TestAccTencentCloudRedisInstance_Maz(t *testing.T) {
266266
})
267267
}
268268

269+
func TestAccTencentCloudRedisInstance_Cluster(t *testing.T) {
270+
resource.Test(t, resource.TestCase{
271+
PreCheck: func() { testAccPreCheck(t) },
272+
Providers: testAccProviders,
273+
CheckDestroy: testAccTencentCloudRedisInstanceDestroy,
274+
Steps: []resource.TestStep{
275+
{
276+
Config: testAccRedisInstanceCluster(),
277+
Check: resource.ComposeAggregateTestCheckFunc(
278+
testAccTencentCloudRedisInstanceExists("tencentcloud_redis_instance.redis_cluster"),
279+
resource.TestCheckResourceAttr("tencentcloud_redis_instance.redis_cluster", "redis_shard_num", "1"),
280+
),
281+
},
282+
{
283+
Config: testAccRedisInstanceClusterUpdateShard(),
284+
Check: resource.ComposeAggregateTestCheckFunc(
285+
testAccTencentCloudRedisInstanceExists("tencentcloud_redis_instance.redis_cluster"),
286+
resource.TestCheckResourceAttr("tencentcloud_redis_instance.redis_cluster", "redis_shard_num", "3"),
287+
),
288+
},
289+
},
290+
})
291+
}
292+
269293
func TestAccTencentCloudRedisInstance_Prepaid(t *testing.T) {
270294
resource.Test(t, resource.TestCase{
271295
PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_PREPAY) },
@@ -488,6 +512,40 @@ resource "tencentcloud_redis_instance" "redis_maz" {
488512
}`
489513
}
490514

515+
func testAccRedisInstanceCluster() string {
516+
return defaultVpcVariable + `
517+
resource "tencentcloud_redis_instance" "redis_cluster" {
518+
availability_zone = "ap-guangzhou-3"
519+
type_id = 7
520+
password = "AAA123456BBB"
521+
mem_size = 4096
522+
name = "terraform_cluster"
523+
port = 6379
524+
redis_shard_num = 1
525+
redis_replicas_num = 2
526+
replica_zone_ids = [100003, 100004]
527+
vpc_id = var.vpc_id
528+
subnet_id = var.subnet_id
529+
}`
530+
}
531+
532+
func testAccRedisInstanceClusterUpdateShard() string {
533+
return defaultVpcVariable + `
534+
resource "tencentcloud_redis_instance" "redis_cluster" {
535+
availability_zone = "ap-guangzhou-3"
536+
type_id = 7
537+
password = "AAA123456BBB"
538+
mem_size = 4096
539+
name = "terraform_cluster"
540+
port = 6379
541+
redis_shard_num = 3
542+
redis_replicas_num = 2
543+
replica_zone_ids = [100003, 100004]
544+
vpc_id = var.vpc_id
545+
subnet_id = var.subnet_id
546+
}`
547+
}
548+
491549
func testAccRedisInstancePrepaidBasic() string {
492550
return `
493551
resource "tencentcloud_redis_instance" "redis_prepaid_instance_test" {

website/docs/r/redis_instance.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ The following arguments are supported:
7979
* `prepaid_period` - (Optional) 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`.
8080
* `project_id` - (Optional) Specifies which project the instance should belong to.
8181
* `redis_replicas_num` - (Optional) The number of instance copies. This is not required for standalone and master slave versions.
82-
* `redis_shard_num` - (Optional, ForceNew) The number of instance shard. This is not required for standalone and master slave versions.
82+
* `redis_shard_num` - (Optional) The number of instance shard, default is 1. This is not required for standalone and master slave versions.
8383
* `replica_zone_ids` - (Optional) ID of replica nodes available zone. This is not required for standalone and master slave versions.
8484
* `replicas_read_only` - (Optional, ForceNew) 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.
8585
* `security_groups` - (Optional, ForceNew) ID of security group. If both vpc_id and subnet_id are not set, this argument should not be set either.

0 commit comments

Comments
 (0)