Skip to content
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
11 changes: 0 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,6 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.445 h1:Bh7XD0y
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.445/go.mod h1:jMDD351efCFpT1+KVFbcpu6SbmP4TYmp4qkoCfr63nQ=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.359 h1:cNKqelPgUxrJkLY0Azd2QHr/UMYOPPnmqs88clt2akk=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.359/go.mod h1:GlTYjlrf8EKEMu+Z2MXfaM2/nHGUBBF/huBBJqGyGwI=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.487 h1:/iZ931/+8b5IlTiOB9qGHUYMbQtbmSSlHaSZTtVjxF8=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.487/go.mod h1:ro6h0Lg0BKK+8ugBdomSCy0ItTxr3MANinnHcONluVQ=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.488 h1:A1seXWtMf2atBjSNYvcwxyDoFzCMgqyVnsxnWzhqJEA=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.488/go.mod h1:T8mL4dQLkPTL6VtVMeBYol3asSUS53ycP9PJf5Qp1GE=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dayu v1.0.335 h1:D8qrelkK5udv8RzJJIABMzItGIyaZoYnxEVeIsYqiNw=
Expand Down Expand Up @@ -556,12 +554,6 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdmq v1.0.268 h1:ez5lvK
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdmq v1.0.268/go.mod h1:fchXZhmqaYaG2c4wTCBTdnW6TFAtxl3D/P/yuuuLMfA=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.472 h1:9Jzrgx78+5XnZ8myNYjCYZn5ZF+tbSIpF6KWGgWr0uY=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.472/go.mod h1:ayIL2FNqk7HH5fPQrkWtYjgU4jL7if63f7x+yRwb4a0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.463 h1:QA9uGf9PjzitWIRFtf/NjsB4HjeuJdFi43RvTXNJQ5M=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.463/go.mod h1:D8kkDqqTJQe/qYhXsQkwD3ACxXPoAXwNR4JWe1rOQIs=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.480 h1:sP9z+Q7acbqElkzRfWbESLWycmpQHFKM+qIbeFyW24I=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.480/go.mod h1:XC6UD5UnzncR6O48Ya/FsIdkiPJT/jSKlUjolzpfayg=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.484 h1:7+1ltleuaAz/jI3NIapvOsl7wzu8UcJYjnh+d4UWAtc=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.484/go.mod h1:o3AyKFiYfjK7U/DsDzz1XmTRmXrTsemx/gx/630d+DE=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.486 h1:JRtQYtJB9sErV9tXY6xbrC3RmXNepBKd7aV3inxkUPs=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.486/go.mod h1:wtPJIKxQUR3KoL2KWAt/Qi8KMR4ayKHiOeVJ6sTSC4U=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke v1.0.480 h1:oZptW2Fo1pW8fKz/dv+RJLr2q8UC1qkqDqWs3rDgvQ8=
Expand Down Expand Up @@ -777,16 +769,13 @@ gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLks
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/cheggaaa/pb.v1 v1.0.27/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno=
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
144 changes: 144 additions & 0 deletions tencentcloud/data_source_tc_cynosdb_zone_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/*
Use this data source to query which instance types of Redis are available in a specific region.

Example Usage

```hcl
data "tencentcloud_cynosdb_zone_config" "foo" {
}
```
*/
package tencentcloud

import (
"context"
"fmt"
"log"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

func dataSourceTencentCynosdbZoneConfig() *schema.Resource {
return &schema.Resource{
Read: dataSourceTencentCynosdbZoneConfigRead,
Schema: map[string]*schema.Schema{
"result_output_file": {
Type: schema.TypeString,
Optional: true,
Description: "Used to save results.",
},

// Computed values
"list": {
Type: schema.TypeList,
Description: "A list of zone. Each element contains the following attributes:",
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cpu": {
Type: schema.TypeInt,
Computed: true,
Description: "Instance CPU, unit: core.",
},
"memory": {
Type: schema.TypeInt,
Computed: true,
Description: "Instance memory, unit: GB.",
},
"max_storage_size": {
Type: schema.TypeInt,
Computed: true,
Description: "The maximum available storage for the instance, unit GB.",
},
"min_storage_size": {
Type: schema.TypeInt,
Computed: true,
Description: "Minimum available storage of the instance, unit: GB.",
},
"machine_type": {
Type: schema.TypeString,
Computed: true,
Description: "Machine type.",
},
"max_io_bandwidth": {
Type: schema.TypeInt,
Computed: true,
Description: "Max io bandwidth.",
},
"zone_stock_infos": {
Type: schema.TypeList,
Computed: true,
Description: "Regional inventory information.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"zone": {
Type: schema.TypeString,
Computed: true,
Description: "Availability zone.",
},
"has_stock": {
Type: schema.TypeBool,
Computed: true,
Description: "Has stock.",
},
},
},
},
},
},
},
},
}
}

