Skip to content

Commit 48fac55

Browse files
authored
Merge pull request #416 from Himer/master
redis `type_id`,`redis_shard_num`,`redis_replicas_num` supports.
2 parents a1022b5 + da9c8f6 commit 48fac55

13 files changed

+341
-114
lines changed

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
## 1.34.0 (Unreleased)
1+
## 1.33.1 (Unreleased)
2+
3+
ENHANCEMENTS:
4+
Resource: `tencentcloud_redis_instance` add new argument `type_id`,`redis_shard_num`,`redis_replicas_num`
5+
Data Source: `tencentcloud_redis_instances` add new argument `type_id`,`redis_shard_num`,`redis_replicas_num`
6+
Data Source: `tencentcloud_redis_zone_config` add output argument `type_id` and new output argument `type_id`,`redis_shard_nums`,`redis_replicas_nums`
7+
8+
DEPRECATED:
9+
* Resource: `tencentcloud_redis_instance`: optional argument `type` is no longer supported, replace by `type_id`.
10+
* Data Source: `tencentcloud_redis_instances`: output argument `type` is no longer supported, replace by `type_id`
11+
* Data Source: `tencentcloud_redis_zone_config`: output argument `type` is no longer supported, replace by `type_id`
12+
213
## 1.33.0 (May 18, 2020)
314

415
FEATURES:

tencentcloud/connectivity/transport.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"time"
1111
)
1212

13-
const ReqClient = "Terraform-v1.24.1"
13+
const ReqClient = "Terraform-v1.33.1"
1414

