Skip to content

Commit 14d7e52

Browse files
committed
feat
1 parent ccd1663 commit 14d7e52

12 files changed

+376
-209
lines changed

go.mod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,3 +356,7 @@ require (
356356
mvdan.cc/unparam v0.0.0-20221223090309-7455f1af531d // indirect
357357
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
358358
)
359+
require (
360+
github.com/hashicorp/terraform-plugin-sdk v1.7.0
361+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/billing v1.0.856
362+
)

tencentcloud/connectivity/client.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"strconv"
99
"time"
1010

11-
billing "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/billing/v20180709"
1211
csip "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/csip/v20221121"
1312

1413
dasb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dasb/v20191018"
@@ -104,10 +103,9 @@ import (
104103
vod "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vod/v20180717"
105104
vpc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312"
106105
ssl "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wss/v20180426"
107-
)
108106

109-
//internal version: replace import begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
110-
//internal version: replace import end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
107+
billing "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/billing/v20180709"
108+
)
111109

112110
const (
113111
PROVIDER_CVM_REQUEST_TIMEOUT = "TENCENTCLOUD_CVM_REQUEST_TIMEOUT"
@@ -204,8 +202,6 @@ type TencentCloudClient struct {
204202
cdwpgConn *cdwpg.Client
205203
csipConn *csip.Client
206204
billingConn *billing.Client
207-
//internal version: replace client begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
208-
//internal version: replace client end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
209205
}
210206

211207
// NewClientProfile returns a new ClientProfile
@@ -1562,9 +1558,6 @@ func (me *TencentCloudClient) UseCsipClient() *csip.Client {
15621558
return me.csipConn
15631559
}
15641560

1565-
//internal version: replace useClient begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
1566-
//internal version: replace useClient end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
1567-
15681561
func getEnvDefault(key string, defVal int) int {
15691562
val, ex := os.LookupEnv(key)
15701563
if !ex {

tencentcloud/internal/helper/transform.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,13 @@ func StrToBool(s string) (i bool) {
271271
return
272272
}
273273

274-
//internal version: replace boolStr begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
275-
//internal version: replace boolStr end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
274+
func BoolToStr(b bool) (s string) {
275+
s = "false"
276+
if b {
277+
s = "true"
278+
}
279+
return
280+
}
276281

277282
func StrListToStr(strList []*string) string {
278283
res := ""

tencentcloud/provider.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,13 @@ import (
114114
)
115115

116116
const (
117-
PROVIDER_SECRET_ID = "TENCENTCLOUD_SECRET_ID"
118-
PROVIDER_SECRET_KEY = "TENCENTCLOUD_SECRET_KEY"
119-
PROVIDER_SECURITY_TOKEN = "TENCENTCLOUD_SECURITY_TOKEN"
120-
PROVIDER_REGION = "TENCENTCLOUD_REGION"
121-
PROVIDER_PROTOCOL = "TENCENTCLOUD_PROTOCOL"
122-
PROVIDER_DOMAIN = "TENCENTCLOUD_DOMAIN"
123-
//internal version: replace envYunti begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
124-
//internal version: replace envYunti end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
117+
PROVIDER_SECRET_ID = "TENCENTCLOUD_SECRET_ID"
118+
PROVIDER_SECRET_KEY = "TENCENTCLOUD_SECRET_KEY"
119+
PROVIDER_SECURITY_TOKEN = "TENCENTCLOUD_SECURITY_TOKEN"
120+
PROVIDER_REGION = "TENCENTCLOUD_REGION"
121+
PROVIDER_PROTOCOL = "TENCENTCLOUD_PROTOCOL"
122+
PROVIDER_DOMAIN = "TENCENTCLOUD_DOMAIN"
123+
PROVIDER_ENABLE_YUNTI = "TENCENTCLOUD_ENABLE_YUNTI"
125124
PROVIDER_ASSUME_ROLE_ARN = "TENCENTCLOUD_ASSUME_ROLE_ARN"
126125
PROVIDER_ASSUME_ROLE_SESSION_NAME = "TENCENTCLOUD_ASSUME_ROLE_SESSION_NAME"
127126
PROVIDER_ASSUME_ROLE_SESSION_DURATION = "TENCENTCLOUD_ASSUME_ROLE_SESSION_DURATION"
@@ -191,8 +190,14 @@ func Provider() *schema.Provider {
191190
DefaultFunc: schema.EnvDefaultFunc(PROVIDER_DOMAIN, nil),
192191
Description: "The root domain of the API request, Default is `tencentcloudapi.com`.",
193192
},
194-
//internal version: replace enableBpass begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
195-
//internal version: replace enableBpass end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
193+
"enable_bpass": {
194+
Type: schema.TypeBool,
195+
Optional: true,
196+
Default: false,
197+
DefaultFunc: schema.EnvDefaultFunc(PROVIDER_ENABLE_YUNTI, nil),
198+
Description: "Use the yunti account or not, Default is `false`.",
199+
},
200+
196201
"assume_role": {
197202
Type: schema.TypeSet,
198203
Optional: true,

tencentcloud/services/cdb/resource_tc_mysql_instance.go

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@ import (
1515
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
1616

1717
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
18+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/services/billing"
1819
)
1920

20-
//internal version: replace import begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
21-
//internal version: replace import end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
22-
2321
var importMysqlFlag = false
2422

2523
const InWindow = 1
@@ -544,8 +542,9 @@ func mysqlCreateInstancePayByMonth(ctx context.Context, d *schema.ResourceData,
544542
request := cdb.NewCreateDBInstanceRequest()
545543
clientToken := helper.BuildToken()
546544
request.ClientToken = &clientToken
547-
//internal version: replace var begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
548-
//internal version: replace var end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
545+
client := meta.(tccommon.ProviderMeta).GetAPIV3Conn()
546+
billingService := billing.BillingService{Client: client}
547+
var instanceId string
549548

550549
payType, oldOk := d.GetOkExists("pay_type")
551550
var period int
@@ -576,8 +575,19 @@ func mysqlCreateInstancePayByMonth(ctx context.Context, d *schema.ResourceData,
576575
if inErr != nil {
577576
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
578577
logId, request.GetAction(), request.ToJsonString(), inErr.Error())
579-
//internal version: replace bpass begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
580-
//internal version: replace bpass end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
578+
// query deal by bpass
579+
regx := "dealNames:\\[\"(.*)\"\\]\\],"
580+
id, billErr := billingService.QueryDealByBpass(ctx, regx, inErr)
581+
if billErr != nil {
582+
log.Printf("[CRITAL]%s api[DescribeDeals] fail, reason[%s]\n", logId, billErr.Error())
583+
return resource.NonRetryableError(billErr)
584+
}
585+
// yunti prepaid user
586+
if id != nil {
587+
instanceId = *id
588+
return nil
589+
}
590+
581591
return tccommon.RetryError(inErr)
582592
}
583593

@@ -586,8 +596,7 @@ func mysqlCreateInstancePayByMonth(ctx context.Context, d *schema.ResourceData,
586596
}
587597

588598
response = r
589-
//internal version: replace instanceId begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
590-
//internal version: replace instanceId end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
599+
instanceId = *response.Response.InstanceIds[0]
591600
return nil
592601
})
593602

@@ -599,9 +608,7 @@ func mysqlCreateInstancePayByMonth(ctx context.Context, d *schema.ResourceData,
599608
if len(response.Response.InstanceIds) != 1 {
600609
return fmt.Errorf("mysql CreateDBInstance return len(InstanceIds) is not 1,but %d", len(response.Response.InstanceIds))
601610
}
602-
//internal version: replace setId begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
603-
d.SetId(*response.Response.InstanceIds[0])
604-
//internal version: replace setId end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
611+
d.SetId(instanceId)
605612
return nil
606613
}
607614

@@ -661,9 +668,9 @@ func resourceTencentCloudMysqlInstanceCreate(d *schema.ResourceData, meta interf
661668
logId := tccommon.GetLogId(tccommon.ContextNil)
662669
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
663670

664-
//internal version: replace mysqlServer begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
665-
mysqlService := MysqlService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
666-
//internal version: replace mysqlServer end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
671+
client := meta.(tccommon.ProviderMeta).GetAPIV3Conn()
672+
mysqlService := MysqlService{client: client}
673+
tagService := svctag.NewTagService(meta.(tccommon.ProviderMeta).GetAPIV3Conn())
667674

668675
payType := getPayType(d).(int)
669676

@@ -683,16 +690,22 @@ func resourceTencentCloudMysqlInstanceCreate(d *schema.ResourceData, meta interf
683690

684691
mysqlID := d.Id()
685692

686-
//internal version: replace setTag begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
693+
// set tag before query the instance
687694
if tags := helper.GetTags(d, "tags"); len(tags) > 0 {
688-
tcClient := meta.(tccommon.ProviderMeta).GetAPIV3Conn()
689-
tagService := svctag.NewTagService(tcClient)
690-
resourceName := tccommon.BuildTagResourceName("cdb", "instanceId", tcClient.Region, d.Id())
695+
resourceName := tccommon.BuildTagResourceName("cdb", "instanceId", client.Region, d.Id())
691696
if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil {
692697
return err
693698
}
699+
700+
// Wait the tags enabled
701+
err := tagService.WaitTagsEnable(ctx, "cdb", "instanceId", d.Id(), client.Region, tags)
702+
if err != nil {
703+
return err
704+
}
705+
// wait for describe enable
706+
time.Sleep(3 * time.Second)
694707
}
695-
//internal version: replace setTag end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
708+
696709
err := resource.Retry(7*tccommon.ReadRetryTimeout, func() *resource.RetryError {
697710
mysqlInfo, err := mysqlService.DescribeDBInstanceById(ctx, mysqlID)
698711
if err != nil {
@@ -1273,8 +1286,7 @@ func mysqlAllInstanceRoleUpdate(ctx context.Context, d *schema.ResourceData, met
12731286
if err != nil {
12741287
return err
12751288
}
1276-
//internal version: replace waitTag begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
1277-
//internal version: replace waitTag end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation.
1289+
// Wait the tags enabled err = tagService.WaitTagsEnable(ctx, "cdb", "instanceId", d.Id(), region, replaceTags) if err != nil { return err }
12781290
}
12791291

12801292
if d.HasChange("param_template_id") {

0 commit comments

Comments
 (0)