func dataSourceTencentCynosdbZoneConfigRead(d *schema.ResourceData, meta interface{}) error {
defer logElapsed("data_source.tencentcloud_cynosdb_zone_config.read")()

logId := getLogId(contextNil)
ctx := context.WithValue(context.TODO(), logIdKey, logId)

service := CynosdbService{client: meta.(*TencentCloudClient).apiV3Conn}
region := meta.(*TencentCloudClient).apiV3Conn.Region

instanceSpecSet, err := service.DescribeRedisZoneConfig(ctx)
if err != nil {
return fmt.Errorf("api[DescribeRedisZoneConfig]fail, return %s", err.Error())
}

result := make([]map[string]interface{}, 0)

for _, instanceSpec := range instanceSpecSet {
resultItem := make(map[string]interface{})
resultItem["cpu"] = *instanceSpec.Cpu
resultItem["memory"] = *instanceSpec.Memory
resultItem["max_storage_size"] = *instanceSpec.MaxStorageSize
resultItem["min_storage_size"] = *instanceSpec.MinStorageSize
resultItem["machine_type"] = *instanceSpec.MachineType
resultItem["max_io_bandwidth"] = *instanceSpec.MaxIoBandWidth
zoneStockInfos := make([]map[string]interface{}, 0)
for _, zoneStockInfoItem := range instanceSpec.ZoneStockInfos {
zoneStockInfo := make(map[string]interface{})
zoneStockInfo["zone"] = *zoneStockInfoItem.Zone
zoneStockInfo["has_stock"] = *zoneStockInfoItem.HasStock

zoneStockInfos = append(zoneStockInfos, zoneStockInfo)
}
resultItem["zone_stock_infos"] = zoneStockInfos
result = append(result, resultItem)
}

id := "cynosdb_zoneconfig_" + region
d.SetId(id)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个地方最好不要这样设置id,可以根据name组合下

d.Set("list", result)

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

if err := writeToFile(output.(string), result); err != nil {
log.Printf("[CRITAL]%s output file[%s] fail, reason[%s]\n",
logId, output.(string), err.Error())
return err
}

}
return nil
}
40 changes: 40 additions & 0 deletions tencentcloud/data_source_tc_cynosdb_zone_config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package tencentcloud

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccDataSourceCynosdbZoneConfig_basic(t *testing.T) {
t.Parallel()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceCynosdbZoneConfig(),
Check: resource.ComposeTestCheckFunc(
testAccCheckTencentCloudDataSourceID("data.tencentcloud_cynosdb_zone_config.test"),
resource.TestCheckResourceAttrSet("data.tencentcloud_cynosdb_zone_config.test", "list.#"),
resource.TestCheckResourceAttrSet("data.tencentcloud_cynosdb_zone_config.test", "list.0.cpu"),
resource.TestCheckResourceAttrSet("data.tencentcloud_cynosdb_zone_config.test", "list.0.memory"),
resource.TestCheckResourceAttrSet("data.tencentcloud_cynosdb_zone_config.test", "list.0.max_storage_size"),
resource.TestCheckResourceAttrSet("data.tencentcloud_cynosdb_zone_config.test", "list.0.min_storage_size"),
resource.TestCheckResourceAttrSet("data.tencentcloud_cynosdb_zone_config.test", "list.0.machine_type"),
resource.TestCheckResourceAttrSet("data.tencentcloud_cynosdb_zone_config.test", "list.0.max_io_bandwidth"),
resource.TestCheckResourceAttrSet("data.tencentcloud_cynosdb_zone_config.test", "list.0.zone_stock_infos.#"),
resource.TestCheckResourceAttrSet("data.tencentcloud_cynosdb_zone_config.test", "list.0.zone_stock_infos.0.zone"),
resource.TestCheckResourceAttrSet("data.tencentcloud_cynosdb_zone_config.test", "list.0.zone_stock_infos.0.has_stock"),
),
},
},
})
}