1515
type LogRoundTripper struct {
1616
}
@@ -27,19 +27,20 @@ func (me *LogRoundTripper) RoundTrip(request *http.Request) (response *http.Resp
2727
if errRet != nil {
2828
return
2929
}
30-
30+
var headName = "X-TC-Action"
3131
request.Header.Set("X-TC-RequestClient", ReqClient)
32-
inBytes = []byte(fmt.Sprintf("%s, request: ", request.Header["X-TC-Action"]))
32+
inBytes = []byte(fmt.Sprintf("%s, request: ", request.Header[headName]))
3333
requestBody, errRet := ioutil.ReadAll(bodyReader)
3434
if errRet != nil {
3535
return
3636
}
3737
inBytes = append(inBytes, requestBody...)
3838

39+
headName = "X-TC-Region"
3940
appendMessage := []byte(fmt.Sprintf(
4041
", (host %+v, region:%+v)",
4142
request.Header["Host"],
42-
request.Header["X-TC-Region"],
43+
request.Header[headName],
4344
))
4445

4546
inBytes = append(inBytes, appendMessage...)

tencentcloud/data_source_tc_redis_instances.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,27 @@ func dataSourceTencentRedisInstances() *schema.Resource {
8787
Computed: true,
8888
Description: "ID of the project to which a redis instance belongs.",
8989
},
90+
"type_id": {
91+
Type: schema.TypeInt,
92+
Computed: true,
93+
Description: "Instance type. Refer to `data.tencentcloud_redis_zone_config.list.type_id` get available values.",
94+
},
9095
"type": {
9196
Type: schema.TypeString,
9297
Computed: true,
98+
Deprecated: "It has been deprecated from version 1.33.1. Please use 'type_id' instead.",
9399
Description: "Instance type. Available values: master_slave_redis, master_slave_ckv, cluster_ckv, cluster_redis and standalone_redis.",
94100
},
101+
"redis_shard_num": {
102+
Type: schema.TypeInt,
103+
Computed: true,
104+
Description: "The number of instance shard.",
105+
},
106+
"redis_replicas_num": {
107+
Type: schema.TypeInt,
108+
Computed: true,
109+
Description: "The number of instance copies.",
110+
},
95111
"mem_size": {
96112
Type: schema.TypeInt,
97113
Computed: true,
@@ -225,6 +241,9 @@ instanceLoop:
225241
instanceDes["create_time"] = instance.CreateTime
226242

227243
instanceDes["tags"] = instance.Tags
244+
instanceDes["redis_shard_num"] = instance.RedisShardNum
245+
instanceDes["redis_replicas_num"] = instance.RedisReplicasNum
246+
instanceDes["type_id"] = instance.TypeId
228247

229248
instanceList = append(instanceList, instanceDes)
230249
}

tencentcloud/data_source_tc_redis_instances_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func testAccTencentCloudRedisInstancesDataSourceConfig() string {
4747
return `
4848
resource "tencentcloud_redis_instance" "redis_instance_test" {
4949
availability_zone = "ap-guangzhou-3"
50-
type = "master_slave_redis"
50+
type_id = 2
5151
password = "test12345789"
5252
mem_size = 8192
5353
name = "terraform_test"

tencentcloud/data_source_tc_redis_zone_config.go

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ func dataSourceTencentRedisZoneConfig() *schema.Resource {
3131
Optional: true,
3232
Description: "Name of a region. If this value is not set, the current region getting from provider's configuration will be used.",
3333
},
34+
"type_id": {
35+
Type: schema.TypeInt,
36+
Optional: true,
37+
ValidateFunc: validateIntegerMin(2),
38+
Description: "Instance type id.",
39+
},
3440
"result_output_file": {
3541
Type: schema.TypeString,
3642
Optional: true,
@@ -48,9 +54,15 @@ func dataSourceTencentRedisZoneConfig() *schema.Resource {
4854
Computed: true,
4955
Description: "ID of available zone.",
5056
},
57+
"type_id": {
58+
Type: schema.TypeInt,
59+
Computed: true,
60+
Description: "Instance type. Which redis type supports in this zone.",
61+
},
5162
"type": {
5263
Type: schema.TypeString,
5364
Computed: true,
65+
Deprecated: "It has been deprecated from version 1.33.1. Please use 'type_id' instead.",
5466
Description: "Instance type. Available values: master_slave_redis, master_slave_ckv, cluster_ckv, cluster_redis and standalone_redis.",
5567
},
5668
"version": {
@@ -64,6 +76,18 @@ func dataSourceTencentRedisZoneConfig() *schema.Resource {
6476
Computed: true,
6577
Description: "The memory volume of an available instance(in MB).",
6678
},
79+
"redis_shard_nums": {
80+
Type: schema.TypeList,
81+
Computed: true,
82+
Elem: &schema.Schema{Type: schema.TypeInt},
83+
Description: "The support numbers of instance shard.",
84+
},
85+
"redis_replicas_nums": {
86+
Type: schema.TypeList,
87+
Computed: true,
88+
Elem: &schema.Schema{Type: schema.TypeInt},
89+
Description: "The support numbers of instance copies.",
90+
},
6791
},
6892
},
6993
},
@@ -86,6 +110,8 @@ func dataSourceTencentRedisZoneConfigRead(d *schema.ResourceData, meta interface
86110
log.Printf("[INFO]%s region is not set,so we use [%s] from env\n ", logId, region)
87111
}
88112

113+
typeId := int64(d.Get("type_id").(int))
114+
89115
sellConfigures, err := service.DescribeRedisZoneConfig(ctx)
90116
if err != nil {
91117
return fmt.Errorf("api[DescribeRedisZoneConfig]fail, return %s", err.Error())
@@ -110,18 +136,19 @@ func dataSourceTencentRedisZoneConfigRead(d *schema.ResourceData, meta interface
110136
if *products.PayMode != "0" {
111137
continue
112138
}
113-
//this products sale out.
114-
if *products.Saleout {
115-
continue
116-
}
117-
//not support this type now .
118-
if REDIS_NAMES[*products.Type] == "" {
139+
140+
if typeId != 0 && typeId != *products.Type {
119141
continue
120142
}
121143

122144
zoneConfigures := map[string]interface{}{}
123145
zoneConfigures["zone"] = zoneName
124146
zoneConfigures["version"] = *products.Version
147+
zoneConfigures["type_id"] = products.Type
148+
//this products sale out.
149+
if *products.Saleout {
150+
continue
151+
}
125152

126153
memSizes := make([]int64, 0, len(products.TotalSize))
127154

@@ -136,6 +163,27 @@ func dataSourceTencentRedisZoneConfigRead(d *schema.ResourceData, meta interface
136163
zoneConfigures["mem_sizes"] = memSizes
137164
zoneConfigures["type"] = REDIS_NAMES[*products.Type]
138165

166+
var redisShardNums []int64
167+
var redisReplicasNums []int64
168+
169+
for _, v := range products.ShardNum {
170+
int64Value, err := strconv.ParseInt(*v, 10, 64)
171+
if err != nil {
172+
return fmt.Errorf("api[DescribeRedisZoneConfig]return error `redis_shard_nums`,%s", err.Error())
173+
}
174+
redisShardNums = append(redisShardNums, int64Value)
175+
}
176+
zoneConfigures["redis_shard_nums"] = redisShardNums
177+
178+
for _, v := range products.ReplicaNum {
179+
int64Value, err := strconv.ParseInt(*v, 10, 64)
180+
if err != nil {
181+
return fmt.Errorf("api[DescribeRedisZoneConfig]return error `redis_replicas_nums`,%s", err.Error())
182+
}
183+
redisReplicasNums = append(redisReplicasNums, int64Value)
184+
}
185+
zoneConfigures["redis_replicas_nums"] = redisReplicasNums
186+
139187
allZonesConfigs = append(allZonesConfigs, zoneConfigures)
140188
}
141189
}
@@ -144,7 +192,12 @@ func dataSourceTencentRedisZoneConfigRead(d *schema.ResourceData, meta interface
144192
log.Printf("[CRITAL]%s provider set redis zoneConfigs fail, reason:%s\n ", logId, err.Error())
145193
return err
146194
}
147-
d.SetId("redis_zoneconfig" + region)
195+
196+
id := "redis_zoneconfig" + region
197+
if typeId != 0 {
198+
id += fmt.Sprintf("%d", typeId)
199+
}
200+
d.SetId(id)
148201

149202
if output, ok := d.GetOk("result_output_file"); ok && output.(string) != "" {
150203

tencentcloud/data_source_tc_redis_zone_config_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ func TestAccDataSourceRedisZoneConfig_basic(t *testing.T) {
2929
testAccCheckTencentCloudDataSourceID("data.tencentcloud_redis_zone_config.testWithRegion"),
3030
resource.TestCheckResourceAttrSet("data.tencentcloud_redis_zone_config.testWithRegion", "list.#"),
3131
resource.TestCheckResourceAttrSet("data.tencentcloud_redis_zone_config.testWithRegion", "list.0.zone"),
32-
resource.TestCheckResourceAttrSet("data.tencentcloud_redis_zone_config.testWithRegion", "list.0.type"),
32+
resource.TestCheckResourceAttrSet("data.tencentcloud_redis_zone_config.testWithRegion", "list.0.type_id"),
3333
resource.TestCheckResourceAttrSet("data.tencentcloud_redis_zone_config.testWithRegion", "list.0.version"),
3434
resource.TestCheckResourceAttrSet("data.tencentcloud_redis_zone_config.testWithRegion", "list.0.mem_sizes.#"),
35+
resource.TestCheckResourceAttrSet("data.tencentcloud_redis_zone_config.testWithRegion", "list.0.redis_shard_nums.#"),
36+
resource.TestCheckResourceAttrSet("data.tencentcloud_redis_zone_config.testWithRegion", "list.0.redis_replicas_nums.#"),
3537
),
3638
},
3739
},

tencentcloud/resource_tc_redis_backup_config_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ func testAccRedisBackupConfigUpdate() string {
9595
return fmt.Sprintf(`
9696
resource "tencentcloud_redis_instance" "redis_instance_test" {
9797
availability_zone = "ap-guangzhou-3"
98+
type_id = 2
9899
password = "test12345789"
99100
mem_size = 8192
100101
name = "terrform_test"
@@ -110,6 +111,7 @@ func testAccRedisBackupConfig() string {
110111
return fmt.Sprintf(`
111112
resource "tencentcloud_redis_instance" "redis_instance_test" {
112113
availability_zone = "ap-guangzhou-3"
114+
type_id = 2
113115
password = "test12345789"
114116
mem_size = 8192
115117
name = "terrform_test"

0 commit comments

Comments
 (0)