Skip to content

redis type_id,redis_shard_num,redis_replicas_num supports. #416

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

Merged
merged 3 commits into from
May 21, 2020
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
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
## 1.34.0 (Unreleased)
## 1.33.1 (Unreleased)

ENHANCEMENTS:
Resource: `tencentcloud_redis_instance` add new argument `type_id`,`redis_shard_num`,`redis_replicas_num`
Data Source: `tencentcloud_redis_instances` add new argument `type_id`,`redis_shard_num`,`redis_replicas_num`
Data Source: `tencentcloud_redis_zone_config` add output argument `type_id` and new output argument `type_id`,`redis_shard_nums`,`redis_replicas_nums`

DEPRECATED:
* Resource: `tencentcloud_redis_instance`: optional argument `type` is no longer supported, replace by `type_id`.
* Data Source: `tencentcloud_redis_instances`: output argument `type` is no longer supported, replace by `type_id`
* Data Source: `tencentcloud_redis_zone_config`: output argument `type` is no longer supported, replace by `type_id`

## 1.33.0 (May 18, 2020)

FEATURES:
Expand Down
9 changes: 5 additions & 4 deletions tencentcloud/connectivity/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"
)

const ReqClient = "Terraform-v1.24.1"
const ReqClient = "Terraform-v1.33.1"