func testAccDataSourceCynosdbZoneConfig() string {
return `data "tencentcloud_cynosdb_zone_config" "test" {

}`
}
2 changes: 2 additions & 0 deletions tencentcloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ CynosDB
Data Source
tencentcloud_cynosdb_clusters
tencentcloud_cynosdb_instances
tencentcloud_cynosdb_zone_config

Resource
tencentcloud_cynosdb_cluster
Expand Down Expand Up @@ -934,6 +935,7 @@ func Provider() terraform.ResourceProvider {
"tencentcloud_audits": dataSourceTencentCloudAudits(),
"tencentcloud_cynosdb_clusters": dataSourceTencentCloudCynosdbClusters(),
"tencentcloud_cynosdb_instances": dataSourceTencentCloudCynosdbInstances(),
"tencentcloud_cynosdb_zone_config": dataSourceTencentCynosdbZoneConfig(),
"tencentcloud_vod_adaptive_dynamic_streaming_templates": dataSourceTencentCloudVodAdaptiveDynamicStreamingTemplates(),
"tencentcloud_vod_image_sprite_templates": dataSourceTencentCloudVodImageSpriteTemplates(),
"tencentcloud_vod_procedure_templates": dataSourceTencentCloudVodProcedureTemplates(),
Expand Down
22 changes: 22 additions & 0 deletions tencentcloud/service_tencentcloud_cynosdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,28 @@ type CynosdbService struct {
client *connectivity.TencentCloudClient
}

func (me *CynosdbService) DescribeRedisZoneConfig(ctx context.Context) (instanceSpecSet []*cynosdb.InstanceSpec, err error) {
logId := getLogId(ctx)
request := cynosdb.NewDescribeInstanceSpecsRequest()

request.DbType = helper.String("MYSQL")
request.IncludeZoneStocks = helper.Bool(true)

err = resource.Retry(readRetryTimeout, func() *resource.RetryError {
ratelimit.Check(request.GetAction())
response, e := me.client.UseCynosdbClient().DescribeInstanceSpecs(request)
if e != nil {
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]",
logId, request.GetAction(), request.ToJsonString(), e.Error())
return retryError(e)
}
instanceSpecSet = response.Response.InstanceSpecSet
return nil
})

return
}

func (me *CynosdbService) DescribeClusters(ctx context.Context, filters map[string]string) (clusters []*cynosdb.CynosdbCluster, errRet error) {
logId := getLogId(ctx)
request := cynosdb.NewDescribeClustersRequest()
Expand Down
42 changes: 42 additions & 0 deletions website/docs/d/cynosdb_zone_config.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
subcategory: "CynosDB"
layout: "tencentcloud"
page_title: "TencentCloud: tencentcloud_cynosdb_zone_config"
sidebar_current: "docs-tencentcloud-datasource-cynosdb_zone_config"
description: |-
Use this data source to query which instance types of Redis are available in a specific region.
---

# tencentcloud_cynosdb_zone_config

Use this data source to query which instance types of Redis are available in a specific region.

## Example Usage

```hcl
data "tencentcloud_cynosdb_zone_config" "foo" {
}
```

## Argument Reference

The following arguments are supported:

* `result_output_file` - (Optional, String) Used to save results.

## Attributes Reference

In addition to all arguments above, the following attributes are exported:

* `list` - A list of zone. Each element contains the following attributes:
* `cpu` - Instance CPU, unit: core.
* `machine_type` - Machine type.
* `max_io_bandwidth` - Max io bandwidth.
* `max_storage_size` - The maximum available storage for the instance, unit GB.
* `memory` - Instance memory, unit: GB.
* `min_storage_size` - Minimum available storage of the instance, unit: GB.
* `zone_stock_infos` - Regional inventory information.
* `has_stock` - Has stock.
* `zone` - Availability zone.


3 changes: 3 additions & 0 deletions website/tencentcloud.erb
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,9 @@
<li>
<a href="/docs/providers/tencentcloud/d/cynosdb_instances.html">tencentcloud_cynosdb_instances</a>
</li>
<li>
<a href="/docs/providers/tencentcloud/d/cynosdb_zone_config.html">tencentcloud_cynosdb_zone_config</a>
</li>
</ul>
</li>
<li>
Expand Down