Skip to content

Commit

Permalink
fix(cynosdb): [121024677] tencentcloud_cynosdb_cluster support `ins…
Browse files Browse the repository at this point in the history
…tance_init_infos` (#3015)

* add

* add
  • Loading branch information
SevenEarth authored Dec 13, 2024
1 parent 51cf3dc commit 7ce73bd
Show file tree
Hide file tree
Showing 13 changed files with 8,775 additions and 3,032 deletions.
3 changes: 3 additions & 0 deletions .changelog/3015.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_cynosdb_cluster: support `instance_init_infos`
```
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.1034
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.1033
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.1046
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1056
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1058
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.1014
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.762
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.692
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.1058
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dayu v1.0.335
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dbbrain v1.0.652
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dc v1.0.633
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1052 h1:RCs
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1052/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1056 h1:bOSZ7cOXvBe8MCBqDBTtpyKIqx9q6woxqIPK5M9FhNY=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1056/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1058 h1:VVv5rEFtGbxEB23V3gJO5pFHEXGlOh9duEWEtNm+w6c=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1058/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/controlcenter v1.0.993 h1:WlPgXldQCxt7qi5Xrc6j6zTrsXWzN5BcOGs7Irq7fwQ=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/controlcenter v1.0.993/go.mod h1:Z9U8zNtyuyKhjS0698wqsrG/kLx1TQ5CEixXBwVe7xY=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/csip v1.0.860 h1:F3esKBIT3HW9+7Gt8cVgf8X06VdGIczpgLBUECzSEzU=
Expand All @@ -946,6 +948,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.762 h1:2egy69S
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.762/go.mod h1:1XylIfNUbAzmNqi4XMhwcM3VhmUHdu1OYybOeaJ4sOw=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.692 h1:lD44AqXCzkraZiCeMjL7dZmvuyurpyQRKwPHA6Ux5To=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.692/go.mod h1:nH1mCLxOm21eqEYORMJ5pifOfHoupCIx8YwMOu9YW2c=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.1058 h1:qgni/qIuUYkc5THMbtyGNSNleoac5ffMeM5TErJ9bnA=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.1058/go.mod h1:HqoJMWKikraStfU3fj5HRK8linrtr4mfWF03GbOj2j8=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dasb v1.0.970 h1:qVIRHgG1twsqF4aVN/x2T2yMRfPpsZBTNefDkqzM06M=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dasb v1.0.970/go.mod h1:NJuuQD4z6vcnsZnC7Tvz2U9hElNS1wroc34UQbZvP2U=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dayu v1.0.335 h1:D8qrelkK5udv8RzJJIABMzItGIyaZoYnxEVeIsYqiNw=
Expand Down
64 changes: 64 additions & 0 deletions tencentcloud/services/cynosdb/extension_cynosdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,70 @@ func TencentCynosdbClusterBaseInfo() map[string]*schema.Schema {
ConflictsWith: []string{"prarm_template_id"},
Description: "The ID of the parameter template.",
},
"instance_init_infos": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Description: "Instance initialization configuration information, mainly used to select instances of different specifications when purchasing a cluster.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cpu": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
Description: "CPU of instance.",
},
"memory": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
Description: "Memory of instance.",
},
"instance_type": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Instance type. Value: `rw`, `ro`.",
},
"instance_count": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
Description: "Instance count. Range: [1, 15].",
},
"min_ro_count": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
Description: "Minimum number of Serverless instances. Range [1,15].",
},
"max_ro_count": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
Description: "Maximum number of Serverless instances. Range [1,15].",
},
"min_ro_cpu": {
Type: schema.TypeFloat,
Optional: true,
ForceNew: true,
Description: "Minimum Serverless Instance Specifications.",
},
"max_ro_cpu": {
Type: schema.TypeFloat,
Optional: true,
ForceNew: true,
Description: "Maximum Serverless Instance Specifications.",
},
"device_type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: "Instance machine type. Values: `common`, `exclusive`.",
},
},
},
},
"db_mode": {
Type: schema.TypeString,
Optional: true,
Expand Down
46 changes: 44 additions & 2 deletions tencentcloud/services/cynosdb/resource_tc_cynosdb_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,50 @@ func resourceTencentCloudCynosdbClusterCreate(d *schema.ResourceData, meta inter
request.ParamTemplateId = helper.IntInt64(v.(int))
}

if v, ok := d.GetOk("instance_init_infos"); ok {
for _, item := range v.([]interface{}) {
value := item.(map[string]interface{})
tmpInitInfo := cynosdb.InstanceInitInfo{}
if v, ok := value["cpu"]; ok {
tmpInitInfo.Cpu = helper.IntInt64(v.(int))
}

if v, ok := value["memory"]; ok {
tmpInitInfo.Memory = helper.IntInt64(v.(int))
}

if v, ok := value["instance_type"]; ok {
tmpInitInfo.InstanceType = helper.String(v.(string))
}

if v, ok := value["instance_count"]; ok {
tmpInitInfo.InstanceCount = helper.IntInt64(v.(int))
}

if v, ok := value["min_ro_count"].(int); ok && v != 0 {
tmpInitInfo.MinRoCount = helper.IntInt64(v)
}

if v, ok := value["max_ro_count"].(int); ok && v != 0 {
tmpInitInfo.MaxRoCount = helper.IntInt64(v)
}

if v, ok := value["min_ro_cpu"].(float64); ok && v != 0 {
tmpInitInfo.MinRoCpu = helper.Float64(v)
}

if v, ok := value["max_ro_cpu"].(float64); ok && v != 0 {
tmpInitInfo.MaxRoCpu = helper.Float64(v)
}

if v, ok := value["device_type"].(string); ok && v != "" {
tmpInitInfo.DeviceType = helper.String(v)
}

request.InstanceInitInfos = append(request.InstanceInitInfos, &tmpInitInfo)
}
}

isServerless := d.Get("db_mode").(string) == CYNOSDB_SERVERLESS
if v, ok := d.GetOk("instance_cpu_core"); ok {
request.Cpu = helper.IntInt64(v.(int))
Expand Down Expand Up @@ -158,8 +202,6 @@ func resourceTencentCloudCynosdbClusterCreate(d *schema.ResourceData, meta inter
}

request.PayMode = &chargeType
request.InstanceCount = helper.Int64(1)

var response *cynosdb.CreateClustersResponse
var err error
err = resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
Expand Down
18 changes: 16 additions & 2 deletions tencentcloud/services/cynosdb/resource_tc_cynosdb_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ resource "tencentcloud_cynosdb_cluster" "example" {
db_type = "MYSQL"
db_version = "5.7"
port = 3306
storage_limit = 1000
cluster_name = "tf-example"
password = "cynosDB@123"
instance_maintain_duration = 7200
Expand Down Expand Up @@ -80,6 +79,22 @@ resource "tencentcloud_cynosdb_cluster" "example" {
tencentcloud_security_group.example.id,
]
instance_init_infos {
cpu = 2
memory = 4
instance_type = "rw"
instance_count = 1
device_type = "common"
}
instance_init_infos {
cpu = 2
memory = 4
instance_type = "ro"
instance_count = 1
device_type = "exclusive"
}
tags = {
createBy = "terraform"
}
Expand Down Expand Up @@ -146,7 +161,6 @@ resource "tencentcloud_cynosdb_cluster" "example" {
db_type = "MYSQL"
db_version = "8.0"
port = 3306
storage_limit = 1000
cluster_name = "tf-example"
password = "cynosDB@123"
instance_maintain_duration = 7200
Expand Down
84 changes: 42 additions & 42 deletions tencentcloud/services/cynosdb/service_tencentcloud_cynosdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -1649,48 +1649,48 @@ func (me *CynosdbService) DescribeCynosdbRollbackTimeRangeByFilter(ctx context.C
return
}

func (me *CynosdbService) DescribeCynosdbRollbackTimeValidityByFilter(ctx context.Context, param map[string]interface{}) (rollbackTimeValidity *cynosdb.DescribeRollbackTimeValidityResponseParams, errRet error) {
var (
logId = tccommon.GetLogId(ctx)
request = cynosdb.NewDescribeRollbackTimeValidityRequest()
)

defer func() {
if errRet != nil {
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), errRet.Error())
}
}()

for k, v := range param {
if k == "ClusterId" {
request.ClusterId = v.(*string)
}
if k == "ExpectTime" {
request.ExpectTime = v.(*string)
}
if k == "ExpectTimeThresh" {
request.ExpectTimeThresh = v.(*uint64)
}
}

ratelimit.Check(request.GetAction())

response, err := me.client.UseCynosdbClient().DescribeRollbackTimeValidity(request)
if err != nil {
errRet = err
return
}

log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())

if response == nil {
return
}

rollbackTimeValidity = response.Response

return
}
// func (me *CynosdbService) DescribeCynosdbRollbackTimeValidityByFilter(ctx context.Context, param map[string]interface{}) (rollbackTimeValidity *cynosdb.DescribeRollbackTimeValidityResponseParams, errRet error) {
// var (
// logId = tccommon.GetLogId(ctx)
// request = cynosdb.NewDescribeRollbackTimeValidityRequest()
// )

// defer func() {
// if errRet != nil {
// log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), errRet.Error())
// }
// }()

// for k, v := range param {
// if k == "ClusterId" {
// request.ClusterId = v.(*string)
// }
// if k == "ExpectTime" {
// request.ExpectTime = v.(*string)
// }
// if k == "ExpectTimeThresh" {
// request.ExpectTimeThresh = v.(*uint64)
// }
// }

// ratelimit.Check(request.GetAction())

// response, err := me.client.UseCynosdbClient().DescribeRollbackTimeValidity(request)
// if err != nil {
// errRet = err
// return
// }

// log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())

// if response == nil {
// return
// }

// rollbackTimeValidity = response.Response

// return
// }

func (me *CynosdbService) DescribeCynosdbResourcePackageListByFilter(ctx context.Context, param map[string]interface{}) (resourcePackageList []*cynosdb.Package, errRet error) {
var (
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7ce73bd

Please sign in to comment.