type LogRoundTripper struct {
}
Expand All @@ -27,19 +27,20 @@ func (me *LogRoundTripper) RoundTrip(request *http.Request) (response *http.Resp
if errRet != nil {
return
}

var headName = "X-TC-Action"
request.Header.Set("X-TC-RequestClient", ReqClient)
inBytes = []byte(fmt.Sprintf("%s, request: ", request.Header["X-TC-Action"]))
inBytes = []byte(fmt.Sprintf("%s, request: ", request.Header[headName]))
requestBody, errRet := ioutil.ReadAll(bodyReader)
if errRet != nil {
return
}
inBytes = append(inBytes, requestBody...)

headName = "X-TC-Region"
appendMessage := []byte(fmt.Sprintf(
", (host %+v, region:%+v)",
request.Header["Host"],
request.Header["X-TC-Region"],
request.Header[headName],
))

inBytes = append(inBytes, appendMessage...)
Expand Down
19 changes: 19 additions & 0 deletions tencentcloud/data_source_tc_redis_instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,27 @@ func dataSourceTencentRedisInstances() *schema.Resource {
Computed: true,
Description: "ID of the project to which a redis instance belongs.",
},
"type_id": {
Type: schema.TypeInt,
Computed: true,
Description: "Instance type. Refer to `data.tencentcloud_redis_zone_config.list.type_id` get available values.",
},
"type": {
Type: schema.TypeString,
Computed: true,
Deprecated: "It has been deprecated from version 1.33.1. Please use 'type_id' instead.",
Description: "Instance type. Available values: master_slave_redis, master_slave_ckv, cluster_ckv, cluster_redis and standalone_redis.",
},
"redis_shard_num": {
Type: schema.TypeInt,
Computed: true,
Description: "The number of instance shard.",
},
"redis_replicas_num": {
Type: schema.TypeInt,
Computed: true,
Description: "The number of instance copies.",
},
"mem_size": {
Type: schema.TypeInt,
Computed: true,
Expand Down Expand Up @@ -225,6 +241,9 @@ instanceLoop:
instanceDes["create_time"] = instance.CreateTime

instanceDes["tags"] = instance.Tags
instanceDes["redis_shard_num"] = instance.RedisShardNum
instanceDes["redis_replicas_num"] = instance.RedisReplicasNum
instanceDes["type_id"] = instance.TypeId

instanceList = append(instanceList, instanceDes)
}
Expand Down
2 changes: 1 addition & 1 deletion tencentcloud/data_source_tc_redis_instances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func testAccTencentCloudRedisInstancesDataSourceConfig() string {
return `
resource "tencentcloud_redis_instance" "redis_instance_test" {
availability_zone = "ap-guangzhou-3"
type = "master_slave_redis"
type_id = 2
password = "test12345789"
mem_size = 8192
name = "terraform_test"
Expand Down
67 changes: 60 additions & 7 deletions tencentcloud/data_source_tc_redis_zone_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ func dataSourceTencentRedisZoneConfig() *schema.Resource {
Optional: true,
Description: "Name of a region. If this value is not set, the current region getting from provider's configuration will be used.",
},
"type_id": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validateIntegerMin(2),
Description: "Instance type id.",
},
"result_output_file": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -48,9 +54,15 @@ func dataSourceTencentRedisZoneConfig() *schema.Resource {
Computed: true,
Description: "ID of available zone.",
},
"type_id": {
Type: schema.TypeInt,
Computed: true,
Description: "Instance type. Which redis type supports in this zone.",
},
"type": {
Type: schema.TypeString,
Computed: true,
Deprecated: "It has been deprecated from version 1.33.1. Please use 'type_id' instead.",
Description: "Instance type. Available values: master_slave_redis, master_slave_ckv, cluster_ckv, cluster_redis and standalone_redis.",
},
"version": {
Expand All @@ -64,6 +76,18 @@ func dataSourceTencentRedisZoneConfig() *schema.Resource {
Computed: true,
Description: "The memory volume of an available instance(in MB).",
},
"redis_shard_nums": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeInt},
Description: "The support numbers of instance shard.",
},
"redis_replicas_nums": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeInt},
Description: "The support numbers of instance copies.",
},
},
},
},
Expand All @@ -86,6 +110,8 @@ func dataSourceTencentRedisZoneConfigRead(d *schema.ResourceData, meta interface
log.Printf("[INFO]%s region is not set,so we use [%s] from env\n ", logId, region)
}

typeId := int64(d.Get("type_id").(int))

sellConfigures, err := service.DescribeRedisZoneConfig(ctx)
if err != nil {
return fmt.Errorf("api[DescribeRedisZoneConfig]fail, return %s", err.Error())
Expand All @@ -110,18 +136,19 @@ func dataSourceTencentRedisZoneConfigRead(d *schema.ResourceData, meta interface
if *products.PayMode != "0" {
continue
}
//this products sale out.
if *products.Saleout {
continue
}
//not support this type now .
if REDIS_NAMES[*products.Type] == "" {

if typeId != 0 && typeId != *products.Type {
continue
}

zoneConfigures := map[string]interface{}{}
zoneConfigures["zone"] = zoneName
zoneConfigures["version"] = *products.Version
zoneConfigures["type_id"] = products.Type
//this products sale out.
if *products.Saleout {
continue
}

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

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

var redisShardNums []int64
var redisReplicasNums []int64

for _, v := range products.ShardNum {
int64Value, err := strconv.ParseInt(*v, 10, 64)
if err != nil {
return fmt.Errorf("api[DescribeRedisZoneConfig]return error `redis_shard_nums`,%s", err.Error())
}
redisShardNums = append(redisShardNums, int64Value)
}
zoneConfigures["redis_shard_nums"] = redisShardNums

for _, v := range products.ReplicaNum {
int64Value, err := strconv.ParseInt(*v, 10, 64)
if err != nil {
return fmt.Errorf("api[DescribeRedisZoneConfig]return error `redis_replicas_nums`,%s", err.Error())
}
redisReplicasNums = append(redisReplicasNums, int64Value)
}
zoneConfigures["redis_replicas_nums"] = redisReplicasNums

allZonesConfigs = append(allZonesConfigs, zoneConfigures)
}
}
Expand All @@ -144,7 +192,12 @@ func dataSourceTencentRedisZoneConfigRead(d *schema.ResourceData, meta interface
log.Printf("[CRITAL]%s provider set redis zoneConfigs fail, reason:%s\n ", logId, err.Error())
return err
}
d.SetId("redis_zoneconfig" + region)

id := "redis_zoneconfig" + region
if typeId != 0 {
id += fmt.Sprintf("%d", typeId)
}
d.SetId(id)

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

Expand Down
4 changes: 3 additions & 1 deletion tencentcloud/data_source_tc_redis_zone_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ func TestAccDataSourceRedisZoneConfig_basic(t *testing.T) {
testAccCheckTencentCloudDataSourceID("data.tencentcloud_redis_zone_config.testWithRegion"),
resource.TestCheckResourceAttrSet("data.tencentcloud_redis_zone_config.testWithRegion", "list.#"),
resource.TestCheckResourceAttrSet("data.tencentcloud_redis_zone_config.testWithRegion", "list.0.zone"),
resource.TestCheckResourceAttrSet("data.tencentcloud_redis_zone_config.testWithRegion", "list.0.type"),
resource.TestCheckResourceAttrSet("data.tencentcloud_redis_zone_config.testWithRegion", "list.0.type_id"),
resource.TestCheckResourceAttrSet("data.tencentcloud_redis_zone_config.testWithRegion", "list.0.version"),
resource.TestCheckResourceAttrSet("data.tencentcloud_redis_zone_config.testWithRegion", "list.0.mem_sizes.#"),
resource.TestCheckResourceAttrSet("data.tencentcloud_redis_zone_config.testWithRegion", "list.0.redis_shard_nums.#"),
resource.TestCheckResourceAttrSet("data.tencentcloud_redis_zone_config.testWithRegion", "list.0.redis_replicas_nums.#"),
),
},
},
Expand Down
2 changes: 2 additions & 0 deletions tencentcloud/resource_tc_redis_backup_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func testAccRedisBackupConfigUpdate() string {
return fmt.Sprintf(`
resource "tencentcloud_redis_instance" "redis_instance_test" {
availability_zone = "ap-guangzhou-3"
type_id = 2
password = "test12345789"
mem_size = 8192
name = "terrform_test"
Expand All @@ -110,6 +111,7 @@ func testAccRedisBackupConfig() string {
return fmt.Sprintf(`
resource "tencentcloud_redis_instance" "redis_instance_test" {
availability_zone = "ap-guangzhou-3"
type_id = 2
password = "test12345789"
mem_size = 8192
name = "terrform_test"
Expand Down
Loading