From e61e440f077a946e135096f2385d83c91699b570 Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Thu, 7 Dec 2023 18:34:54 +0800 Subject: [PATCH 01/45] feat: test --- .../resource_tc_postgresql_instance.go | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/tencentcloud/resource_tc_postgresql_instance.go b/tencentcloud/resource_tc_postgresql_instance.go index fa634225b9..72749f533f 100644 --- a/tencentcloud/resource_tc_postgresql_instance.go +++ b/tencentcloud/resource_tc_postgresql_instance.go @@ -304,12 +304,13 @@ func resourceTencentCloudPostgresqlInstanceCreate(d *schema.ResourceData, meta i logId := getLogId(contextNil) ctx := context.WithValue(context.TODO(), logIdKey, logId) - postgresqlService := PostgresqlService{client: meta.(*TencentCloudClient).apiV3Conn} + postgresqlService := PostgresqlService{client: meta.(*TencentCloudClient).apiV3Conn} //yunti mark client var ( - name = d.Get("name").(string) - dbVersion = d.Get("engine_version").(string) - payType = d.Get("charge_type").(string) + name = d.Get("name").(string) + dbVersion = d.Get("engine_version").(string) + payType = d.Get("charge_type").(string) + //yunti mark var projectId = d.Get("project_id").(int) subnetId = d.Get("subnet_id").(string) vpcId = d.Get("vpc_id").(string) @@ -465,6 +466,7 @@ func resourceTencentCloudPostgresqlInstanceCreate(d *schema.ResourceData, meta i voucherIds, ) if inErr != nil { + //yunti mark bypass return retryError(inErr) } return nil @@ -475,6 +477,8 @@ func resourceTencentCloudPostgresqlInstanceCreate(d *schema.ResourceData, meta i d.SetId(instanceId) + //yunti mark setTag + // check creation done err := resource.Retry(20*readRetryTimeout, func() *resource.RetryError { instance, has, err := postgresqlService.DescribePostgresqlInstanceById(ctx, instanceId) @@ -544,6 +548,7 @@ func resourceTencentCloudPostgresqlInstanceCreate(d *schema.ResourceData, meta i return checkErr } + //yunti mark move begin if tags := helper.GetTags(d, "tags"); len(tags) > 0 { tcClient := meta.(*TencentCloudClient).apiV3Conn tagService := &TagService{client: tcClient} @@ -552,6 +557,7 @@ func resourceTencentCloudPostgresqlInstanceCreate(d *schema.ResourceData, meta i return err } } + //yunti mark move end // set pg params paramEntrys := make(map[string]string) @@ -615,7 +621,7 @@ func resourceTencentCloudPostgresqlInstanceUpdate(d *schema.ResourceData, meta i logId := getLogId(contextNil) ctx := context.WithValue(context.TODO(), logIdKey, logId) - postgresqlService := PostgresqlService{client: meta.(*TencentCloudClient).apiV3Conn} + postgresqlService := PostgresqlService{client: meta.(*TencentCloudClient).apiV3Conn} //yunti mark clientUpdate instanceId := d.Id() d.Partial(true) @@ -1060,14 +1066,16 @@ func resourceTencentCloudPostgresqlInstanceUpdate(d *schema.ResourceData, meta i oldValue, newValue := d.GetChange("tags") replaceTags, deleteTags := diffTags(oldValue.(map[string]interface{}), newValue.(map[string]interface{})) + //yunti mark move begin tcClient := meta.(*TencentCloudClient).apiV3Conn tagService := &TagService{client: tcClient} + //yunti mark move end resourceName := BuildTagResourceName("postgres", "DBInstanceId", tcClient.Region, d.Id()) err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags) if err != nil { return err } - + //yunti mark waitTag } paramEntrys := make(map[string]string) if d.HasChange("max_standby_archive_delay") { From ff5d2d4837f8612a73ee24b24d7e6a55ed31e20c Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Thu, 7 Dec 2023 18:35:42 +0800 Subject: [PATCH 02/45] feat: test --- scripts/yunti-code.yaml | 292 ++++++++++++++++++ scripts/yunti-process-code.py | 80 +++++ scripts/yunti-process-code.sh | 0 tencentcloud/connectivity/client.go | 5 + tencentcloud/resource_tc_cynosdb_cluster.go | 11 +- .../resource_tc_elasticsearch_instance.go | 20 +- tencentcloud/resource_tc_mongodb_instance.go | 11 +- tencentcloud/resource_tc_mysql_instance.go | 20 +- 8 files changed, 411 insertions(+), 28 deletions(-) create mode 100644 scripts/yunti-code.yaml create mode 100644 scripts/yunti-process-code.py create mode 100644 scripts/yunti-process-code.sh diff --git a/scripts/yunti-code.yaml b/scripts/yunti-code.yaml new file mode 100644 index 0000000000..727d17f39e --- /dev/null +++ b/scripts/yunti-code.yaml @@ -0,0 +1,292 @@ +tencentcloud/connectivity/client.go: + import: "billing \"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/billing/v20180709\"" + client: "billingConn *billing.Client" + useClient: | + func (me *TencentCloudClient) UseBillingClient() *billing.Client { + if me.billingConn != nil { + return me.billingConn + } + + cpf := me.NewClientProfile(300) + me.billingConn, _ = billing.NewClient(me.Credential, me.Region, cpf) + me.billingConn.WithHttpTransport(&LogRoundTripper{}) + + return me.billingConn + } + +tencentcloud/extension_billing.go: + all: | + package tencentcloud + + var TRADE_RETRYABLE_ERROR = []string{ + "InternalError.TradeError", //mysql + "FailedOperation.PayFailed", //redis + } + + // deal status: https://cloud.tencent.com/document/product/555/19179 + + var DEAL_STATUS_CODE = []int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12} + + var DEAL_TERMINATE_STATUS_CODE = []int64{4, 5, 6, 7, 8, 9, 10, 11} + +tencentcloud/internal/helper/transform.go: + a: | + func BoolToStr(b bool) (s string) { + s = "false" + if b { + s = "true" + } + return + } +tencentcloud/provider.go: + a: " PROVIDER_ENABLE_YUNTI = \"TENCENTCLOUD_ENABLE_YUNTI\"" + b: | + "enable_bpass": { + Type: schema.TypeBool, + Optional: true, + Default: false, + DefaultFunc: schema.EnvDefaultFunc(PROVIDER_ENABLE_YUNTI, nil), + Description: "Use the yunti account or not, Default is `false`.", + }, +tencentcloud/resource_tc_cynosdb_cluster.go: + a: | + billingService = BillingService{client: client} + b: " var id string" + c: " var chargeTypeStr string" + d: " chargeTypeStr = v.(string)" + e: | + if chargeTypeStr == CYNOSDB_CHARGE_TYPE_PREPAID { + regx := "\"dealNames\":\\[\"(.*)\"\\]" + // query deal by bpass + resourceId, billErr := billingService.QueryDealByBpass(ctx, regx, err) + if billErr != nil { + log.Printf("[CRITAL]%s api[QueryDealByBpass] fail, reason[%s]\n", logId, billErr.Error()) + return resource.NonRetryableError(billErr) + } + // yunti prepaid user + if resourceId != nil { + id = *resourceId + return nil + } + } + f: | + // normal user + if !billingService.isYunTiAccount() { + id = *dealRes.Response.BillingResourceInfos[0].ClusterId + } + g: | + // set tag before query the instance + if tags := helper.GetTags(d, "tags"); len(tags) > 0 { + resourceName := BuildTagResourceName("cynosdb", "cluster", region, id) + if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil { + return err + } + + // Wait the tags enabled + err = tagService.waitTagsEnable(ctx, "cynosdb", "cluster", id, region, tags) + if err != nil { + return err + } + } + h: | + // Wait the tags enabled + err := tagService.waitTagsEnable(ctx, "cynosdb", "cluster", d.Id(), region, replaceTags) + if err != nil { + return err + } + +tencentcloud/resource_tc_elasticsearch_instance.go: + a: | + var ( + client = meta.(*TencentCloudClient).apiV3Conn + elasticsearchService = ElasticsearchService{client: client} + billingService = BillingService{client: client} + tagService = TagService{client: client} + region = client.Region + chargeType string + + request = es.NewCreateInstanceRequest() + ) + b: "chargeType = v.(string)" + c: | + var tags map[string]string + if tags = helper.GetTags(d, "tags"); len(tags) > 0 { + if billingService.isYunTiAccount() { + request.TagList = make([]*es.TagInfo, 0, len(tags)) + for k, v := range tags { + tagInfo := &es.TagInfo{ + TagKey: helper.String(k), + TagValue: helper.String(v), + } + request.TagList = append(request.TagList, tagInfo) + } + } + } + d: | + if chargeType == ES_CHARGE_TYPE_PREPAID { + regx := "\"dealNames\":\\[\"(.*)\"\\]" + // query deal by bpass + id, billErr := billingService.QueryDealByBpass(ctx, regx, err) + if billErr != nil { + log.Printf("[CRITAL]%s api[QueryDealByBpass] fail, reason[%s]\n", logId, billErr.Error()) + return resource.NonRetryableError(billErr) + } + // yunti prepaid user + if id != nil { + instanceId = *id + return nil + } + } + e: | + // set tag before query the instance + if len(tags) > 0 { + // resourceName := fmt.Sprintf("qcs::es:%s:uin/:instance/%s", region, instanceId) + resourceName := BuildTagResourceName("es", "instance", region, d.Id()) + if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil { + return err + } + + // Wait the tags enabled + err = tagService.waitTagsEnable(ctx, "es", "instance", d.Id(), region, tags) + if err != nil { + return err + } + } + f: | + // resourceName := fmt.Sprintf("qcs::es:%s:uin/:instance/%s", region, instanceId) + resourceName := BuildTagResourceName("es", "instance", region, d.Id()) + if err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags); err != nil { + return err + } + + // Wait the tags enabled + err := tagService.waitTagsEnable(ctx, "es", "instance", d.Id(), region, replaceTags) + +tencentcloud/resource_tc_mongodb_instance.go: + import: " sdkErrors \"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors\"" + bpass: | + // query deal by bpass + e, ok := err.(*sdkErrors.TencentCloudSDKError) + log.Printf("[DEBUG]%s query deal for PREPAID user, msg:[%s] \n", logId, e.Error()) + + if ok && IsContains("InvalidParameterValue.InvalidTradeOperation", e.Code) { + // yunti prepaid user + return retryError(fmt.Errorf("[DEBUG] wait pass the bpass for yunti prepaid user, retry... error msg:[%s]", e.Message)) + } + + // if id != nil { + // // yunti prepaid user + // resourceId = *id + // return nil + // } + setTag: | + // set tag before query the instance + if tags := helper.GetTags(d, "tags"); len(tags) > 0 { + resourceName := BuildTagResourceName("mongodb", "instance", region, instanceId) + if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil { + return err + } + + // Wait the tags enabled + err := tagService.waitTagsEnable(ctx, "mongodb", "instance", instanceId, region, tags) + if err != nil { + return err + } + } + +tencentcloud/resource_tc_mysql_instance.go: + var: | + client := meta.(*TencentCloudClient).apiV3Conn + billingService := BillingService{client: client} + var instanceId string + bpass: | + // query deal by bpass + regx := "dealNames:\\[\"(.*)\"\\]\\]," + id, billErr := billingService.QueryDealByBpass(ctx, regx, inErr) + if billErr != nil { + log.Printf("[CRITAL]%s api[DescribeDeals] fail, reason[%s]\n", logId, billErr.Error()) + return resource.NonRetryableError(billErr) + } + // yunti prepaid user + if id != nil { + instanceId = *id + return nil + } + instanceId: "instanceId = *response.Response.InstanceIds[0]" + setId: "d.SetId(instanceId)" + mysqlServer: | + client := meta.(*TencentCloudClient).apiV3Conn + mysqlService := MysqlService{client: client} + tagService := &TagService{client: client} + setTag: | + // set tag before query the instance + if tags := helper.GetTags(d, "tags"); len(tags) > 0 { + resourceName := BuildTagResourceName("cdb", "instanceId", client.Region, d.Id()) + if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil { + return err + } + + // Wait the tags enabled + err := tagService.waitTagsEnable(ctx, "cdb", "instanceId", d.Id(), client.Region, tags) + if err != nil { + return err + } + // wait for describe enable + time.Sleep(3 * time.Second) + } + waitTag: + // Wait the tags enabled + err = tagService.waitTagsEnable(ctx, "cdb", "instanceId", d.Id(), region, replaceTags) + if err != nil { + return err + } + +tencentcloud/resource_tc_postgresql_instance.go: + clientCreate: | + client := meta.(*TencentCloudClient).apiV3Conn + postgresqlService := PostgresqlService{client: client} + tagService := TagService{client: client} + billingService := BillingService{client: client} + region := client.Region + var: "chargeType = d.Get(\"charge_type\").(string)" + bypass: | + log.Printf("[CRITAL]%s api[%s] fail, reason:%s", logId, "CreatePostgresqlInstance", inErr.Error()) + + if chargeType == COMMON_PAYTYPE_PREPAID { + regx := "\"dealNames\":\\[\"(.*)\"\\]" + // query deal by bpass + id, billErr := billingService.QueryDealByBpass(ctx, regx, inErr) + if billErr != nil { + log.Printf("[CRITAL]%s api[QueryDealByBpass] fail, reason[%s]\n", logId, billErr.Error()) + return resource.NonRetryableError(billErr) + } + // yunti prepaid user + if id != nil { + instanceId = *id + return nil + } + } + setTag: | + // set tag before query the instance + if tags := helper.GetTags(d, "tags"); len(tags) > 0 { + resourceName := BuildTagResourceName("postgres", "DBInstanceId", region, d.Id()) + if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil { + return err + } + + // Wait the tags enabled + err := tagService.waitTagsEnable(ctx, "postgres", "DBInstanceId", d.Id(), region, tags) + if err != nil { + return err + } + } + clientUpdate: | + cClient := meta.(*TencentCloudClient).apiV3Conn + tagService := &TagService{client: tcClient} + postgresqlService := PostgresqlService{client: tcClient} + waitTag: | + // Wait the tags enabled + err = tagService.waitTagsEnable(ctx, "postgres", "DBInstanceId", d.Id(), tcClient.Region, replaceTags) + if err != nil { + return err + } \ No newline at end of file diff --git a/scripts/yunti-process-code.py b/scripts/yunti-process-code.py new file mode 100644 index 0000000000..0b42d780be --- /dev/null +++ b/scripts/yunti-process-code.py @@ -0,0 +1,80 @@ +import yaml +import json +import re + + +# 处理每个文件 +def replace(dictionary): + for file_name, content in dictionary.items(): + # 读取文件内容 + if file_name=="tencentcloud/extension_billing.go": + with open("../"+file_name, "w") as f: + f.write(content["all"]) + continue + + with open("../"+file_name, "r") as f: + file_content = f.readlines() + + # 修改文件内容 + new_file_content = [] + for line in file_content: + match = re.search(r"//yunti mark (\w+)", line) + if match: + index = match.group(1) + if index =="move": + continue + if index in content: + line = content[index] +"\n" + new_file_content.append(line) + + # 写入修改后的文件内容 + with open("../"+file_name, "w") as f: + f.writelines(new_file_content) + +def move(dictionary): + start_marker = "//yunti mark move begin" + end_marker = "//yunti mark move end" + + for file_name, _ in dictionary.items(): + if file_name=="tencentcloud/extension_billing.go": + continue + # 打开文件并读取内容 + with open("../"+file_name, "r") as file: + lines = file.readlines() + + modified_lines = [] + inside_code_block = False + # 遍历文件内容的每一行 + for line in lines: + if start_marker in line: + inside_code_block = True + elif end_marker in line: + inside_code_block = False + elif not inside_code_block: + modified_lines.append(line) + + # 将修改后的内容写回文件 + with open("../"+file_name, "w") as file: + file.writelines(modified_lines) + + print("代码已成功删除。") + +def run(): + # 读取YAML文件 + yaml_file = "yunti-code.yaml" + + # 将YAML文件转换为JSON + with open(yaml_file, "r") as f: + yaml_data = yaml.safe_load(f) + json_data = json.dumps(yaml_data) + + # 将JSON转换为字典 + dictionary = json.loads(json_data) + + # 替换 + # replace(dictionary) + + # Move + move(dictionary) + +run() \ No newline at end of file diff --git a/scripts/yunti-process-code.sh b/scripts/yunti-process-code.sh new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tencentcloud/connectivity/client.go b/tencentcloud/connectivity/client.go index 960a95b363..86fe64bfa8 100644 --- a/tencentcloud/connectivity/client.go +++ b/tencentcloud/connectivity/client.go @@ -103,6 +103,8 @@ import ( ssl "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wss/v20180426" ) +//yunti mark import + const ( PROVIDER_CVM_REQUEST_TIMEOUT = "TENCENTCLOUD_CVM_REQUEST_TIMEOUT" PROVIDER_CBS_REQUEST_TIMEOUT = "TENCENTCLOUD_CBS_REQUEST_TIMEOUT" @@ -196,6 +198,7 @@ type TencentCloudClient struct { trocketConn *trocket.Client biConn *bi.Client cdwpgConn *cdwpg.Client + //yunti mark client } // NewClientProfile returns a new ClientProfile @@ -1371,6 +1374,8 @@ func (me *TencentCloudClient) UseCdwpgClient() *cdwpg.Client { return me.cdwpgConn } +//yunti mark useClient + func getEnvDefault(key string, defVal int) int { val, ex := os.LookupEnv(key) if !ex { diff --git a/tencentcloud/resource_tc_cynosdb_cluster.go b/tencentcloud/resource_tc_cynosdb_cluster.go index 3df6b57e3a..07108fda09 100644 --- a/tencentcloud/resource_tc_cynosdb_cluster.go +++ b/tencentcloud/resource_tc_cynosdb_cluster.go @@ -39,10 +39,10 @@ func resourceTencentCloudCynosdbClusterCreate(d *schema.ResourceData, meta inter cynosdbService = CynosdbService{client: client} tagService = TagService{client: client} region = client.Region - + //yunti mark a request = cynosdb.NewCreateClustersRequest() ) - + //yunti mark b request.ProjectId = helper.IntInt64(d.Get("project_id").(int)) request.Zone = helper.String(d.Get("available_zone").(string)) request.VpcId = helper.String(d.Get("vpc_id").(string)) @@ -115,7 +115,9 @@ func resourceTencentCloudCynosdbClusterCreate(d *schema.ResourceData, meta inter } var chargeType int64 = 0 + //yunti mark c if v, ok := d.GetOk("charge_type"); ok { + //yunti mark d if v == CYNOSDB_CHARGE_TYPE_PREPAID { chargeType = 1 if vv, ok := d.GetOk("prepaid_period"); ok { @@ -143,6 +145,7 @@ func resourceTencentCloudCynosdbClusterCreate(d *schema.ResourceData, meta inter } } log.Printf("[CRITAL]%s api[%s] fail, reason:%s", logId, request.GetAction(), err.Error()) + //yunti mark e return retryError(err) } return nil @@ -180,9 +183,10 @@ func resourceTencentCloudCynosdbClusterCreate(d *schema.ResourceData, meta inter return fmt.Errorf("cynosdb cluster id count isn't 1") } - id := *dealRes.Response.BillingResourceInfos[0].ClusterId + id := *dealRes.Response.BillingResourceInfos[0].ClusterId //yunti mark f d.SetId(id) + //yunti mark g _, _, has, err := cynosdbService.DescribeClusterById(ctx, id) if err != nil { return err @@ -638,6 +642,7 @@ func resourceTencentCloudCynosdbClusterUpdate(d *schema.ResourceData, meta inter return err } + //yunti mark h } // update sg diff --git a/tencentcloud/resource_tc_elasticsearch_instance.go b/tencentcloud/resource_tc_elasticsearch_instance.go index 42528639f8..a94b3cd8c3 100755 --- a/tencentcloud/resource_tc_elasticsearch_instance.go +++ b/tencentcloud/resource_tc_elasticsearch_instance.go @@ -1,3 +1,6 @@ +//go:build ignore +// +build ignore + package tencentcloud import ( @@ -264,7 +267,7 @@ func resourceTencentCloudElasticsearchInstanceCreate(d *schema.ResourceData, met elasticsearchService := ElasticsearchService{ client: meta.(*TencentCloudClient).apiV3Conn, } - + //yunti mark a request := es.NewCreateInstanceRequest() request.Zone = helper.String(d.Get("availability_zone").(string)) request.EsVersion = helper.String(d.Get("version").(string)) @@ -275,7 +278,7 @@ func resourceTencentCloudElasticsearchInstanceCreate(d *schema.ResourceData, met request.InstanceName = helper.String(v.(string)) } if v, ok := d.GetOk("charge_type"); ok { - chargeType := v.(string) + chargeType := v.(string) //yunti mark b request.ChargeType = &chargeType if chargeType == ES_CHARGE_TYPE_PREPAID { if v, ok := d.GetOk("charge_period"); ok { @@ -355,7 +358,7 @@ func resourceTencentCloudElasticsearchInstanceCreate(d *schema.ResourceData, met request.NodeInfoList = append(request.NodeInfoList, &info) } } - + //yunti mark c instanceId := "" err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { ratelimit.Check(request.GetAction()) @@ -363,6 +366,7 @@ func resourceTencentCloudElasticsearchInstanceCreate(d *schema.ResourceData, met if err != nil { log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), err.Error()) + //yunti mark d return retryError(err) } instanceId = *response.Response.InstanceId @@ -373,6 +377,8 @@ func resourceTencentCloudElasticsearchInstanceCreate(d *schema.ResourceData, met } d.SetId(instanceId) + //yunti mark e + instanceEmptyRetries := 5 err = resource.Retry(15*readRetryTimeout, func() *resource.RetryError { instance, errRet := elasticsearchService.DescribeInstanceById(ctx, instanceId) @@ -706,6 +712,7 @@ func resourceTencentCloudElasticsearchInstanceUpdate(d *schema.ResourceData, met return err } } + if d.HasChange("tags") { oldInterface, newInterface := d.GetChange("tags") replaceTags, deleteTags := diffTags(oldInterface.(map[string]interface{}), newInterface.(map[string]interface{})) @@ -713,8 +720,11 @@ func resourceTencentCloudElasticsearchInstanceUpdate(d *schema.ResourceData, met client: meta.(*TencentCloudClient).apiV3Conn, } region := meta.(*TencentCloudClient).apiV3Conn.Region - resourceName := fmt.Sprintf("qcs::es:%s:uin/:instance/%s", region, instanceId) - err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags) + + resourceName := fmt.Sprintf("qcs::es:%s:uin/:instance/%s", region, instanceId) //yunti mark move + err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags) //yunti mark move + + //yunti mark f if err != nil { return err } diff --git a/tencentcloud/resource_tc_mongodb_instance.go b/tencentcloud/resource_tc_mongodb_instance.go index f091a1f1bc..aba927e9fe 100644 --- a/tencentcloud/resource_tc_mongodb_instance.go +++ b/tencentcloud/resource_tc_mongodb_instance.go @@ -14,6 +14,8 @@ import ( "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/ratelimit" ) +//yunti mark import + func resourceTencentCloudMongodbInstance() *schema.Resource { mongodbInstanceInfo := map[string]*schema.Schema{ "standby_instance_list": { @@ -218,6 +220,7 @@ func mongodbCreateInstanceByMonth(ctx context.Context, d *schema.ResourceData, m response, err = meta.(*TencentCloudClient).apiV3Conn.UseMongodbClient().CreateDBInstance(request) if err != nil { log.Printf("[CRITAL]%s api[%s] fail, reason:%s", logId, request.GetAction(), err.Error()) + //yunti mark bpass return retryError(err) } return nil @@ -263,6 +266,7 @@ func resourceTencentCloudMongodbInstanceCreate(d *schema.ResourceData, meta inte instanceId := d.Id() + //yunti mark setTag _, has, err := mongodbService.DescribeInstanceById(ctx, instanceId) if err != nil { return err @@ -286,13 +290,6 @@ func resourceTencentCloudMongodbInstanceCreate(d *schema.ResourceData, meta inte return fmt.Errorf("[CRITAL]%s creating mongodb instance failed, instance doesn't exist", logId) } - if tags := helper.GetTags(d, "tags"); len(tags) > 0 { - resourceName := BuildTagResourceName("mongodb", "instance", region, instanceId) - if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil { - return err - } - } - return resourceTencentCloudMongodbInstanceRead(d, meta) } diff --git a/tencentcloud/resource_tc_mysql_instance.go b/tencentcloud/resource_tc_mysql_instance.go index a493273500..4ea42c934b 100644 --- a/tencentcloud/resource_tc_mysql_instance.go +++ b/tencentcloud/resource_tc_mysql_instance.go @@ -520,6 +520,7 @@ func mysqlCreateInstancePayByMonth(ctx context.Context, d *schema.ResourceData, request := cdb.NewCreateDBInstanceRequest() clientToken := helper.BuildToken() request.ClientToken = &clientToken + //yunti mark var payType, oldOk := d.GetOkExists("pay_type") var period int @@ -548,6 +549,7 @@ func mysqlCreateInstancePayByMonth(ctx context.Context, d *schema.ResourceData, if inErr != nil { log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), inErr.Error()) + //yunti mark bpass return retryError(inErr) } @@ -556,7 +558,7 @@ func mysqlCreateInstancePayByMonth(ctx context.Context, d *schema.ResourceData, } response = r - + //yunti mark instanceId return nil }) @@ -568,7 +570,7 @@ func mysqlCreateInstancePayByMonth(ctx context.Context, d *schema.ResourceData, if len(response.Response.InstanceIds) != 1 { return fmt.Errorf("mysql CreateDBInstance return len(InstanceIds) is not 1,but %d", len(response.Response.InstanceIds)) } - d.SetId(*response.Response.InstanceIds[0]) + d.SetId(*response.Response.InstanceIds[0]) //yunti mark setId return nil } @@ -626,7 +628,7 @@ func resourceTencentCloudMysqlInstanceCreate(d *schema.ResourceData, meta interf logId := getLogId(contextNil) ctx := context.WithValue(context.TODO(), logIdKey, logId) - mysqlService := MysqlService{client: meta.(*TencentCloudClient).apiV3Conn} + mysqlService := MysqlService{client: meta.(*TencentCloudClient).apiV3Conn} //yunti mark mysqlServer payType := getPayType(d).(int) @@ -646,15 +648,7 @@ func resourceTencentCloudMysqlInstanceCreate(d *schema.ResourceData, meta interf mysqlID := d.Id() - if tags := helper.GetTags(d, "tags"); len(tags) > 0 { - tcClient := meta.(*TencentCloudClient).apiV3Conn - tagService := &TagService{client: tcClient} - resourceName := BuildTagResourceName("cdb", "instanceId", tcClient.Region, d.Id()) - if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil { - return err - } - } - + //yunti mark setTag err := resource.Retry(7*readRetryTimeout, func() *resource.RetryError { mysqlInfo, err := mysqlService.DescribeDBInstanceById(ctx, mysqlID) if err != nil { @@ -1158,7 +1152,7 @@ func mysqlAllInstanceRoleUpdate(ctx context.Context, d *schema.ResourceData, met if err != nil { return err } - + //yunti mark waitTag } if d.HasChange("param_template_id") { From 24034555d7071238800a15abc0511a427b6046eb Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Thu, 7 Dec 2023 18:40:31 +0800 Subject: [PATCH 03/45] feat: test --- tencentcloud/resource_tc_postgresql_instance.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tencentcloud/resource_tc_postgresql_instance.go b/tencentcloud/resource_tc_postgresql_instance.go index 72749f533f..3e4dfc34e9 100644 --- a/tencentcloud/resource_tc_postgresql_instance.go +++ b/tencentcloud/resource_tc_postgresql_instance.go @@ -304,7 +304,7 @@ func resourceTencentCloudPostgresqlInstanceCreate(d *schema.ResourceData, meta i logId := getLogId(contextNil) ctx := context.WithValue(context.TODO(), logIdKey, logId) - postgresqlService := PostgresqlService{client: meta.(*TencentCloudClient).apiV3Conn} //yunti mark client + postgresqlService := PostgresqlService{client: meta.(*TencentCloudClient).apiV3Conn} //yunti mark clientCreate var ( name = d.Get("name").(string) From 6481d96a559a294345e88268e34a174ad525eba3 Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Thu, 7 Dec 2023 19:54:42 +0800 Subject: [PATCH 04/45] feat: test --- scripts/yunti-code.yaml | 40 +++++++++---------- scripts/yunti-process-code.py | 7 ++-- tencentcloud/connectivity/client.go | 16 ++++++-- tencentcloud/internal/helper/transform.go | 2 + tencentcloud/provider.go | 14 ++++--- tencentcloud/resource_tc_cynosdb_cluster.go | 16 ++++---- .../resource_tc_elasticsearch_instance.go | 20 ++++++---- tencentcloud/resource_tc_mongodb_instance.go | 9 ++++- 8 files changed, 74 insertions(+), 50 deletions(-) diff --git a/scripts/yunti-code.yaml b/scripts/yunti-code.yaml index 727d17f39e..7779eacc3e 100644 --- a/scripts/yunti-code.yaml +++ b/scripts/yunti-code.yaml @@ -1,5 +1,5 @@ tencentcloud/connectivity/client.go: - import: "billing \"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/billing/v20180709\"" + import: "import billing \"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/billing/v20180709\"" client: "billingConn *billing.Client" useClient: | func (me *TencentCloudClient) UseBillingClient() *billing.Client { @@ -30,7 +30,7 @@ tencentcloud/extension_billing.go: var DEAL_TERMINATE_STATUS_CODE = []int64{4, 5, 6, 7, 8, 9, 10, 11} tencentcloud/internal/helper/transform.go: - a: | + boolStr: | func BoolToStr(b bool) (s string) { s = "false" if b { @@ -39,8 +39,8 @@ tencentcloud/internal/helper/transform.go: return } tencentcloud/provider.go: - a: " PROVIDER_ENABLE_YUNTI = \"TENCENTCLOUD_ENABLE_YUNTI\"" - b: | + envYunti: " PROVIDER_ENABLE_YUNTI = \"TENCENTCLOUD_ENABLE_YUNTI\"" + enableBpass: | "enable_bpass": { Type: schema.TypeBool, Optional: true, @@ -49,12 +49,12 @@ tencentcloud/provider.go: Description: "Use the yunti account or not, Default is `false`.", }, tencentcloud/resource_tc_cynosdb_cluster.go: - a: | + client: | billingService = BillingService{client: client} - b: " var id string" - c: " var chargeTypeStr string" - d: " chargeTypeStr = v.(string)" - e: | + varId: " var id string" + varCharge: " var chargeTypeStr string" + strCharge: " chargeTypeStr = v.(string)" + byPass: | if chargeTypeStr == CYNOSDB_CHARGE_TYPE_PREPAID { regx := "\"dealNames\":\\[\"(.*)\"\\]" // query deal by bpass @@ -69,12 +69,12 @@ tencentcloud/resource_tc_cynosdb_cluster.go: return nil } } - f: | + normal: | // normal user if !billingService.isYunTiAccount() { id = *dealRes.Response.BillingResourceInfos[0].ClusterId } - g: | + setTag: | // set tag before query the instance if tags := helper.GetTags(d, "tags"); len(tags) > 0 { resourceName := BuildTagResourceName("cynosdb", "cluster", region, id) @@ -88,7 +88,7 @@ tencentcloud/resource_tc_cynosdb_cluster.go: return err } } - h: | + waitTag: | // Wait the tags enabled err := tagService.waitTagsEnable(ctx, "cynosdb", "cluster", d.Id(), region, replaceTags) if err != nil { @@ -96,7 +96,7 @@ tencentcloud/resource_tc_cynosdb_cluster.go: } tencentcloud/resource_tc_elasticsearch_instance.go: - a: | + var: | var ( client = meta.(*TencentCloudClient).apiV3Conn elasticsearchService = ElasticsearchService{client: client} @@ -107,8 +107,8 @@ tencentcloud/resource_tc_elasticsearch_instance.go: request = es.NewCreateInstanceRequest() ) - b: "chargeType = v.(string)" - c: | + strCharge: "chargeType = v.(string)" + reqTag: | var tags map[string]string if tags = helper.GetTags(d, "tags"); len(tags) > 0 { if billingService.isYunTiAccount() { @@ -122,7 +122,7 @@ tencentcloud/resource_tc_elasticsearch_instance.go: } } } - d: | + bypass: | if chargeType == ES_CHARGE_TYPE_PREPAID { regx := "\"dealNames\":\\[\"(.*)\"\\]" // query deal by bpass @@ -137,7 +137,7 @@ tencentcloud/resource_tc_elasticsearch_instance.go: return nil } } - e: | + setTag: | // set tag before query the instance if len(tags) > 0 { // resourceName := fmt.Sprintf("qcs::es:%s:uin/:instance/%s", region, instanceId) @@ -152,7 +152,7 @@ tencentcloud/resource_tc_elasticsearch_instance.go: return err } } - f: | + waitTag: | // resourceName := fmt.Sprintf("qcs::es:%s:uin/:instance/%s", region, instanceId) resourceName := BuildTagResourceName("es", "instance", region, d.Id()) if err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags); err != nil { @@ -163,7 +163,7 @@ tencentcloud/resource_tc_elasticsearch_instance.go: err := tagService.waitTagsEnable(ctx, "es", "instance", d.Id(), region, replaceTags) tencentcloud/resource_tc_mongodb_instance.go: - import: " sdkErrors \"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors\"" + import: "import sdkErrors \"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors\"" bpass: | // query deal by bpass e, ok := err.(*sdkErrors.TencentCloudSDKError) @@ -281,7 +281,7 @@ tencentcloud/resource_tc_postgresql_instance.go: } } clientUpdate: | - cClient := meta.(*TencentCloudClient).apiV3Conn + tcClient := meta.(*TencentCloudClient).apiV3Conn tagService := &TagService{client: tcClient} postgresqlService := PostgresqlService{client: tcClient} waitTag: | diff --git a/scripts/yunti-process-code.py b/scripts/yunti-process-code.py index 0b42d780be..6f2fd4eda5 100644 --- a/scripts/yunti-process-code.py +++ b/scripts/yunti-process-code.py @@ -71,10 +71,11 @@ def run(): # 将JSON转换为字典 dictionary = json.loads(json_data) - # 替换 - # replace(dictionary) - # Move move(dictionary) + # 替换 + replace(dictionary) + + run() \ No newline at end of file diff --git a/tencentcloud/connectivity/client.go b/tencentcloud/connectivity/client.go index 86fe64bfa8..6967ec2536 100644 --- a/tencentcloud/connectivity/client.go +++ b/tencentcloud/connectivity/client.go @@ -103,8 +103,6 @@ import ( ssl "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wss/v20180426" ) -//yunti mark import - const ( PROVIDER_CVM_REQUEST_TIMEOUT = "TENCENTCLOUD_CVM_REQUEST_TIMEOUT" PROVIDER_CBS_REQUEST_TIMEOUT = "TENCENTCLOUD_CBS_REQUEST_TIMEOUT" @@ -198,7 +196,7 @@ type TencentCloudClient struct { trocketConn *trocket.Client biConn *bi.Client cdwpgConn *cdwpg.Client - //yunti mark client + billingConn *billing.Client } // NewClientProfile returns a new ClientProfile @@ -1374,7 +1372,17 @@ func (me *TencentCloudClient) UseCdwpgClient() *cdwpg.Client { return me.cdwpgConn } -//yunti mark useClient +func (me *TencentCloudClient) UseBillingClient() *billing.Client { + if me.billingConn != nil { + return me.billingConn + } + + cpf := me.NewClientProfile(300) + me.billingConn, _ = billing.NewClient(me.Credential, me.Region, cpf) + me.billingConn.WithHttpTransport(&LogRoundTripper{}) + + return me.billingConn +} func getEnvDefault(key string, defVal int) int { val, ex := os.LookupEnv(key) diff --git a/tencentcloud/internal/helper/transform.go b/tencentcloud/internal/helper/transform.go index d895c68526..1ada9c087f 100644 --- a/tencentcloud/internal/helper/transform.go +++ b/tencentcloud/internal/helper/transform.go @@ -271,6 +271,8 @@ func StrToBool(s string) (i bool) { return } +//yunti mark boolStr + func StrListToStr(strList []*string) string { res := "" for i, v := range strList { diff --git a/tencentcloud/provider.go b/tencentcloud/provider.go index 26f1133d19..197b0dc03a 100644 --- a/tencentcloud/provider.go +++ b/tencentcloud/provider.go @@ -21,12 +21,13 @@ import ( ) const ( - PROVIDER_SECRET_ID = "TENCENTCLOUD_SECRET_ID" - PROVIDER_SECRET_KEY = "TENCENTCLOUD_SECRET_KEY" - PROVIDER_SECURITY_TOKEN = "TENCENTCLOUD_SECURITY_TOKEN" - PROVIDER_REGION = "TENCENTCLOUD_REGION" - PROVIDER_PROTOCOL = "TENCENTCLOUD_PROTOCOL" - PROVIDER_DOMAIN = "TENCENTCLOUD_DOMAIN" + PROVIDER_SECRET_ID = "TENCENTCLOUD_SECRET_ID" + PROVIDER_SECRET_KEY = "TENCENTCLOUD_SECRET_KEY" + PROVIDER_SECURITY_TOKEN = "TENCENTCLOUD_SECURITY_TOKEN" + PROVIDER_REGION = "TENCENTCLOUD_REGION" + PROVIDER_PROTOCOL = "TENCENTCLOUD_PROTOCOL" + PROVIDER_DOMAIN = "TENCENTCLOUD_DOMAIN" + //yunti mark envYunti PROVIDER_ASSUME_ROLE_ARN = "TENCENTCLOUD_ASSUME_ROLE_ARN" PROVIDER_ASSUME_ROLE_SESSION_NAME = "TENCENTCLOUD_ASSUME_ROLE_SESSION_NAME" PROVIDER_ASSUME_ROLE_SESSION_DURATION = "TENCENTCLOUD_ASSUME_ROLE_SESSION_DURATION" @@ -85,6 +86,7 @@ func Provider() *schema.Provider { DefaultFunc: schema.EnvDefaultFunc(PROVIDER_DOMAIN, nil), Description: "The root domain of the API request, Default is `tencentcloudapi.com`.", }, + //yunti mark enableBpass "assume_role": { Type: schema.TypeSet, Optional: true, diff --git a/tencentcloud/resource_tc_cynosdb_cluster.go b/tencentcloud/resource_tc_cynosdb_cluster.go index 07108fda09..a15b51c93a 100644 --- a/tencentcloud/resource_tc_cynosdb_cluster.go +++ b/tencentcloud/resource_tc_cynosdb_cluster.go @@ -39,10 +39,10 @@ func resourceTencentCloudCynosdbClusterCreate(d *schema.ResourceData, meta inter cynosdbService = CynosdbService{client: client} tagService = TagService{client: client} region = client.Region - //yunti mark a + //yunti mark client request = cynosdb.NewCreateClustersRequest() ) - //yunti mark b + //yunti mark varId request.ProjectId = helper.IntInt64(d.Get("project_id").(int)) request.Zone = helper.String(d.Get("available_zone").(string)) request.VpcId = helper.String(d.Get("vpc_id").(string)) @@ -115,9 +115,9 @@ func resourceTencentCloudCynosdbClusterCreate(d *schema.ResourceData, meta inter } var chargeType int64 = 0 - //yunti mark c + //yunti mark varCharge if v, ok := d.GetOk("charge_type"); ok { - //yunti mark d + //yunti mark strCharge if v == CYNOSDB_CHARGE_TYPE_PREPAID { chargeType = 1 if vv, ok := d.GetOk("prepaid_period"); ok { @@ -145,7 +145,7 @@ func resourceTencentCloudCynosdbClusterCreate(d *schema.ResourceData, meta inter } } log.Printf("[CRITAL]%s api[%s] fail, reason:%s", logId, request.GetAction(), err.Error()) - //yunti mark e + //yunti mark byPass return retryError(err) } return nil @@ -183,10 +183,10 @@ func resourceTencentCloudCynosdbClusterCreate(d *schema.ResourceData, meta inter return fmt.Errorf("cynosdb cluster id count isn't 1") } - id := *dealRes.Response.BillingResourceInfos[0].ClusterId //yunti mark f + id := *dealRes.Response.BillingResourceInfos[0].ClusterId //yunti mark normal d.SetId(id) - //yunti mark g + //yunti mark setTag _, _, has, err := cynosdbService.DescribeClusterById(ctx, id) if err != nil { return err @@ -642,7 +642,7 @@ func resourceTencentCloudCynosdbClusterUpdate(d *schema.ResourceData, meta inter return err } - //yunti mark h + //yunti mark waitTag } // update sg diff --git a/tencentcloud/resource_tc_elasticsearch_instance.go b/tencentcloud/resource_tc_elasticsearch_instance.go index a94b3cd8c3..6045044fee 100755 --- a/tencentcloud/resource_tc_elasticsearch_instance.go +++ b/tencentcloud/resource_tc_elasticsearch_instance.go @@ -264,11 +264,13 @@ func resourceTencentCloudElasticsearchInstanceCreate(d *schema.ResourceData, met defer logElapsed("resource.tencentcloud_elasticsearch_instance.create")() logId := getLogId(contextNil) ctx := context.WithValue(context.TODO(), logIdKey, logId) + //yunti mark begin elasticsearchService := ElasticsearchService{ client: meta.(*TencentCloudClient).apiV3Conn, } - //yunti mark a request := es.NewCreateInstanceRequest() + //yunti mark end + //yunti mark var request.Zone = helper.String(d.Get("availability_zone").(string)) request.EsVersion = helper.String(d.Get("version").(string)) request.VpcId = helper.String(d.Get("vpc_id").(string)) @@ -278,7 +280,7 @@ func resourceTencentCloudElasticsearchInstanceCreate(d *schema.ResourceData, met request.InstanceName = helper.String(v.(string)) } if v, ok := d.GetOk("charge_type"); ok { - chargeType := v.(string) //yunti mark b + chargeType := v.(string) //yunti mark strCharge request.ChargeType = &chargeType if chargeType == ES_CHARGE_TYPE_PREPAID { if v, ok := d.GetOk("charge_period"); ok { @@ -358,7 +360,7 @@ func resourceTencentCloudElasticsearchInstanceCreate(d *schema.ResourceData, met request.NodeInfoList = append(request.NodeInfoList, &info) } } - //yunti mark c + //yunti mark reqTag instanceId := "" err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { ratelimit.Check(request.GetAction()) @@ -366,7 +368,7 @@ func resourceTencentCloudElasticsearchInstanceCreate(d *schema.ResourceData, met if err != nil { log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), err.Error()) - //yunti mark d + //yunti mark bypass return retryError(err) } instanceId = *response.Response.InstanceId @@ -377,7 +379,7 @@ func resourceTencentCloudElasticsearchInstanceCreate(d *schema.ResourceData, met } d.SetId(instanceId) - //yunti mark e + //yunti mark setTag instanceEmptyRetries := 5 err = resource.Retry(15*readRetryTimeout, func() *resource.RetryError { @@ -721,10 +723,12 @@ func resourceTencentCloudElasticsearchInstanceUpdate(d *schema.ResourceData, met } region := meta.(*TencentCloudClient).apiV3Conn.Region - resourceName := fmt.Sprintf("qcs::es:%s:uin/:instance/%s", region, instanceId) //yunti mark move - err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags) //yunti mark move + //yunti mark move begin + resourceName := fmt.Sprintf("qcs::es:%s:uin/:instance/%s", region, instanceId) + err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags) + //yunti mark move end - //yunti mark f + //yunti mark waitTag if err != nil { return err } diff --git a/tencentcloud/resource_tc_mongodb_instance.go b/tencentcloud/resource_tc_mongodb_instance.go index aba927e9fe..6b223b05c4 100644 --- a/tencentcloud/resource_tc_mongodb_instance.go +++ b/tencentcloud/resource_tc_mongodb_instance.go @@ -289,7 +289,14 @@ func resourceTencentCloudMongodbInstanceCreate(d *schema.ResourceData, meta inte if !has { return fmt.Errorf("[CRITAL]%s creating mongodb instance failed, instance doesn't exist", logId) } - + //yunti mark begin + if tags := helper.GetTags(d, "tags"); len(tags) > 0 { + resourceName := BuildTagResourceName("mongodb", "instance", region, instanceId) + if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil { + return err + } + } + //yunti mark end return resourceTencentCloudMongodbInstanceRead(d, meta) } From a020a5bbfd67d4eb9fbe8eefb600e334920c2bb7 Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Thu, 7 Dec 2023 20:35:19 +0800 Subject: [PATCH 05/45] feat: test --- tencentcloud/resource_tc_elasticsearch_instance.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/tencentcloud/resource_tc_elasticsearch_instance.go b/tencentcloud/resource_tc_elasticsearch_instance.go index 6045044fee..b262669504 100755 --- a/tencentcloud/resource_tc_elasticsearch_instance.go +++ b/tencentcloud/resource_tc_elasticsearch_instance.go @@ -1,6 +1,3 @@ -//go:build ignore -// +build ignore - package tencentcloud import ( From bbe6f6c72ea3a9132f1b1aa093bdc729342a9516 Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Thu, 7 Dec 2023 20:38:45 +0800 Subject: [PATCH 06/45] feat: test --- scripts/yunti-code.yaml | 7 ++++++- scripts/yunti-process-code.py | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/yunti-code.yaml b/scripts/yunti-code.yaml index 7779eacc3e..a4da16f8a9 100644 --- a/scripts/yunti-code.yaml +++ b/scripts/yunti-code.yaml @@ -289,4 +289,9 @@ tencentcloud/resource_tc_postgresql_instance.go: err = tagService.waitTagsEnable(ctx, "postgres", "DBInstanceId", d.Id(), tcClient.Region, replaceTags) if err != nil { return err - } \ No newline at end of file + } +go.mod: | + require ( + github.com/hashicorp/terraform-plugin-sdk v1.7.0 + github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/billing v1.0.809 + ) \ No newline at end of file diff --git a/scripts/yunti-process-code.py b/scripts/yunti-process-code.py index 6f2fd4eda5..3a5afd15c9 100644 --- a/scripts/yunti-process-code.py +++ b/scripts/yunti-process-code.py @@ -30,6 +30,8 @@ def replace(dictionary): # 写入修改后的文件内容 with open("../"+file_name, "w") as f: f.writelines(new_file_content) + print("success replace") + def move(dictionary): start_marker = "//yunti mark move begin" @@ -57,7 +59,7 @@ def move(dictionary): with open("../"+file_name, "w") as file: file.writelines(modified_lines) - print("代码已成功删除。") + print("success clear") def run(): # 读取YAML文件 From 92875f3aa24b4b967f86df4c88ee17a5d2361c90 Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Thu, 7 Dec 2023 20:44:06 +0800 Subject: [PATCH 07/45] feat: test --- scripts/yunti-process-code.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 scripts/yunti-process-code.sh diff --git a/scripts/yunti-process-code.sh b/scripts/yunti-process-code.sh deleted file mode 100644 index e69de29bb2..0000000000 From 20d68e9e7b1f3e7b20267679d7c7f9061f2d66a9 Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Thu, 7 Dec 2023 20:46:21 +0800 Subject: [PATCH 08/45] feat: test --- tencentcloud/connectivity/client.go | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/tencentcloud/connectivity/client.go b/tencentcloud/connectivity/client.go index 6967ec2536..75feed7c36 100644 --- a/tencentcloud/connectivity/client.go +++ b/tencentcloud/connectivity/client.go @@ -1372,18 +1372,6 @@ func (me *TencentCloudClient) UseCdwpgClient() *cdwpg.Client { return me.cdwpgConn } -func (me *TencentCloudClient) UseBillingClient() *billing.Client { - if me.billingConn != nil { - return me.billingConn - } - - cpf := me.NewClientProfile(300) - me.billingConn, _ = billing.NewClient(me.Credential, me.Region, cpf) - me.billingConn.WithHttpTransport(&LogRoundTripper{}) - - return me.billingConn -} - func getEnvDefault(key string, defVal int) int { val, ex := os.LookupEnv(key) if !ex { From 97e78ff045c4cfbc55e926f91951fa48c36a413a Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Thu, 7 Dec 2023 20:46:51 +0800 Subject: [PATCH 09/45] feat: test --- tencentcloud/connectivity/client.go | 1 - 1 file changed, 1 deletion(-) diff --git a/tencentcloud/connectivity/client.go b/tencentcloud/connectivity/client.go index 75feed7c36..960a95b363 100644 --- a/tencentcloud/connectivity/client.go +++ b/tencentcloud/connectivity/client.go @@ -196,7 +196,6 @@ type TencentCloudClient struct { trocketConn *trocket.Client biConn *bi.Client cdwpgConn *cdwpg.Client - billingConn *billing.Client } // NewClientProfile returns a new ClientProfile From 60f7118b49354eece419577e919cde0dc30a8bb2 Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Thu, 7 Dec 2023 20:48:28 +0800 Subject: [PATCH 10/45] feat: test --- tencentcloud/connectivity/client.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tencentcloud/connectivity/client.go b/tencentcloud/connectivity/client.go index 960a95b363..d828051b3f 100644 --- a/tencentcloud/connectivity/client.go +++ b/tencentcloud/connectivity/client.go @@ -196,8 +196,11 @@ type TencentCloudClient struct { trocketConn *trocket.Client biConn *bi.Client cdwpgConn *cdwpg.Client + //yunti mark client } +//yunti mark import + // NewClientProfile returns a new ClientProfile func (me *TencentCloudClient) NewClientProfile(timeout int) *profile.ClientProfile { cpf := profile.NewClientProfile() @@ -1371,6 +1374,8 @@ func (me *TencentCloudClient) UseCdwpgClient() *cdwpg.Client { return me.cdwpgConn } +//yunti mark useClient + func getEnvDefault(key string, defVal int) int { val, ex := os.LookupEnv(key) if !ex { From c2c925f666ad200ee245d0b46f07f73ba2e7886b Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Thu, 7 Dec 2023 20:50:05 +0800 Subject: [PATCH 11/45] feat: test --- tencentcloud/connectivity/client.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tencentcloud/connectivity/client.go b/tencentcloud/connectivity/client.go index d828051b3f..86fe64bfa8 100644 --- a/tencentcloud/connectivity/client.go +++ b/tencentcloud/connectivity/client.go @@ -103,6 +103,8 @@ import ( ssl "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wss/v20180426" ) +//yunti mark import + const ( PROVIDER_CVM_REQUEST_TIMEOUT = "TENCENTCLOUD_CVM_REQUEST_TIMEOUT" PROVIDER_CBS_REQUEST_TIMEOUT = "TENCENTCLOUD_CBS_REQUEST_TIMEOUT" @@ -199,8 +201,6 @@ type TencentCloudClient struct { //yunti mark client } -//yunti mark import - // NewClientProfile returns a new ClientProfile func (me *TencentCloudClient) NewClientProfile(timeout int) *profile.ClientProfile { cpf := profile.NewClientProfile() From 3caa00111a17ae4b73a010ee1ebcca2d69f96e8f Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Thu, 7 Dec 2023 21:02:08 +0800 Subject: [PATCH 12/45] feat: test --- scripts/yunti-code.yaml | 170 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 170 insertions(+) diff --git a/scripts/yunti-code.yaml b/scripts/yunti-code.yaml index a4da16f8a9..0be425ff0f 100644 --- a/scripts/yunti-code.yaml +++ b/scripts/yunti-code.yaml @@ -290,6 +290,176 @@ tencentcloud/resource_tc_postgresql_instance.go: if err != nil { return err } + + +tencentcloud/service_tencentcloud_tag.go: + waitTag: | + func (me *TagService) waitTagsEnable(ctx context.Context, serviceType, resType, resId, region string, tags map[string]string) (retErr error) { + billingService := BillingService{client: me.client} + if !billingService.isYunTiAccount() { + return nil + } + retErr = resource.Retry(3*readRetryTimeout, func() *resource.RetryError { + ret, err := me.DescribeResourceTags(ctx, serviceType, resType, region, resId) + if err != nil { + return retryError(err) + } + if ret != nil { + if tagEqual(ret, tags) { + return nil + } + return resource.RetryableError(fmt.Errorf("the redis.instance %s is uncomplete, retry ...", resId)) + } + return resource.RetryableError(fmt.Errorf("the redis.instance %s's tags is nil, retry ...", resId)) + }) + return retErr + } + + func tagEqual(dst, orig map[string]string) bool { + for k := range orig { + if dst[k] == "" { + return false + } + if dst[k] != orig[k] { + return false + } + } + return true + } + +tencentcloud/service_tencentcloud_billing.go: + all: | + package tencentcloud + + import ( + "context" + "fmt" + "log" + "os" + "regexp" + "strings" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/ratelimit" + + billing "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/billing/v20180709" + sdkErrors "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/connectivity" + ) + + type BillingService struct { + client *connectivity.TencentCloudClient + } + + func (me *BillingService) DescribeDeals(ctx context.Context, dealId string) (deal *billing.Deal, errRet error) { + var ( + logId = getLogId(ctx) + request = billing.NewDescribeDealsByCondRequest() + response = billing.NewDescribeDealsByCondResponse() + dealList []*billing.Deal + ) + + defer func() { + if errRet != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, "query object", request.ToJsonString(), errRet.Error()) + } + }() + + request.OrderId = helper.String(dealId) + request.Limit = helper.IntInt64(20) + baseTime := time.Now().Local() + startTime := baseTime.AddDate(0, 0, -7).Format("2006-01-02 15:04:05") + endTime := baseTime.Format("2006-01-02 15:04:05") + request.StartTime = helper.String(startTime) + request.EndTime = helper.String(endTime) + + ratelimit.Check(request.GetAction()) + err := resource.Retry(20*readRetryTimeout, func() *resource.RetryError { + for _, dealState := range DEAL_STATUS_CODE { + request.Status = helper.Int64(dealState) + response, ee := me.client.UseBillingClient().DescribeDealsByCond(request) + if ee != nil { + return retryError(errRet, InternalError) + } + dealList = response.Response.Deals + if len(dealList) > 0 { + break + } + } + if len(dealList) != 1 { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + return nil + } + deal = dealList[0] + if in(*deal.Status, DEAL_TERMINATE_STATUS_CODE) { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + return nil + } + time.Sleep(3 * time.Second) + return resource.RetryableError(fmt.Errorf("deal status is not ready..., current is: %v", deal.Status)) + }) + + if err != nil { + errRet = err + return + } + return + } + + func (me *BillingService) isYunTiAccount() bool { + val, ok := os.LookupEnv(PROVIDER_ENABLE_YUNTI) + if ok && strings.ToLower(val) == "true" { + return true + } + return false + } + + //query deal by bpass + func (me *BillingService) QueryDealByBpass(ctx context.Context, dealRegx string, msg error) (resourceId *string, err error) { + logId := getLogId(ctx) + + if !me.isYunTiAccount() { + return + } + + e, ok := msg.(*sdkErrors.TencentCloudSDKError) + log.Printf("[DEBUG]%s query deal for PREPAID user, msg:[%s] \n", logId, e.Error()) + + if ok && IsContains(TRADE_RETRYABLE_ERROR, e.Code) { + errStr := msg.Error() + + re := regexp.MustCompile(dealRegx) + result := re.FindStringSubmatch(errStr) + for i, str := range result { + log.Printf("[DEBUG] FindStringSubmatch sub[%v]:%s,\n", i, str) + } + dealId := re.FindStringSubmatch(errStr)[1] + deal, billErr := me.DescribeDeals(ctx, dealId) + if billErr != nil { + log.Printf("[CRITAL]%s api[DescribeDeals] fail, reason[%s]\n", logId, billErr.Error()) + return nil, billErr + } + resourceId = deal.ResourceId[0] + log.Printf("[DEBUG]%s query deal for PREPAID user succeed, dealId:[%s] resourceId:[%s]\n", logId, dealId, *resourceId) + return resourceId, nil + } + return + } + + func in(target int64, intArr []int64) bool { + for _, element := range intArr { + if target == element { + return true + } + } + return false + } + go.mod: | require ( github.com/hashicorp/terraform-plugin-sdk v1.7.0 From 0853f1d07d700ed239dc0986048851fb2cc0181b Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Thu, 7 Dec 2023 21:03:21 +0800 Subject: [PATCH 13/45] feat: test --- scripts/yunti-process-code.py | 2 +- tencentcloud/service_tencentcloud_tag.go | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/yunti-process-code.py b/scripts/yunti-process-code.py index 3a5afd15c9..95679450c4 100644 --- a/scripts/yunti-process-code.py +++ b/scripts/yunti-process-code.py @@ -7,7 +7,7 @@ def replace(dictionary): for file_name, content in dictionary.items(): # 读取文件内容 - if file_name=="tencentcloud/extension_billing.go": + if file_name=="tencentcloud/extension_billing.go" or "tencentcloud/service_tencentcloud_billing.go": with open("../"+file_name, "w") as f: f.write(content["all"]) continue diff --git a/tencentcloud/service_tencentcloud_tag.go b/tencentcloud/service_tencentcloud_tag.go index e6faa75ded..121df2fe2f 100644 --- a/tencentcloud/service_tencentcloud_tag.go +++ b/tencentcloud/service_tencentcloud_tag.go @@ -102,6 +102,8 @@ func (me *TagService) DescribeResourceTags(ctx context.Context, serviceType, res return } +//yunti mark waitTag + func diffTags(oldTags, newTags map[string]interface{}) (replaceTags map[string]string, deleteTags []string) { replaceTags = make(map[string]string) deleteTags = make([]string, 0) From 054cc5f81b7bd6aadaab1e0ea68fe2c95f956960 Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Thu, 7 Dec 2023 21:06:52 +0800 Subject: [PATCH 14/45] feat: test --- scripts/yunti-process-code.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/yunti-process-code.py b/scripts/yunti-process-code.py index 95679450c4..7f7d53d2bd 100644 --- a/scripts/yunti-process-code.py +++ b/scripts/yunti-process-code.py @@ -38,7 +38,7 @@ def move(dictionary): end_marker = "//yunti mark move end" for file_name, _ in dictionary.items(): - if file_name=="tencentcloud/extension_billing.go": + if file_name=="tencentcloud/extension_billing.go" or "tencentcloud/service_tencentcloud_billing.go'": continue # 打开文件并读取内容 with open("../"+file_name, "r") as file: From e5ab542db8c79549a21ae6d5130535cf56819bb4 Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Thu, 7 Dec 2023 21:07:13 +0800 Subject: [PATCH 15/45] feat: test --- scripts/yunti-process-code.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/yunti-process-code.py b/scripts/yunti-process-code.py index 7f7d53d2bd..91b81fc463 100644 --- a/scripts/yunti-process-code.py +++ b/scripts/yunti-process-code.py @@ -38,7 +38,7 @@ def move(dictionary): end_marker = "//yunti mark move end" for file_name, _ in dictionary.items(): - if file_name=="tencentcloud/extension_billing.go" or "tencentcloud/service_tencentcloud_billing.go'": + if file_name=="tencentcloud/extension_billing.go" or "tencentcloud/service_tencentcloud_billing.go": continue # 打开文件并读取内容 with open("../"+file_name, "r") as file: From 90e34cfdfca86bf4dd849435f23d867089d2347c Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Thu, 7 Dec 2023 21:15:00 +0800 Subject: [PATCH 16/45] feat: test --- scripts/yunti-process-code.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/yunti-process-code.py b/scripts/yunti-process-code.py index 91b81fc463..583542ed7b 100644 --- a/scripts/yunti-process-code.py +++ b/scripts/yunti-process-code.py @@ -7,11 +7,14 @@ def replace(dictionary): for file_name, content in dictionary.items(): # 读取文件内容 - if file_name=="tencentcloud/extension_billing.go" or "tencentcloud/service_tencentcloud_billing.go": + if file_name=="tencentcloud/extension_billing.go": + with open("../"+file_name, "w") as f: + f.write(content["all"]) + continue + if file_name=="tencentcloud/service_tencentcloud_billing.go": with open("../"+file_name, "w") as f: f.write(content["all"]) continue - with open("../"+file_name, "r") as f: file_content = f.readlines() From c0b648eaa29fd6ce93e2f079ed55e753295540de Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Thu, 7 Dec 2023 21:17:40 +0800 Subject: [PATCH 17/45] feat: test --- scripts/yunti-code.yaml | 1 + tencentcloud/resource_tc_elasticsearch_instance.go | 4 ++-- tencentcloud/service_tencentcloud_tag.go | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/yunti-code.yaml b/scripts/yunti-code.yaml index 0be425ff0f..2d16aa1d6a 100644 --- a/scripts/yunti-code.yaml +++ b/scripts/yunti-code.yaml @@ -293,6 +293,7 @@ tencentcloud/resource_tc_postgresql_instance.go: tencentcloud/service_tencentcloud_tag.go: + tagFmt: "import \"fmt\"" waitTag: | func (me *TagService) waitTagsEnable(ctx context.Context, serviceType, resType, resId, region string, tags map[string]string) (retErr error) { billingService := BillingService{client: me.client} diff --git a/tencentcloud/resource_tc_elasticsearch_instance.go b/tencentcloud/resource_tc_elasticsearch_instance.go index b262669504..a11e4b382f 100755 --- a/tencentcloud/resource_tc_elasticsearch_instance.go +++ b/tencentcloud/resource_tc_elasticsearch_instance.go @@ -261,12 +261,12 @@ func resourceTencentCloudElasticsearchInstanceCreate(d *schema.ResourceData, met defer logElapsed("resource.tencentcloud_elasticsearch_instance.create")() logId := getLogId(contextNil) ctx := context.WithValue(context.TODO(), logIdKey, logId) - //yunti mark begin + //yunti mark move begin elasticsearchService := ElasticsearchService{ client: meta.(*TencentCloudClient).apiV3Conn, } request := es.NewCreateInstanceRequest() - //yunti mark end + //yunti mark move end //yunti mark var request.Zone = helper.String(d.Get("availability_zone").(string)) request.EsVersion = helper.String(d.Get("version").(string)) diff --git a/tencentcloud/service_tencentcloud_tag.go b/tencentcloud/service_tencentcloud_tag.go index 121df2fe2f..1ff33767a1 100644 --- a/tencentcloud/service_tencentcloud_tag.go +++ b/tencentcloud/service_tencentcloud_tag.go @@ -12,6 +12,8 @@ import ( "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/ratelimit" ) +//yunti mark tagFmt + type TagService struct { client *connectivity.TencentCloudClient } From 412096190f9195a7342ccbb8d34d6c517134f96c Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Fri, 8 Dec 2023 14:13:25 +0800 Subject: [PATCH 18/45] feat: test --- tencentcloud/resource_tc_elasticsearch_instance.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tencentcloud/resource_tc_elasticsearch_instance.go b/tencentcloud/resource_tc_elasticsearch_instance.go index a11e4b382f..a8def5e6d2 100755 --- a/tencentcloud/resource_tc_elasticsearch_instance.go +++ b/tencentcloud/resource_tc_elasticsearch_instance.go @@ -720,12 +720,14 @@ func resourceTencentCloudElasticsearchInstanceUpdate(d *schema.ResourceData, met } region := meta.(*TencentCloudClient).apiV3Conn.Region - //yunti mark move begin + //internal version: replace begin resourceName := fmt.Sprintf("qcs::es:%s:uin/:instance/%s", region, instanceId) err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags) - //yunti mark move end + //internal version: replace end + + //internal version: replace waitTag begin + //internal version: replace waitTag end - //yunti mark waitTag if err != nil { return err } From 39d020522d8caa72f58e4f9ba85a61464d7cb05c Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Fri, 8 Dec 2023 16:01:51 +0800 Subject: [PATCH 19/45] feat: test --- .../resource_tc_elasticsearch_instance.go | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/tencentcloud/resource_tc_elasticsearch_instance.go b/tencentcloud/resource_tc_elasticsearch_instance.go index a8def5e6d2..6c73a7c8f4 100755 --- a/tencentcloud/resource_tc_elasticsearch_instance.go +++ b/tencentcloud/resource_tc_elasticsearch_instance.go @@ -261,13 +261,14 @@ func resourceTencentCloudElasticsearchInstanceCreate(d *schema.ResourceData, met defer logElapsed("resource.tencentcloud_elasticsearch_instance.create")() logId := getLogId(contextNil) ctx := context.WithValue(context.TODO(), logIdKey, logId) - //yunti mark move begin + //internal version: replace null begin elasticsearchService := ElasticsearchService{ client: meta.(*TencentCloudClient).apiV3Conn, } request := es.NewCreateInstanceRequest() - //yunti mark move end - //yunti mark var + //internal version: replace null end + //internal version: replace ver begin + //internal version: replace ver end request.Zone = helper.String(d.Get("availability_zone").(string)) request.EsVersion = helper.String(d.Get("version").(string)) request.VpcId = helper.String(d.Get("vpc_id").(string)) @@ -357,7 +358,8 @@ func resourceTencentCloudElasticsearchInstanceCreate(d *schema.ResourceData, met request.NodeInfoList = append(request.NodeInfoList, &info) } } - //yunti mark reqTag + //internal version: replace reqTag begin + //internal version: replace reqTag end instanceId := "" err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { ratelimit.Check(request.GetAction()) @@ -365,7 +367,8 @@ func resourceTencentCloudElasticsearchInstanceCreate(d *schema.ResourceData, met if err != nil { log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), err.Error()) - //yunti mark bypass + //internal version: replace bypass begin + //internal version: replace bypass end return retryError(err) } instanceId = *response.Response.InstanceId @@ -376,8 +379,8 @@ func resourceTencentCloudElasticsearchInstanceCreate(d *schema.ResourceData, met } d.SetId(instanceId) - //yunti mark setTag - + //internal version: replace setTag begin + //internal version: replace setTag end instanceEmptyRetries := 5 err = resource.Retry(15*readRetryTimeout, func() *resource.RetryError { instance, errRet := elasticsearchService.DescribeInstanceById(ctx, instanceId) @@ -720,10 +723,10 @@ func resourceTencentCloudElasticsearchInstanceUpdate(d *schema.ResourceData, met } region := meta.(*TencentCloudClient).apiV3Conn.Region - //internal version: replace begin + //internal version: replace null begin resourceName := fmt.Sprintf("qcs::es:%s:uin/:instance/%s", region, instanceId) err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags) - //internal version: replace end + //internal version: replace null end //internal version: replace waitTag begin //internal version: replace waitTag end From 88ee2b5b066e5c63889724da03cdfc0e775d0e72 Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Fri, 8 Dec 2023 16:25:33 +0800 Subject: [PATCH 20/45] feat: test --- tencentcloud/resource_tc_elasticsearch_instance.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tencentcloud/resource_tc_elasticsearch_instance.go b/tencentcloud/resource_tc_elasticsearch_instance.go index 6c73a7c8f4..3831d6ef92 100755 --- a/tencentcloud/resource_tc_elasticsearch_instance.go +++ b/tencentcloud/resource_tc_elasticsearch_instance.go @@ -267,8 +267,8 @@ func resourceTencentCloudElasticsearchInstanceCreate(d *schema.ResourceData, met } request := es.NewCreateInstanceRequest() //internal version: replace null end - //internal version: replace ver begin - //internal version: replace ver end + //internal version: replace var begin + //internal version: replace var end request.Zone = helper.String(d.Get("availability_zone").(string)) request.EsVersion = helper.String(d.Get("version").(string)) request.VpcId = helper.String(d.Get("vpc_id").(string)) From d69eff278ec3b3b9d44f453edf9a7ff3ff983ee8 Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Fri, 8 Dec 2023 16:37:39 +0800 Subject: [PATCH 21/45] feat: fix rex --- scripts/yunti-code.yaml | 42 ++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/scripts/yunti-code.yaml b/scripts/yunti-code.yaml index 2d16aa1d6a..4f865fb8e1 100644 --- a/scripts/yunti-code.yaml +++ b/scripts/yunti-code.yaml @@ -124,11 +124,11 @@ tencentcloud/resource_tc_elasticsearch_instance.go: } bypass: | if chargeType == ES_CHARGE_TYPE_PREPAID { - regx := "\"dealNames\":\\[\"(.*)\"\\]" + regx := "\"dealNames\":\\\[\"(.*)\"\\\]" // query deal by bpass id, billErr := billingService.QueryDealByBpass(ctx, regx, err) if billErr != nil { - log.Printf("[CRITAL]%s api[QueryDealByBpass] fail, reason[%s]\n", logId, billErr.Error()) + log.Printf("[CRITAL]%s api[QueryDealByBpass] fail, reason[%s]\\n", logId, billErr.Error()) return resource.NonRetryableError(billErr) } // yunti prepaid user @@ -251,7 +251,7 @@ tencentcloud/resource_tc_postgresql_instance.go: var: "chargeType = d.Get(\"charge_type\").(string)" bypass: | log.Printf("[CRITAL]%s api[%s] fail, reason:%s", logId, "CreatePostgresqlInstance", inErr.Error()) - + if chargeType == COMMON_PAYTYPE_PREPAID { regx := "\"dealNames\":\\[\"(.*)\"\\]" // query deal by bpass @@ -273,7 +273,7 @@ tencentcloud/resource_tc_postgresql_instance.go: if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil { return err } - + // Wait the tags enabled err := tagService.waitTagsEnable(ctx, "postgres", "DBInstanceId", d.Id(), region, tags) if err != nil { @@ -315,7 +315,7 @@ tencentcloud/service_tencentcloud_tag.go: }) return retErr } - + func tagEqual(dst, orig map[string]string) bool { for k := range orig { if dst[k] == "" { @@ -327,7 +327,7 @@ tencentcloud/service_tencentcloud_tag.go: } return true } - +# tencentcloud/service_tencentcloud_billing.go: all: | package tencentcloud @@ -340,20 +340,20 @@ tencentcloud/service_tencentcloud_billing.go: "regexp" "strings" "time" - + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/ratelimit" - + billing "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/billing/v20180709" sdkErrors "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors" "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/connectivity" ) - + type BillingService struct { client *connectivity.TencentCloudClient } - + func (me *BillingService) DescribeDeals(ctx context.Context, dealId string) (deal *billing.Deal, errRet error) { var ( logId = getLogId(ctx) @@ -361,14 +361,14 @@ tencentcloud/service_tencentcloud_billing.go: response = billing.NewDescribeDealsByCondResponse() dealList []*billing.Deal ) - + defer func() { if errRet != nil { log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, "query object", request.ToJsonString(), errRet.Error()) } }() - + request.OrderId = helper.String(dealId) request.Limit = helper.IntInt64(20) baseTime := time.Now().Local() @@ -376,7 +376,7 @@ tencentcloud/service_tencentcloud_billing.go: endTime := baseTime.Format("2006-01-02 15:04:05") request.StartTime = helper.String(startTime) request.EndTime = helper.String(endTime) - + ratelimit.Check(request.GetAction()) err := resource.Retry(20*readRetryTimeout, func() *resource.RetryError { for _, dealState := range DEAL_STATUS_CODE { @@ -404,14 +404,14 @@ tencentcloud/service_tencentcloud_billing.go: time.Sleep(3 * time.Second) return resource.RetryableError(fmt.Errorf("deal status is not ready..., current is: %v", deal.Status)) }) - + if err != nil { errRet = err return } return } - + func (me *BillingService) isYunTiAccount() bool { val, ok := os.LookupEnv(PROVIDER_ENABLE_YUNTI) if ok && strings.ToLower(val) == "true" { @@ -419,21 +419,21 @@ tencentcloud/service_tencentcloud_billing.go: } return false } - + //query deal by bpass func (me *BillingService) QueryDealByBpass(ctx context.Context, dealRegx string, msg error) (resourceId *string, err error) { logId := getLogId(ctx) - + if !me.isYunTiAccount() { return } - + e, ok := msg.(*sdkErrors.TencentCloudSDKError) log.Printf("[DEBUG]%s query deal for PREPAID user, msg:[%s] \n", logId, e.Error()) - + if ok && IsContains(TRADE_RETRYABLE_ERROR, e.Code) { errStr := msg.Error() - + re := regexp.MustCompile(dealRegx) result := re.FindStringSubmatch(errStr) for i, str := range result { @@ -451,7 +451,7 @@ tencentcloud/service_tencentcloud_billing.go: } return } - + func in(target int64, intArr []int64) bool { for _, element := range intArr { if target == element { From 8591fc1ca6837ccb4c8d7a7f7766c9a3227d7e70 Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Fri, 8 Dec 2023 16:43:19 +0800 Subject: [PATCH 22/45] feat: py update --- scripts/yunti-process-code.py | 141 ++++++++++++++++++++-------------- 1 file changed, 84 insertions(+), 57 deletions(-) diff --git a/scripts/yunti-process-code.py b/scripts/yunti-process-code.py index 583542ed7b..880b5c30b2 100644 --- a/scripts/yunti-process-code.py +++ b/scripts/yunti-process-code.py @@ -3,66 +3,95 @@ import re -# 处理每个文件 + +# +# def move(dictionary): +# for file_name, content in dictionary.items(): +# +# if file_name=="tencentcloud/extension_billing.go": +# continue +# # 打开文件并读取内容 +# print(file_name) +# with open("../"+file_name, "r") as file: +# lines = file.readlines() +# +# modified_lines = [] +# inside_code_block = False +# replacement_start="" +# replacement_end="" +# # 遍历文件内容的每一行 +# for line in lines: +# +# start_match = re.search(r"//internal version: replace (\w+) begin", line) +# end_match = re.search(r"//internal version: replace (\w+) end", line) +# if start_match: +# inside_code_block = True +# replacement_start = start_match.group(1) +# continue +# elif end_match: +# inside_code_block = False +# replacement_end = end_match.group(1) +# continue +# elif not inside_code_block: +# if replacement_start ==replacement_end: +# if replacement_start in content: +# line=content[replacement_start] +# else: +# line="" +# modified_lines.append(line) +# +# # modified_lines.append(line) +# +# # 将修改后的内容写回文件 +# with open("../"+file_name, "w") as file: +# file.writelines(modified_lines) +# +# print("success replace") +# + + + +def replace_code(dictionary, code): + + matches = re.finditer(r"//internal version: replace (\w+) begin.*?//internal version: replace \w+ end", code, flags=re.DOTALL) + + for match in matches: + key = match.group(1) + print(key) + if key in dictionary: + # 使用字典中的代码替换 + replacement_code = dictionary[key] + else: + replacement_code="" + # testKey=re.search(r"//internal version: replace \w+ begin.*?//internal version: replace \w+ end") + # print(testKey,replacement_code) + mark_str="//internal version: replace %s begin.*?//internal version: replace %s end"%(key,key) + code = re.sub(r"%s"%mark_str, replacement_code, code, flags=re.DOTALL) + return code + def replace(dictionary): for file_name, content in dictionary.items(): - # 读取文件内容 - if file_name=="tencentcloud/extension_billing.go": - with open("../"+file_name, "w") as f: - f.write(content["all"]) - continue - if file_name=="tencentcloud/service_tencentcloud_billing.go": - with open("../"+file_name, "w") as f: - f.write(content["all"]) - continue - with open("../"+file_name, "r") as f: - file_content = f.readlines() - - # 修改文件内容 - new_file_content = [] - for line in file_content: - match = re.search(r"//yunti mark (\w+)", line) - if match: - index = match.group(1) - if index =="move": - continue - if index in content: - line = content[index] +"\n" - new_file_content.append(line) - - # 写入修改后的文件内容 - with open("../"+file_name, "w") as f: - f.writelines(new_file_content) - print("success replace") - - -def move(dictionary): - start_marker = "//yunti mark move begin" - end_marker = "//yunti mark move end" - - for file_name, _ in dictionary.items(): - if file_name=="tencentcloud/extension_billing.go" or "tencentcloud/service_tencentcloud_billing.go": + if file_name in "tencentcloud/extension_billing.go" or file_name in "tencentcloud/service_tencentcloud_billing.go": + with open("../" + file_name, "w") as file: + file.write(content["all"]) continue + + if file_name in "go.sum": + with open("../" + file_name, "a") as file: + file.write(content) # 打开文件并读取内容 - with open("../"+file_name, "r") as file: - lines = file.readlines() - - modified_lines = [] - inside_code_block = False - # 遍历文件内容的每一行 - for line in lines: - if start_marker in line: - inside_code_block = True - elif end_marker in line: - inside_code_block = False - elif not inside_code_block: - modified_lines.append(line) + with open("../" + file_name, "r") as file: + code = file.read() + + # 替换代码 + replaced_code = replace_code(content, code) # 将修改后的内容写回文件 - with open("../"+file_name, "w") as file: - file.writelines(modified_lines) + with open("../" + file_name, "w") as file: + file.write(replaced_code) + + print("Success replace") - print("success clear") def run(): # 读取YAML文件 @@ -76,11 +105,9 @@ def run(): # 将JSON转换为字典 dictionary = json.loads(json_data) - # Move - move(dictionary) - # 替换 replace(dictionary) -run() \ No newline at end of file + +run() From fcc7e8fdf0334e8c4e078dbf7d3486b8c3c91220 Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Fri, 8 Dec 2023 16:44:25 +0800 Subject: [PATCH 23/45] feat: py update --- scripts/yunti-process-code.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/yunti-process-code.py b/scripts/yunti-process-code.py index 880b5c30b2..b2cc3d7bb1 100644 --- a/scripts/yunti-process-code.py +++ b/scripts/yunti-process-code.py @@ -76,7 +76,7 @@ def replace(dictionary): file.write(content["all"]) continue - if file_name in "go.sum": + if file_name in "go.mod": with open("../" + file_name, "a") as file: file.write(content) # 打开文件并读取内容 From b49b82d39f06280b1be954ab0a9e5fd79e423199 Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Fri, 8 Dec 2023 17:05:05 +0800 Subject: [PATCH 24/45] feat: mark update --- scripts/yunti-code.yaml | 4 +- scripts/yunti-process-code.py | 80 +++++++------------ tencentcloud/connectivity/client.go | 9 ++- tencentcloud/internal/helper/transform.go | 3 +- tencentcloud/provider.go | 6 +- tencentcloud/resource_tc_cynosdb_cluster.go | 26 +++--- .../resource_tc_elasticsearch_instance.go | 8 +- tencentcloud/resource_tc_mongodb_instance.go | 15 ++-- tencentcloud/resource_tc_mysql_instance.go | 21 +++-- .../resource_tc_postgresql_instance.go | 34 +++++--- tencentcloud/service_tencentcloud_tag.go | 6 +- 11 files changed, 115 insertions(+), 97 deletions(-) diff --git a/scripts/yunti-code.yaml b/scripts/yunti-code.yaml index 4f865fb8e1..d5222a820a 100644 --- a/scripts/yunti-code.yaml +++ b/scripts/yunti-code.yaml @@ -122,7 +122,7 @@ tencentcloud/resource_tc_elasticsearch_instance.go: } } } - bypass: | + bpass: | if chargeType == ES_CHARGE_TYPE_PREPAID { regx := "\"dealNames\":\\\[\"(.*)\"\\\]" // query deal by bpass @@ -249,7 +249,7 @@ tencentcloud/resource_tc_postgresql_instance.go: billingService := BillingService{client: client} region := client.Region var: "chargeType = d.Get(\"charge_type\").(string)" - bypass: | + bpass: | log.Printf("[CRITAL]%s api[%s] fail, reason:%s", logId, "CreatePostgresqlInstance", inErr.Error()) if chargeType == COMMON_PAYTYPE_PREPAID { diff --git a/scripts/yunti-process-code.py b/scripts/yunti-process-code.py index b2cc3d7bb1..a7e128349d 100644 --- a/scripts/yunti-process-code.py +++ b/scripts/yunti-process-code.py @@ -2,55 +2,6 @@ import json import re - - -# -# def move(dictionary): -# for file_name, content in dictionary.items(): -# -# if file_name=="tencentcloud/extension_billing.go": -# continue -# # 打开文件并读取内容 -# print(file_name) -# with open("../"+file_name, "r") as file: -# lines = file.readlines() -# -# modified_lines = [] -# inside_code_block = False -# replacement_start="" -# replacement_end="" -# # 遍历文件内容的每一行 -# for line in lines: -# -# start_match = re.search(r"//internal version: replace (\w+) begin", line) -# end_match = re.search(r"//internal version: replace (\w+) end", line) -# if start_match: -# inside_code_block = True -# replacement_start = start_match.group(1) -# continue -# elif end_match: -# inside_code_block = False -# replacement_end = end_match.group(1) -# continue -# elif not inside_code_block: -# if replacement_start ==replacement_end: -# if replacement_start in content: -# line=content[replacement_start] -# else: -# line="" -# modified_lines.append(line) -# -# # modified_lines.append(line) -# -# # 将修改后的内容写回文件 -# with open("../"+file_name, "w") as file: -# file.writelines(modified_lines) -# -# print("success replace") -# - - - def replace_code(dictionary, code): matches = re.finditer(r"//internal version: replace (\w+) begin.*?//internal version: replace \w+ end", code, flags=re.DOTALL) @@ -69,6 +20,20 @@ def replace_code(dictionary, code): code = re.sub(r"%s"%mark_str, replacement_code, code, flags=re.DOTALL) return code +def mark_replace_code(dictionary, code): + str="//yunti mark (\w+)" + strDe="//yunti mark %s" + + strRe="//internal version: replace %s begin\n//internal version: replace %s end" + matches = re.finditer(r"%s"%str, code, flags=re.DOTALL) + + for match in matches: + key = match.group(1) + print(key) + print("%s"%strDe) + code = re.sub(strDe%key, strRe%(key,key), code, flags=re.DOTALL) + return code + def replace(dictionary): for file_name, content in dictionary.items(): if file_name in "tencentcloud/extension_billing.go" or file_name in "tencentcloud/service_tencentcloud_billing.go": @@ -93,6 +58,19 @@ def replace(dictionary): print("Success replace") +def mark(dictionary): + for file_name, content in dictionary.items(): + if file_name in "tencentcloud/extension_billing.go" or file_name in "tencentcloud/service_tencentcloud_billing.go": + continue + with open("../" + file_name, "r") as file: + code = file.read() + # 替换代码 + replaced_code = mark_replace_code(content, code) + + # 将修改后的内容写回文件 + with open("../" + file_name, "w") as file: + file.write(replaced_code) + def run(): # 读取YAML文件 yaml_file = "yunti-code.yaml" @@ -105,8 +83,8 @@ def run(): # 将JSON转换为字典 dictionary = json.loads(json_data) - replace(dictionary) - + # replace(dictionary) + mark(dictionary) diff --git a/tencentcloud/connectivity/client.go b/tencentcloud/connectivity/client.go index 86fe64bfa8..80db8d550e 100644 --- a/tencentcloud/connectivity/client.go +++ b/tencentcloud/connectivity/client.go @@ -103,7 +103,8 @@ import ( ssl "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wss/v20180426" ) -//yunti mark import +//internal version: replace import begin +//internal version: replace import end const ( PROVIDER_CVM_REQUEST_TIMEOUT = "TENCENTCLOUD_CVM_REQUEST_TIMEOUT" @@ -198,7 +199,8 @@ type TencentCloudClient struct { trocketConn *trocket.Client biConn *bi.Client cdwpgConn *cdwpg.Client - //yunti mark client + //internal version: replace client begin + //internal version: replace client end } // NewClientProfile returns a new ClientProfile @@ -1374,7 +1376,8 @@ func (me *TencentCloudClient) UseCdwpgClient() *cdwpg.Client { return me.cdwpgConn } -//yunti mark useClient +//internal version: replace useClient begin +//internal version: replace useClient end func getEnvDefault(key string, defVal int) int { val, ex := os.LookupEnv(key) diff --git a/tencentcloud/internal/helper/transform.go b/tencentcloud/internal/helper/transform.go index 1ada9c087f..411d041b47 100644 --- a/tencentcloud/internal/helper/transform.go +++ b/tencentcloud/internal/helper/transform.go @@ -271,7 +271,8 @@ func StrToBool(s string) (i bool) { return } -//yunti mark boolStr +//internal version: replace boolStr begin +//internal version: replace boolStr end func StrListToStr(strList []*string) string { res := "" diff --git a/tencentcloud/provider.go b/tencentcloud/provider.go index 197b0dc03a..deb8056601 100644 --- a/tencentcloud/provider.go +++ b/tencentcloud/provider.go @@ -27,7 +27,8 @@ const ( PROVIDER_REGION = "TENCENTCLOUD_REGION" PROVIDER_PROTOCOL = "TENCENTCLOUD_PROTOCOL" PROVIDER_DOMAIN = "TENCENTCLOUD_DOMAIN" - //yunti mark envYunti + //internal version: replace envYunti begin + //internal version: replace envYunti end PROVIDER_ASSUME_ROLE_ARN = "TENCENTCLOUD_ASSUME_ROLE_ARN" PROVIDER_ASSUME_ROLE_SESSION_NAME = "TENCENTCLOUD_ASSUME_ROLE_SESSION_NAME" PROVIDER_ASSUME_ROLE_SESSION_DURATION = "TENCENTCLOUD_ASSUME_ROLE_SESSION_DURATION" @@ -86,7 +87,8 @@ func Provider() *schema.Provider { DefaultFunc: schema.EnvDefaultFunc(PROVIDER_DOMAIN, nil), Description: "The root domain of the API request, Default is `tencentcloudapi.com`.", }, - //yunti mark enableBpass + //internal version: replace enableBpass begin + //internal version: replace enableBpass end "assume_role": { Type: schema.TypeSet, Optional: true, diff --git a/tencentcloud/resource_tc_cynosdb_cluster.go b/tencentcloud/resource_tc_cynosdb_cluster.go index a15b51c93a..796e1de9ba 100644 --- a/tencentcloud/resource_tc_cynosdb_cluster.go +++ b/tencentcloud/resource_tc_cynosdb_cluster.go @@ -39,10 +39,12 @@ func resourceTencentCloudCynosdbClusterCreate(d *schema.ResourceData, meta inter cynosdbService = CynosdbService{client: client} tagService = TagService{client: client} region = client.Region - //yunti mark client + //internal version: replace client begin + //internal version: replace client end request = cynosdb.NewCreateClustersRequest() ) - //yunti mark varId + //internal version: replace varId begin + //internal version: replace varId end request.ProjectId = helper.IntInt64(d.Get("project_id").(int)) request.Zone = helper.String(d.Get("available_zone").(string)) request.VpcId = helper.String(d.Get("vpc_id").(string)) @@ -115,9 +117,11 @@ func resourceTencentCloudCynosdbClusterCreate(d *schema.ResourceData, meta inter } var chargeType int64 = 0 - //yunti mark varCharge + //internal version: replace varCharge begin + //internal version: replace varCharge end if v, ok := d.GetOk("charge_type"); ok { - //yunti mark strCharge + //internal version: replace strCharge begin + //internal version: replace strCharge end if v == CYNOSDB_CHARGE_TYPE_PREPAID { chargeType = 1 if vv, ok := d.GetOk("prepaid_period"); ok { @@ -145,7 +149,8 @@ func resourceTencentCloudCynosdbClusterCreate(d *schema.ResourceData, meta inter } } log.Printf("[CRITAL]%s api[%s] fail, reason:%s", logId, request.GetAction(), err.Error()) - //yunti mark byPass + //internal version: replace bpass begin + //internal version: replace bpass end return retryError(err) } return nil @@ -182,11 +187,13 @@ func resourceTencentCloudCynosdbClusterCreate(d *schema.ResourceData, meta inter if dealRes != nil && dealRes.Response != nil && len(dealRes.Response.BillingResourceInfos) != 1 { return fmt.Errorf("cynosdb cluster id count isn't 1") } - - id := *dealRes.Response.BillingResourceInfos[0].ClusterId //yunti mark normal + //internal version: replace normal begin + id := *dealRes.Response.BillingResourceInfos[0].ClusterId + //internal version: replace normal end d.SetId(id) - //yunti mark setTag + //internal version: replace setTag begin + //internal version: replace setTag end _, _, has, err := cynosdbService.DescribeClusterById(ctx, id) if err != nil { return err @@ -642,7 +649,8 @@ func resourceTencentCloudCynosdbClusterUpdate(d *schema.ResourceData, meta inter return err } - //yunti mark waitTag + //internal version: replace waitTag begin + //internal version: replace waitTag end } // update sg diff --git a/tencentcloud/resource_tc_elasticsearch_instance.go b/tencentcloud/resource_tc_elasticsearch_instance.go index 3831d6ef92..503314d756 100755 --- a/tencentcloud/resource_tc_elasticsearch_instance.go +++ b/tencentcloud/resource_tc_elasticsearch_instance.go @@ -278,7 +278,9 @@ func resourceTencentCloudElasticsearchInstanceCreate(d *schema.ResourceData, met request.InstanceName = helper.String(v.(string)) } if v, ok := d.GetOk("charge_type"); ok { - chargeType := v.(string) //yunti mark strCharge + //internal version: replace strCharge begin + chargeType := v.(string) + //internal version: replace strCharge end request.ChargeType = &chargeType if chargeType == ES_CHARGE_TYPE_PREPAID { if v, ok := d.GetOk("charge_period"); ok { @@ -367,8 +369,8 @@ func resourceTencentCloudElasticsearchInstanceCreate(d *schema.ResourceData, met if err != nil { log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), err.Error()) - //internal version: replace bypass begin - //internal version: replace bypass end + //internal version: replace bpass begin + //internal version: replace bpass end return retryError(err) } instanceId = *response.Response.InstanceId diff --git a/tencentcloud/resource_tc_mongodb_instance.go b/tencentcloud/resource_tc_mongodb_instance.go index 6b223b05c4..ff8d6c831d 100644 --- a/tencentcloud/resource_tc_mongodb_instance.go +++ b/tencentcloud/resource_tc_mongodb_instance.go @@ -14,7 +14,8 @@ import ( "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/ratelimit" ) -//yunti mark import +//internal version: replace import begin +//internal version: replace import end func resourceTencentCloudMongodbInstance() *schema.Resource { mongodbInstanceInfo := map[string]*schema.Schema{ @@ -220,7 +221,8 @@ func mongodbCreateInstanceByMonth(ctx context.Context, d *schema.ResourceData, m response, err = meta.(*TencentCloudClient).apiV3Conn.UseMongodbClient().CreateDBInstance(request) if err != nil { log.Printf("[CRITAL]%s api[%s] fail, reason:%s", logId, request.GetAction(), err.Error()) - //yunti mark bpass + //internal version: replace bpass begin + //internal version: replace bpass end return retryError(err) } return nil @@ -266,7 +268,8 @@ func resourceTencentCloudMongodbInstanceCreate(d *schema.ResourceData, meta inte instanceId := d.Id() - //yunti mark setTag + //internal version: replace setTag begin + //internal version: replace setTag end _, has, err := mongodbService.DescribeInstanceById(ctx, instanceId) if err != nil { return err @@ -289,14 +292,16 @@ func resourceTencentCloudMongodbInstanceCreate(d *schema.ResourceData, meta inte if !has { return fmt.Errorf("[CRITAL]%s creating mongodb instance failed, instance doesn't exist", logId) } - //yunti mark begin + //internal version: replace begin begin + //internal version: replace begin end if tags := helper.GetTags(d, "tags"); len(tags) > 0 { resourceName := BuildTagResourceName("mongodb", "instance", region, instanceId) if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil { return err } } - //yunti mark end + //internal version: replace end begin + //internal version: replace end end return resourceTencentCloudMongodbInstanceRead(d, meta) } diff --git a/tencentcloud/resource_tc_mysql_instance.go b/tencentcloud/resource_tc_mysql_instance.go index 4ea42c934b..f406629055 100644 --- a/tencentcloud/resource_tc_mysql_instance.go +++ b/tencentcloud/resource_tc_mysql_instance.go @@ -520,7 +520,8 @@ func mysqlCreateInstancePayByMonth(ctx context.Context, d *schema.ResourceData, request := cdb.NewCreateDBInstanceRequest() clientToken := helper.BuildToken() request.ClientToken = &clientToken - //yunti mark var + //internal version: replace var begin + //internal version: replace var end payType, oldOk := d.GetOkExists("pay_type") var period int @@ -549,7 +550,8 @@ func mysqlCreateInstancePayByMonth(ctx context.Context, d *schema.ResourceData, if inErr != nil { log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), inErr.Error()) - //yunti mark bpass + //internal version: replace bpass begin + //internal version: replace bpass end return retryError(inErr) } @@ -558,7 +560,8 @@ func mysqlCreateInstancePayByMonth(ctx context.Context, d *schema.ResourceData, } response = r - //yunti mark instanceId + //internal version: replace instanceId begin + //internal version: replace instanceId end return nil }) @@ -570,7 +573,8 @@ func mysqlCreateInstancePayByMonth(ctx context.Context, d *schema.ResourceData, if len(response.Response.InstanceIds) != 1 { return fmt.Errorf("mysql CreateDBInstance return len(InstanceIds) is not 1,but %d", len(response.Response.InstanceIds)) } - d.SetId(*response.Response.InstanceIds[0]) //yunti mark setId + d.SetId(*response.Response.InstanceIds[0]) //internal version: replace setId begin + //internal version: replace setId end return nil } @@ -628,7 +632,8 @@ func resourceTencentCloudMysqlInstanceCreate(d *schema.ResourceData, meta interf logId := getLogId(contextNil) ctx := context.WithValue(context.TODO(), logIdKey, logId) - mysqlService := MysqlService{client: meta.(*TencentCloudClient).apiV3Conn} //yunti mark mysqlServer + mysqlService := MysqlService{client: meta.(*TencentCloudClient).apiV3Conn} //internal version: replace mysqlServer begin + //internal version: replace mysqlServer end payType := getPayType(d).(int) @@ -648,7 +653,8 @@ func resourceTencentCloudMysqlInstanceCreate(d *schema.ResourceData, meta interf mysqlID := d.Id() - //yunti mark setTag + //internal version: replace setTag begin + //internal version: replace setTag end err := resource.Retry(7*readRetryTimeout, func() *resource.RetryError { mysqlInfo, err := mysqlService.DescribeDBInstanceById(ctx, mysqlID) if err != nil { @@ -1152,7 +1158,8 @@ func mysqlAllInstanceRoleUpdate(ctx context.Context, d *schema.ResourceData, met if err != nil { return err } - //yunti mark waitTag + //internal version: replace waitTag begin + //internal version: replace waitTag end } if d.HasChange("param_template_id") { diff --git a/tencentcloud/resource_tc_postgresql_instance.go b/tencentcloud/resource_tc_postgresql_instance.go index 3e4dfc34e9..629c471904 100644 --- a/tencentcloud/resource_tc_postgresql_instance.go +++ b/tencentcloud/resource_tc_postgresql_instance.go @@ -303,14 +303,16 @@ func resourceTencentCloudPostgresqlInstanceCreate(d *schema.ResourceData, meta i logId := getLogId(contextNil) ctx := context.WithValue(context.TODO(), logIdKey, logId) - - postgresqlService := PostgresqlService{client: meta.(*TencentCloudClient).apiV3Conn} //yunti mark clientCreate + //internal version: replace clientCreate begin + postgresqlService := PostgresqlService{client: meta.(*TencentCloudClient).apiV3Conn} + //internal version: replace clientCreate end var ( name = d.Get("name").(string) dbVersion = d.Get("engine_version").(string) payType = d.Get("charge_type").(string) - //yunti mark var + //internal version: replace var begin + //internal version: replace var end projectId = d.Get("project_id").(int) subnetId = d.Get("subnet_id").(string) vpcId = d.Get("vpc_id").(string) @@ -466,7 +468,8 @@ func resourceTencentCloudPostgresqlInstanceCreate(d *schema.ResourceData, meta i voucherIds, ) if inErr != nil { - //yunti mark bypass + //internal version: replace bpass begin + //internal version: replace bpass end return retryError(inErr) } return nil @@ -477,7 +480,8 @@ func resourceTencentCloudPostgresqlInstanceCreate(d *schema.ResourceData, meta i d.SetId(instanceId) - //yunti mark setTag + //internal version: replace setTag begin + //internal version: replace setTag end // check creation done err := resource.Retry(20*readRetryTimeout, func() *resource.RetryError { @@ -548,7 +552,8 @@ func resourceTencentCloudPostgresqlInstanceCreate(d *schema.ResourceData, meta i return checkErr } - //yunti mark move begin + //internal version: replace move begin + //internal version: replace move end begin if tags := helper.GetTags(d, "tags"); len(tags) > 0 { tcClient := meta.(*TencentCloudClient).apiV3Conn tagService := &TagService{client: tcClient} @@ -557,7 +562,8 @@ func resourceTencentCloudPostgresqlInstanceCreate(d *schema.ResourceData, meta i return err } } - //yunti mark move end + //internal version: replace move begin + //internal version: replace move end end // set pg params paramEntrys := make(map[string]string) @@ -620,8 +626,9 @@ func resourceTencentCloudPostgresqlInstanceUpdate(d *schema.ResourceData, meta i logId := getLogId(contextNil) ctx := context.WithValue(context.TODO(), logIdKey, logId) - - postgresqlService := PostgresqlService{client: meta.(*TencentCloudClient).apiV3Conn} //yunti mark clientUpdate + //internal version: replace clientUpdate begin + postgresqlService := PostgresqlService{client: meta.(*TencentCloudClient).apiV3Conn} + //internal version: replace clientUpdate end instanceId := d.Id() d.Partial(true) @@ -1066,16 +1073,19 @@ func resourceTencentCloudPostgresqlInstanceUpdate(d *schema.ResourceData, meta i oldValue, newValue := d.GetChange("tags") replaceTags, deleteTags := diffTags(oldValue.(map[string]interface{}), newValue.(map[string]interface{})) - //yunti mark move begin + //internal version: replace move begin + //internal version: replace move end begin tcClient := meta.(*TencentCloudClient).apiV3Conn tagService := &TagService{client: tcClient} - //yunti mark move end + //internal version: replace move begin + //internal version: replace move end end resourceName := BuildTagResourceName("postgres", "DBInstanceId", tcClient.Region, d.Id()) err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags) if err != nil { return err } - //yunti mark waitTag + //internal version: replace waitTag begin + //internal version: replace waitTag end } paramEntrys := make(map[string]string) if d.HasChange("max_standby_archive_delay") { diff --git a/tencentcloud/service_tencentcloud_tag.go b/tencentcloud/service_tencentcloud_tag.go index 1ff33767a1..f660645d84 100644 --- a/tencentcloud/service_tencentcloud_tag.go +++ b/tencentcloud/service_tencentcloud_tag.go @@ -12,7 +12,8 @@ import ( "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/ratelimit" ) -//yunti mark tagFmt +//internal version: replace tagFmt begin +//internal version: replace tagFmt end type TagService struct { client *connectivity.TencentCloudClient @@ -104,7 +105,8 @@ func (me *TagService) DescribeResourceTags(ctx context.Context, serviceType, res return } -//yunti mark waitTag +//internal version: replace waitTag begin +//internal version: replace waitTag end func diffTags(oldTags, newTags map[string]interface{}) (replaceTags map[string]string, deleteTags []string) { replaceTags = make(map[string]string) From 9be580b72208f66ff1a0eb6f88bb6796e650e46e Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Fri, 8 Dec 2023 17:54:51 +0800 Subject: [PATCH 25/45] feat: mark update --- scripts/yunti-code.yaml | 113 ++++++++++++++++++++- scripts/yunti-process-code.py | 58 +++++------ tencentcloud/resource_tc_redis_instance.go | 56 +++++++--- tencentcloud/resource_tc_tdmq_instance.go | 14 ++- 4 files changed, 197 insertions(+), 44 deletions(-) diff --git a/scripts/yunti-code.yaml b/scripts/yunti-code.yaml index d5222a820a..f8ad71e16f 100644 --- a/scripts/yunti-code.yaml +++ b/scripts/yunti-code.yaml @@ -465,4 +465,115 @@ go.mod: | require ( github.com/hashicorp/terraform-plugin-sdk v1.7.0 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/billing v1.0.809 - ) \ No newline at end of file + ) + + +tencentcloud/resource_tc_redis_instance.go: + import: " \"time\"" + tagComputed: " Computed: true," + clientCreate: " billingService := BillingService{client: client}" + redisServer: " masterZoneId, err := redisService.getZoneId(availabilityZone)" + varId: "var resourceId string" + bpass: | + log.Printf("[CRITAL]%s api[CreateInstances] fail, reason[%s]\n", logId, err.Error()) + + if chargeType == REDIS_CHARGE_TYPE_PREPAID { + regx := "\"dealNames\":\\[\"(.*)\"\\]" // dealNames:\["(.*)"\] + // query deal by bpass + id, inErr := billingService.QueryDealByBpass(ctx, regx, err) + if inErr != nil { + return inErr + } + // yunti prepaid user + if id != nil { + resourceId = *id + } + } else { + return err + } + getId: | + // normal user + if !billingService.isYunTiAccount() || chargeType == REDIS_CHARGE_TYPE_POSTPAID { + resourceId = *instanceIds[0] + } + setTag: | + // set tag before query the instance + if tags := helper.GetTags(d, "tags"); len(tags) > 0 { + log.Printf("[DEBUG]%s begin to modify tags, len(tags):[%v], tags:[%s]\n", logId, len(tags), tags) + for k, v := range tags { + log.Printf("[DEBUG]%s tags[k:%s, v:%s]", logId, k, v) + } + resourceName := BuildTagResourceName("redis", "instance", region, resourceId) + if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil { + log.Printf("[CRITAL]%s modify tags failed, reason:%s\n", logId, err.Error()) + return err + } + + // Wait the tags enabled + err = tagService.waitTagsEnable(ctx, "redis", "instance", resourceId, region, tags) + if err != nil { + return err + } + // wait for describe enable + time.Sleep(3 * time.Second) + } + clientRead: | + tcClient := meta.(*TencentCloudClient).apiV3Conn + service := RedisService{client: tcClient} + tagService := &TagService{client: tcClient} + + instanceId := d.Id() + redisFail: | + log.Printf("[WARN]%s resource `tencentcloud_redis_instance` [%s] not found, please check if it has been deleted.", logId, instanceId) + return nil + resourceTag: + var tags map[string]string + tags, err = tagService.DescribeResourceTags(ctx, "redis", "instance", tcClient.Region, instanceId) + setTagUpdate: "resourceName := BuildTagResourceName(\"redis\", \"instance\", region, d.Id())" + waitTag: | + // Wait the tags enabled + err := tagService.waitTagsEnable(ctx, "redis", "instance", d.Id(), region, replaceTags) + if err != nil { + return err + } + +tencentcloud/resource_tc_tdmq_instance.go: + client: | + var ( + logId = getLogId(contextNil) + ctx = context.WithValue(context.TODO(), logIdKey, logId) + client = meta.(*TencentCloudClient).apiV3Conn + tagService = TagService{client: client} + region = client.Region + ) + buildName: "resourceName := BuildTagResourceName(\"tdmq\", \"cluster\", region, clusterId)" + waitTag: | + // Wait the tags enabled + err = tagService.waitTagsEnable(ctx, "tdmq", "cluster", clusterId, region, tags) + if err != nil { + return err + } + var: | + var ( + logId = getLogId(contextNil) + ctx = context.WithValue(context.TODO(), logIdKey, logId) + client = meta.(*TencentCloudClient).apiV3Conn + service = TdmqService{client: client} + tagService = TagService{client: client} + region = client.Region + id = d.Id() + ) + setTag: + oldTags, newTags := d.GetChange("tags") + replaceTags, deleteTags := diffTags(oldTags.(map[string]interface{}), newTags.(map[string]interface{})) + resourceName := BuildTagResourceName("tdmq", "cluster", region, d.Id()) + if err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags); err != nil { + return err + } + + + // Wait the tags enabled + err := tagService.waitTagsEnable(ctx, "tdmq", "cluster", d.Id(), region, replaceTags) + if err != nil { + return err + } \ No newline at end of file diff --git a/scripts/yunti-process-code.py b/scripts/yunti-process-code.py index a7e128349d..da948f3cbd 100644 --- a/scripts/yunti-process-code.py +++ b/scripts/yunti-process-code.py @@ -19,20 +19,20 @@ def replace_code(dictionary, code): mark_str="//internal version: replace %s begin.*?//internal version: replace %s end"%(key,key) code = re.sub(r"%s"%mark_str, replacement_code, code, flags=re.DOTALL) return code - -def mark_replace_code(dictionary, code): - str="//yunti mark (\w+)" - strDe="//yunti mark %s" - - strRe="//internal version: replace %s begin\n//internal version: replace %s end" - matches = re.finditer(r"%s"%str, code, flags=re.DOTALL) - - for match in matches: - key = match.group(1) - print(key) - print("%s"%strDe) - code = re.sub(strDe%key, strRe%(key,key), code, flags=re.DOTALL) - return code +# +# def mark_replace_code(dictionary, code): +# str="//yunti mark (\w+)" +# strDe="//yunti mark %s" +# +# strRe="//internal version: replace %s begin\n//internal version: replace %s end" +# matches = re.finditer(r"%s"%str, code, flags=re.DOTALL) +# +# for match in matches: +# key = match.group(1) +# print(key) +# print("%s"%strDe) +# code = re.sub(strDe%key, strRe%(key,key), code, flags=re.DOTALL) +# return code def replace(dictionary): for file_name, content in dictionary.items(): @@ -57,19 +57,19 @@ def replace(dictionary): print("Success replace") - -def mark(dictionary): - for file_name, content in dictionary.items(): - if file_name in "tencentcloud/extension_billing.go" or file_name in "tencentcloud/service_tencentcloud_billing.go": - continue - with open("../" + file_name, "r") as file: - code = file.read() - # 替换代码 - replaced_code = mark_replace_code(content, code) - - # 将修改后的内容写回文件 - with open("../" + file_name, "w") as file: - file.write(replaced_code) +# +# def mark(dictionary): +# for file_name, content in dictionary.items(): +# if file_name in "tencentcloud/extension_billing.go" or file_name in "tencentcloud/service_tencentcloud_billing.go": +# continue +# with open("../" + file_name, "r") as file: +# code = file.read() +# # 替换代码 +# replaced_code = mark_replace_code(content, code) +# +# # 将修改后的内容写回文件 +# with open("../" + file_name, "w") as file: +# file.write(replaced_code) def run(): # 读取YAML文件 @@ -83,8 +83,8 @@ def run(): # 将JSON转换为字典 dictionary = json.loads(json_data) - # replace(dictionary) - mark(dictionary) + replace(dictionary) + # mark(dictionary) diff --git a/tencentcloud/resource_tc_redis_instance.go b/tencentcloud/resource_tc_redis_instance.go index 92d3b0e2f6..f8fcfff2bb 100644 --- a/tencentcloud/resource_tc_redis_instance.go +++ b/tencentcloud/resource_tc_redis_instance.go @@ -3,18 +3,20 @@ package tencentcloud import ( "context" "fmt" - "log" - "sort" - "strconv" - "strings" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" sdkErrors "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors" redis "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/redis/v20180412" "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" + "log" + "sort" + "strconv" + "strings" ) +//internal version: replace import begin +//internal version: replace import end + func resourceTencentCloudRedisInstance() *schema.Resource { types := []string{} for _, v := range REDIS_NAMES { @@ -176,8 +178,10 @@ func resourceTencentCloudRedisInstance() *schema.Resource { }, "tags": { - Type: schema.TypeMap, - Optional: true, + Type: schema.TypeMap, + Optional: true, + //internal version: replace tagComputed begin + //internal version: replace tagComputed end Description: "Instance tags.", }, @@ -257,6 +261,8 @@ func resourceTencentCloudRedisInstanceCreate(d *schema.ResourceData, meta interf client := meta.(*TencentCloudClient).apiV3Conn redisService := RedisService{client: client} tagService := TagService{client: client} + //internal version: replace clientCreate begin + //internal version: replace clientCreate end region := client.Region availabilityZone := d.Get("availability_zone").(string) @@ -381,13 +387,17 @@ func resourceTencentCloudRedisInstanceCreate(d *schema.ResourceData, meta interf requestSecurityGroup = append(requestSecurityGroup, v.(string)) } + //internal version: replace null begin service := RedisService{client: meta.(*TencentCloudClient).apiV3Conn} + //internal version: replace null end nodeInfo := make([]*redis.RedisNodeInfo, 0) if raw, ok := d.GetOk("replica_zone_ids"); ok { zoneIds := raw.([]interface{}) - + //internal version: replace redisServer begin masterZoneId, err := service.getZoneId(availabilityZone) + //internal version: replace redisServer end + if err != nil { return err } @@ -428,15 +438,25 @@ func resourceTencentCloudRedisInstanceCreate(d *schema.ResourceData, meta interf replicasReadonly, paramsTemplateId, ) - + //internal version: replace varId begin + //internal version: replace varId end if err != nil { + //internal version: replace bpass begin return err + //internal version: replace bpass end } if len(instanceIds) == 0 { return fmt.Errorf("redis api CreateInstances return empty redis id") } + + //internal version: replace getId begin var redisId = *instanceIds[0] + //internal version: replace getId end + + //internal version: replace setTag begin + //internal version: replace setTag begin + _, _, _, err = redisService.CheckRedisOnlineOk(ctx, redisId, 20*readRetryTimeout) if err != nil { @@ -445,12 +465,14 @@ func resourceTencentCloudRedisInstanceCreate(d *schema.ResourceData, meta interf } d.SetId(redisId) + //internal version: replace null begin if tags := helper.GetTags(d, "tags"); len(tags) > 0 { resourceName := BuildTagResourceName("redis", "instance", region, d.Id()) if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil { return err } } + //internal version: replace null end return resourceTencentCloudRedisInstanceRead(d, meta) } @@ -461,8 +483,10 @@ func resourceTencentCloudRedisInstanceRead(d *schema.ResourceData, meta interfac logId := getLogId(contextNil) ctx := context.WithValue(context.TODO(), logIdKey, logId) - + //internal version: replace clientRead begin service := RedisService{client: meta.(*TencentCloudClient).apiV3Conn} + //internal version: replace clientRead end + var onlineHas = true var ( has bool @@ -489,7 +513,9 @@ func resourceTencentCloudRedisInstanceRead(d *schema.ResourceData, meta interfac return nil }) if err != nil { + //internal version: replace redisFail begin return fmt.Errorf("Fail to get info from redis, reaseon %s", err.Error()) + //internal version: replace redisFail end } if !onlineHas { return nil @@ -586,10 +612,12 @@ func resourceTencentCloudRedisInstanceRead(d *schema.ResourceData, meta interfac _ = d.Set("replica_zone_ids", zoneIds) } } - + //internal version: replace resourceTag begin tcClient := meta.(*TencentCloudClient).apiV3Conn tagService := &TagService{client: tcClient} tags, err := tagService.DescribeResourceTags(ctx, "redis", "instance", tcClient.Region, d.Id()) + //internal version: replace resourceTag end + if err != nil { return err } @@ -892,11 +920,15 @@ func resourceTencentCloudRedisInstanceUpdate(d *schema.ResourceData, meta interf if d.HasChange("tags") { oldTags, newTags := d.GetChange("tags") replaceTags, deleteTags := diffTags(oldTags.(map[string]interface{}), newTags.(map[string]interface{})) - + //internal version: replace setTagUpdate begin resourceName := BuildTagResourceName("redis", "instance", region, id) + //internal version: replace setTagUpdate end if err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags); err != nil { return err } + + //internal version: replace waitTag begin + //internal version: replace waitTag end } d.Partial(false) diff --git a/tencentcloud/resource_tc_tdmq_instance.go b/tencentcloud/resource_tc_tdmq_instance.go index ae33ce3614..eb67a09adb 100644 --- a/tencentcloud/resource_tc_tdmq_instance.go +++ b/tencentcloud/resource_tc_tdmq_instance.go @@ -49,8 +49,10 @@ func resourceTencentCloudTdmqInstance() *schema.Resource { func resourceTencentCloudTdmqCreate(d *schema.ResourceData, meta interface{}) error { defer logElapsed("resource.tencentcloud_tdmq_instance.create")() + //internal version: replace client begin logId := getLogId(contextNil) ctx := context.WithValue(context.TODO(), logIdKey, logId) + //internal version: replace client end var ( request = tdmq.NewCreateClusterRequest() @@ -88,12 +90,18 @@ func resourceTencentCloudTdmqCreate(d *schema.ResourceData, meta interface{}) er clusterId := *response.Response.ClusterId if tags := helper.GetTags(d, "tags"); len(tags) > 0 { + //internal version: replace buildName begin tagService := TagService{client: meta.(*TencentCloudClient).apiV3Conn} region := meta.(*TencentCloudClient).apiV3Conn.Region resourceName := fmt.Sprintf("qcs::tdmq:%s:uin/:cluster/%s", region, clusterId) + //internal version: replace buildName end + if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil { return err } + + //internal version: replace waitTag begin + //internal version: replace waitTag end } d.SetId(clusterId) @@ -143,14 +151,14 @@ func resourceTencentCloudTdmqRead(d *schema.ResourceData, meta interface{}) erro func resourceTencentCloudTdmqUpdate(d *schema.ResourceData, meta interface{}) error { defer logElapsed("resource.tencentcloud_tdmq_instance.update")() - + //internal version: replace var begin logId := getLogId(contextNil) ctx := context.WithValue(context.TODO(), logIdKey, logId) id := d.Id() service := TdmqService{client: meta.(*TencentCloudClient).apiV3Conn} - + //internal version: replace var end var ( clusterName string remark string @@ -174,6 +182,7 @@ func resourceTencentCloudTdmqUpdate(d *schema.ResourceData, meta interface{}) er } if d.HasChange("tags") { + //internal version: replace tag begin tcClient := meta.(*TencentCloudClient).apiV3Conn tagService := &TagService{client: tcClient} oldTags, newTags := d.GetChange("tags") @@ -182,6 +191,7 @@ func resourceTencentCloudTdmqUpdate(d *schema.ResourceData, meta interface{}) er if err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags); err != nil { return err } + //internal version: replace tag end } return resourceTencentCloudTdmqRead(d, meta) } From 2f41b81c7a1f133bedc522abd878d476dbc3d421 Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Fri, 8 Dec 2023 18:04:25 +0800 Subject: [PATCH 26/45] feat: mark update --- tencentcloud/resource_tc_mysql_instance.go | 6 ++++-- tencentcloud/resource_tc_postgresql_instance.go | 12 ++++-------- tencentcloud/resource_tc_redis_instance.go | 2 +- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/tencentcloud/resource_tc_mysql_instance.go b/tencentcloud/resource_tc_mysql_instance.go index f406629055..be4fbf2c61 100644 --- a/tencentcloud/resource_tc_mysql_instance.go +++ b/tencentcloud/resource_tc_mysql_instance.go @@ -573,7 +573,8 @@ func mysqlCreateInstancePayByMonth(ctx context.Context, d *schema.ResourceData, if len(response.Response.InstanceIds) != 1 { return fmt.Errorf("mysql CreateDBInstance return len(InstanceIds) is not 1,but %d", len(response.Response.InstanceIds)) } - d.SetId(*response.Response.InstanceIds[0]) //internal version: replace setId begin + //internal version: replace setId begin + d.SetId(*response.Response.InstanceIds[0]) //internal version: replace setId end return nil } @@ -632,7 +633,8 @@ func resourceTencentCloudMysqlInstanceCreate(d *schema.ResourceData, meta interf logId := getLogId(contextNil) ctx := context.WithValue(context.TODO(), logIdKey, logId) - mysqlService := MysqlService{client: meta.(*TencentCloudClient).apiV3Conn} //internal version: replace mysqlServer begin + //internal version: replace mysqlServer begin + mysqlService := MysqlService{client: meta.(*TencentCloudClient).apiV3Conn} //internal version: replace mysqlServer end payType := getPayType(d).(int) diff --git a/tencentcloud/resource_tc_postgresql_instance.go b/tencentcloud/resource_tc_postgresql_instance.go index 629c471904..642b589eb9 100644 --- a/tencentcloud/resource_tc_postgresql_instance.go +++ b/tencentcloud/resource_tc_postgresql_instance.go @@ -552,8 +552,7 @@ func resourceTencentCloudPostgresqlInstanceCreate(d *schema.ResourceData, meta i return checkErr } - //internal version: replace move begin - //internal version: replace move end begin + //internal version: replace null begin if tags := helper.GetTags(d, "tags"); len(tags) > 0 { tcClient := meta.(*TencentCloudClient).apiV3Conn tagService := &TagService{client: tcClient} @@ -562,8 +561,7 @@ func resourceTencentCloudPostgresqlInstanceCreate(d *schema.ResourceData, meta i return err } } - //internal version: replace move begin - //internal version: replace move end end + //internal version: replace null end // set pg params paramEntrys := make(map[string]string) @@ -1073,12 +1071,10 @@ func resourceTencentCloudPostgresqlInstanceUpdate(d *schema.ResourceData, meta i oldValue, newValue := d.GetChange("tags") replaceTags, deleteTags := diffTags(oldValue.(map[string]interface{}), newValue.(map[string]interface{})) - //internal version: replace move begin - //internal version: replace move end begin + //internal version: replace null begin tcClient := meta.(*TencentCloudClient).apiV3Conn tagService := &TagService{client: tcClient} - //internal version: replace move begin - //internal version: replace move end end + //internal version: replace null end resourceName := BuildTagResourceName("postgres", "DBInstanceId", tcClient.Region, d.Id()) err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags) if err != nil { diff --git a/tencentcloud/resource_tc_redis_instance.go b/tencentcloud/resource_tc_redis_instance.go index f8fcfff2bb..07e41c5988 100644 --- a/tencentcloud/resource_tc_redis_instance.go +++ b/tencentcloud/resource_tc_redis_instance.go @@ -455,7 +455,7 @@ func resourceTencentCloudRedisInstanceCreate(d *schema.ResourceData, meta interf //internal version: replace getId end //internal version: replace setTag begin - //internal version: replace setTag begin + //internal version: replace setTag end _, _, _, err = redisService.CheckRedisOnlineOk(ctx, redisId, 20*readRetryTimeout) From ff844dec10b950ab8c6f4626bcf2827454f160af Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Fri, 8 Dec 2023 18:08:06 +0800 Subject: [PATCH 27/45] feat: mark update --- scripts/yunti-code.yaml | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/scripts/yunti-code.yaml b/scripts/yunti-code.yaml index f8ad71e16f..d1263ddf32 100644 --- a/scripts/yunti-code.yaml +++ b/scripts/yunti-code.yaml @@ -60,7 +60,7 @@ tencentcloud/resource_tc_cynosdb_cluster.go: // query deal by bpass resourceId, billErr := billingService.QueryDealByBpass(ctx, regx, err) if billErr != nil { - log.Printf("[CRITAL]%s api[QueryDealByBpass] fail, reason[%s]\n", logId, billErr.Error()) + log.Printf("[CRITAL]%s api[QueryDealByBpass] fail, reason[%s]\\n", logId, billErr.Error()) return resource.NonRetryableError(billErr) } // yunti prepaid user @@ -167,7 +167,7 @@ tencentcloud/resource_tc_mongodb_instance.go: bpass: | // query deal by bpass e, ok := err.(*sdkErrors.TencentCloudSDKError) - log.Printf("[DEBUG]%s query deal for PREPAID user, msg:[%s] \n", logId, e.Error()) + log.Printf("[DEBUG]%s query deal for PREPAID user, msg:[%s] \\n", logId, e.Error()) if ok && IsContains("InvalidParameterValue.InvalidTradeOperation", e.Code) { // yunti prepaid user @@ -204,7 +204,7 @@ tencentcloud/resource_tc_mysql_instance.go: regx := "dealNames:\\[\"(.*)\"\\]\\]," id, billErr := billingService.QueryDealByBpass(ctx, regx, inErr) if billErr != nil { - log.Printf("[CRITAL]%s api[DescribeDeals] fail, reason[%s]\n", logId, billErr.Error()) + log.Printf("[CRITAL]%s api[DescribeDeals] fail, reason[%s]\\n", logId, billErr.Error()) return resource.NonRetryableError(billErr) } // yunti prepaid user @@ -257,7 +257,7 @@ tencentcloud/resource_tc_postgresql_instance.go: // query deal by bpass id, billErr := billingService.QueryDealByBpass(ctx, regx, inErr) if billErr != nil { - log.Printf("[CRITAL]%s api[QueryDealByBpass] fail, reason[%s]\n", logId, billErr.Error()) + log.Printf("[CRITAL]%s api[QueryDealByBpass] fail, reason[%s]\\n", logId, billErr.Error()) return resource.NonRetryableError(billErr) } // yunti prepaid user @@ -364,7 +364,7 @@ tencentcloud/service_tencentcloud_billing.go: defer func() { if errRet != nil { - log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\\n", logId, "query object", request.ToJsonString(), errRet.Error()) } }() @@ -391,13 +391,13 @@ tencentcloud/service_tencentcloud_billing.go: } } if len(dealList) != 1 { - log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) return nil } deal = dealList[0] if in(*deal.Status, DEAL_TERMINATE_STATUS_CODE) { - log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) return nil } @@ -429,7 +429,7 @@ tencentcloud/service_tencentcloud_billing.go: } e, ok := msg.(*sdkErrors.TencentCloudSDKError) - log.Printf("[DEBUG]%s query deal for PREPAID user, msg:[%s] \n", logId, e.Error()) + log.Printf("[DEBUG]%s query deal for PREPAID user, msg:[%s] \\n", logId, e.Error()) if ok && IsContains(TRADE_RETRYABLE_ERROR, e.Code) { errStr := msg.Error() @@ -437,16 +437,16 @@ tencentcloud/service_tencentcloud_billing.go: re := regexp.MustCompile(dealRegx) result := re.FindStringSubmatch(errStr) for i, str := range result { - log.Printf("[DEBUG] FindStringSubmatch sub[%v]:%s,\n", i, str) + log.Printf("[DEBUG] FindStringSubmatch sub[%v]:%s,\\n", i, str) } dealId := re.FindStringSubmatch(errStr)[1] deal, billErr := me.DescribeDeals(ctx, dealId) if billErr != nil { - log.Printf("[CRITAL]%s api[DescribeDeals] fail, reason[%s]\n", logId, billErr.Error()) + log.Printf("[CRITAL]%s api[DescribeDeals] fail, reason[%s]\\n", logId, billErr.Error()) return nil, billErr } resourceId = deal.ResourceId[0] - log.Printf("[DEBUG]%s query deal for PREPAID user succeed, dealId:[%s] resourceId:[%s]\n", logId, dealId, *resourceId) + log.Printf("[DEBUG]%s query deal for PREPAID user succeed, dealId:[%s] resourceId:[%s]\\n", logId, dealId, *resourceId) return resourceId, nil } return @@ -475,7 +475,7 @@ tencentcloud/resource_tc_redis_instance.go: redisServer: " masterZoneId, err := redisService.getZoneId(availabilityZone)" varId: "var resourceId string" bpass: | - log.Printf("[CRITAL]%s api[CreateInstances] fail, reason[%s]\n", logId, err.Error()) + log.Printf("[CRITAL]%s api[CreateInstances] fail, reason[%s]\\n", logId, err.Error()) if chargeType == REDIS_CHARGE_TYPE_PREPAID { regx := "\"dealNames\":\\[\"(.*)\"\\]" // dealNames:\["(.*)"\] @@ -499,13 +499,13 @@ tencentcloud/resource_tc_redis_instance.go: setTag: | // set tag before query the instance if tags := helper.GetTags(d, "tags"); len(tags) > 0 { - log.Printf("[DEBUG]%s begin to modify tags, len(tags):[%v], tags:[%s]\n", logId, len(tags), tags) + log.Printf("[DEBUG]%s begin to modify tags, len(tags):[%v], tags:[%s]\\n", logId, len(tags), tags) for k, v := range tags { log.Printf("[DEBUG]%s tags[k:%s, v:%s]", logId, k, v) } resourceName := BuildTagResourceName("redis", "instance", region, resourceId) if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil { - log.Printf("[CRITAL]%s modify tags failed, reason:%s\n", logId, err.Error()) + log.Printf("[CRITAL]%s modify tags failed, reason:%s\\n", logId, err.Error()) return err } From 2a215289a78dfc2099d2cdc7b8c754ddf0635690 Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Fri, 8 Dec 2023 18:11:43 +0800 Subject: [PATCH 28/45] feat: mark update --- scripts/yunti-code.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/yunti-code.yaml b/scripts/yunti-code.yaml index d1263ddf32..41da1a6ae4 100644 --- a/scripts/yunti-code.yaml +++ b/scripts/yunti-code.yaml @@ -56,7 +56,7 @@ tencentcloud/resource_tc_cynosdb_cluster.go: strCharge: " chargeTypeStr = v.(string)" byPass: | if chargeTypeStr == CYNOSDB_CHARGE_TYPE_PREPAID { - regx := "\"dealNames\":\\[\"(.*)\"\\]" + regx := "\"dealNames\":\\\[\"(.*)\"\\\]" // query deal by bpass resourceId, billErr := billingService.QueryDealByBpass(ctx, regx, err) if billErr != nil { @@ -253,7 +253,7 @@ tencentcloud/resource_tc_postgresql_instance.go: log.Printf("[CRITAL]%s api[%s] fail, reason:%s", logId, "CreatePostgresqlInstance", inErr.Error()) if chargeType == COMMON_PAYTYPE_PREPAID { - regx := "\"dealNames\":\\[\"(.*)\"\\]" + regx := "\"dealNames\":\\\[\"(.*)\"\\\]" // query deal by bpass id, billErr := billingService.QueryDealByBpass(ctx, regx, inErr) if billErr != nil { @@ -478,7 +478,7 @@ tencentcloud/resource_tc_redis_instance.go: log.Printf("[CRITAL]%s api[CreateInstances] fail, reason[%s]\\n", logId, err.Error()) if chargeType == REDIS_CHARGE_TYPE_PREPAID { - regx := "\"dealNames\":\\[\"(.*)\"\\]" // dealNames:\["(.*)"\] + regx := "\"dealNames\":\\\[\"(.*)\"\\\]" // dealNames:\["(.*)"\] // query deal by bpass id, inErr := billingService.QueryDealByBpass(ctx, regx, err) if inErr != nil { From 16168b1b000e356f1cb67be20681d88d2c56b2d8 Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Fri, 8 Dec 2023 18:13:33 +0800 Subject: [PATCH 29/45] feat: mark update --- scripts/yunti-code.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/yunti-code.yaml b/scripts/yunti-code.yaml index 41da1a6ae4..370e4f1383 100644 --- a/scripts/yunti-code.yaml +++ b/scripts/yunti-code.yaml @@ -469,7 +469,7 @@ go.mod: | tencentcloud/resource_tc_redis_instance.go: - import: " \"time\"" + import: "import \"time\"" tagComputed: " Computed: true," clientCreate: " billingService := BillingService{client: client}" redisServer: " masterZoneId, err := redisService.getZoneId(availabilityZone)" From d5461b9f3e184fedfdd7f53de2f5851d8459824c Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Fri, 8 Dec 2023 18:15:06 +0800 Subject: [PATCH 30/45] feat: mark update --- scripts/yunti-code.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/yunti-code.yaml b/scripts/yunti-code.yaml index 370e4f1383..39c842c294 100644 --- a/scripts/yunti-code.yaml +++ b/scripts/yunti-code.yaml @@ -201,7 +201,7 @@ tencentcloud/resource_tc_mysql_instance.go: var instanceId string bpass: | // query deal by bpass - regx := "dealNames:\\[\"(.*)\"\\]\\]," + regx := "dealNames:\\\[\"(.*)\"\\\]\\]," id, billErr := billingService.QueryDealByBpass(ctx, regx, inErr) if billErr != nil { log.Printf("[CRITAL]%s api[DescribeDeals] fail, reason[%s]\\n", logId, billErr.Error()) @@ -526,7 +526,7 @@ tencentcloud/resource_tc_redis_instance.go: redisFail: | log.Printf("[WARN]%s resource `tencentcloud_redis_instance` [%s] not found, please check if it has been deleted.", logId, instanceId) return nil - resourceTag: + resourceTag: | var tags map[string]string tags, err = tagService.DescribeResourceTags(ctx, "redis", "instance", tcClient.Region, instanceId) setTagUpdate: "resourceName := BuildTagResourceName(\"redis\", \"instance\", region, d.Id())" From 263d3731ef8da263111cd9fed9e23bba126fb503 Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Fri, 8 Dec 2023 18:17:43 +0800 Subject: [PATCH 31/45] feat: mark update --- scripts/yunti-code.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scripts/yunti-code.yaml b/scripts/yunti-code.yaml index 39c842c294..7103665a25 100644 --- a/scripts/yunti-code.yaml +++ b/scripts/yunti-code.yaml @@ -536,6 +536,15 @@ tencentcloud/resource_tc_redis_instance.go: if err != nil { return err } + queryAndSetId: | + _, _, _, err = redisService.CheckRedisOnlineOk(ctx, resourceId, 20*readRetryTimeout) + + if err != nil { + log.Printf("[CRITAL]%s create redis task fail, reason:%s\n", logId, err.Error()) + return err + } + + d.SetId(resourceId) tencentcloud/resource_tc_tdmq_instance.go: client: | From 0084c21fab88162532addf3900de1bfcd99da9e9 Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Fri, 8 Dec 2023 18:36:15 +0800 Subject: [PATCH 32/45] feat: mark update --- scripts/yunti-code.yaml | 2 +- tencentcloud/resource_tc_redis_instance.go | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/yunti-code.yaml b/scripts/yunti-code.yaml index 7103665a25..63803d4f1f 100644 --- a/scripts/yunti-code.yaml +++ b/scripts/yunti-code.yaml @@ -201,7 +201,7 @@ tencentcloud/resource_tc_mysql_instance.go: var instanceId string bpass: | // query deal by bpass - regx := "dealNames:\\\[\"(.*)\"\\\]\\]," + regx := "dealNames:\\\[\"(.*)\"\\\]\\\]," id, billErr := billingService.QueryDealByBpass(ctx, regx, inErr) if billErr != nil { log.Printf("[CRITAL]%s api[DescribeDeals] fail, reason[%s]\\n", logId, billErr.Error()) diff --git a/tencentcloud/resource_tc_redis_instance.go b/tencentcloud/resource_tc_redis_instance.go index 07e41c5988..344fb11330 100644 --- a/tencentcloud/resource_tc_redis_instance.go +++ b/tencentcloud/resource_tc_redis_instance.go @@ -457,6 +457,7 @@ func resourceTencentCloudRedisInstanceCreate(d *schema.ResourceData, meta interf //internal version: replace setTag begin //internal version: replace setTag end + //internal version: replace queryAndSetId begin _, _, _, err = redisService.CheckRedisOnlineOk(ctx, redisId, 20*readRetryTimeout) if err != nil { @@ -464,6 +465,7 @@ func resourceTencentCloudRedisInstanceCreate(d *schema.ResourceData, meta interf return err } d.SetId(redisId) + //internal version: replace queryAndSetId end //internal version: replace null begin if tags := helper.GetTags(d, "tags"); len(tags) > 0 { From 3d650c002466396dfafb573dc41a379bb995c8c6 Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Fri, 8 Dec 2023 18:37:34 +0800 Subject: [PATCH 33/45] feat: mark update --- scripts/yunti-code.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/yunti-code.yaml b/scripts/yunti-code.yaml index 63803d4f1f..a9d2393128 100644 --- a/scripts/yunti-code.yaml +++ b/scripts/yunti-code.yaml @@ -540,7 +540,7 @@ tencentcloud/resource_tc_redis_instance.go: _, _, _, err = redisService.CheckRedisOnlineOk(ctx, resourceId, 20*readRetryTimeout) if err != nil { - log.Printf("[CRITAL]%s create redis task fail, reason:%s\n", logId, err.Error()) + log.Printf("[CRITAL]%s create redis task fail, reason:%s\\n", logId, err.Error()) return err } From 4095a7a33a9a1372b55d4decf55f419ac39363c3 Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Fri, 8 Dec 2023 18:44:32 +0800 Subject: [PATCH 34/45] feat: mark update --- scripts/yunti-code.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/yunti-code.yaml b/scripts/yunti-code.yaml index a9d2393128..aefcb33ea1 100644 --- a/scripts/yunti-code.yaml +++ b/scripts/yunti-code.yaml @@ -54,7 +54,7 @@ tencentcloud/resource_tc_cynosdb_cluster.go: varId: " var id string" varCharge: " var chargeTypeStr string" strCharge: " chargeTypeStr = v.(string)" - byPass: | + bpass: | if chargeTypeStr == CYNOSDB_CHARGE_TYPE_PREPAID { regx := "\"dealNames\":\\\[\"(.*)\"\\\]" // query deal by bpass From 9d40b65733ef589d2e7c33618db6b2f7db42de36 Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Fri, 8 Dec 2023 18:47:12 +0800 Subject: [PATCH 35/45] feat: mark update --- tencentcloud/resource_tc_tdmq_instance.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tencentcloud/resource_tc_tdmq_instance.go b/tencentcloud/resource_tc_tdmq_instance.go index eb67a09adb..0c4f329392 100644 --- a/tencentcloud/resource_tc_tdmq_instance.go +++ b/tencentcloud/resource_tc_tdmq_instance.go @@ -182,7 +182,7 @@ func resourceTencentCloudTdmqUpdate(d *schema.ResourceData, meta interface{}) er } if d.HasChange("tags") { - //internal version: replace tag begin + //internal version: replace setTag begin tcClient := meta.(*TencentCloudClient).apiV3Conn tagService := &TagService{client: tcClient} oldTags, newTags := d.GetChange("tags") @@ -191,7 +191,7 @@ func resourceTencentCloudTdmqUpdate(d *schema.ResourceData, meta interface{}) er if err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags); err != nil { return err } - //internal version: replace tag end + //internal version: replace setTag end } return resourceTencentCloudTdmqRead(d, meta) } From a316a0bdc38ae6e7a2dd71b6fe3230b43c2f64b2 Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Fri, 8 Dec 2023 18:50:52 +0800 Subject: [PATCH 36/45] feat: mark update --- scripts/yunti-code.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/yunti-code.yaml b/scripts/yunti-code.yaml index aefcb33ea1..e96ee145af 100644 --- a/scripts/yunti-code.yaml +++ b/scripts/yunti-code.yaml @@ -572,7 +572,7 @@ tencentcloud/resource_tc_tdmq_instance.go: region = client.Region id = d.Id() ) - setTag: + setTag: | oldTags, newTags := d.GetChange("tags") replaceTags, deleteTags := diffTags(oldTags.(map[string]interface{}), newTags.(map[string]interface{})) resourceName := BuildTagResourceName("tdmq", "cluster", region, d.Id()) From 78abe499fbae044dfed4d00c42c075fa82282ecf Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Fri, 8 Dec 2023 19:01:37 +0800 Subject: [PATCH 37/45] feat: mark update --- scripts/yunti-code.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/yunti-code.yaml b/scripts/yunti-code.yaml index e96ee145af..2fd5ba555f 100644 --- a/scripts/yunti-code.yaml +++ b/scripts/yunti-code.yaml @@ -327,7 +327,6 @@ tencentcloud/service_tencentcloud_tag.go: } return true } -# tencentcloud/service_tencentcloud_billing.go: all: | package tencentcloud From 85c10bdc2d9af6ca3fae40b0af2ddc77f4a99cf0 Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Fri, 8 Dec 2023 19:05:16 +0800 Subject: [PATCH 38/45] feat: mark update --- GNUmakefile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/GNUmakefile b/GNUmakefile index b74fe3138a..e6f52c24e9 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -198,3 +198,10 @@ changelog: ./scripts/generate-changelog.sh .PHONY: build sweep test testacc fmt fmtcheck lint tools test-compile doc hooks website website-lint website-test + +internal-build: + python ./scripts/yunti-process-code.py + yq eval 'keys' ./scripts/yunti-code.yaml | awk '{print $2}' |grep -v 'go.mod'| xargs -I {} goimports -w {} + yq eval 'keys' ./scripts/yunti-code.yaml | awk '{print $2}' |grep -v 'go.mod'| xargs -I {} go fmt {} + go mod vendor + goimports -w From 955833bf73e84217404154a87a2b3e990e76ae7e Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Fri, 8 Dec 2023 19:05:30 +0800 Subject: [PATCH 39/45] feat: mark update --- scripts/yunti-process-code.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/yunti-process-code.py b/scripts/yunti-process-code.py index da948f3cbd..5a257e9cda 100644 --- a/scripts/yunti-process-code.py +++ b/scripts/yunti-process-code.py @@ -37,22 +37,22 @@ def replace_code(dictionary, code): def replace(dictionary): for file_name, content in dictionary.items(): if file_name in "tencentcloud/extension_billing.go" or file_name in "tencentcloud/service_tencentcloud_billing.go": - with open("../" + file_name, "w") as file: + with open(file_name, "w") as file: file.write(content["all"]) continue if file_name in "go.mod": - with open("../" + file_name, "a") as file: + with open(file_name, "a") as file: file.write(content) # 打开文件并读取内容 - with open("../" + file_name, "r") as file: + with open(file_name, "r") as file: code = file.read() # 替换代码 replaced_code = replace_code(content, code) # 将修改后的内容写回文件 - with open("../" + file_name, "w") as file: + with open(file_name, "w") as file: file.write(replaced_code) print("Success replace") @@ -62,18 +62,18 @@ def replace(dictionary): # for file_name, content in dictionary.items(): # if file_name in "tencentcloud/extension_billing.go" or file_name in "tencentcloud/service_tencentcloud_billing.go": # continue -# with open("../" + file_name, "r") as file: +# with open( + file_name, "r") as file: # code = file.read() # # 替换代码 # replaced_code = mark_replace_code(content, code) # # # 将修改后的内容写回文件 -# with open("../" + file_name, "w") as file: +# with open( + file_name, "w") as file: # file.write(replaced_code) def run(): # 读取YAML文件 - yaml_file = "yunti-code.yaml" + yaml_file = "scripts/yunti-code.yaml" # 将YAML文件转换为JSON with open(yaml_file, "r") as f: From 6776acdf42cc9100ea52f513f324151f94c13cdb Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Fri, 8 Dec 2023 19:17:40 +0800 Subject: [PATCH 40/45] feat: mark update --- scripts/internal-version-build.sh | 4 ++++ 1 file changed, 4 insertions(+) create mode 100755 scripts/internal-version-build.sh diff --git a/scripts/internal-version-build.sh b/scripts/internal-version-build.sh new file mode 100755 index 0000000000..02183e9ab7 --- /dev/null +++ b/scripts/internal-version-build.sh @@ -0,0 +1,4 @@ +python ./scripts/yunti-process-code.py +go mod vendor +yq eval 'keys' ./scripts/yunti-code.yaml | awk '{print $2}' |grep -v 'go.mod'| xargs -I {} goimports -w {} +yq eval 'keys' ./scripts/yunti-code.yaml | awk '{print $2}' |grep -v 'go.mod'| xargs -I {} go fmt {} From eebb39792929b6ed5b541f123ead2ed1005a8e5d Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Fri, 8 Dec 2023 19:19:33 +0800 Subject: [PATCH 41/45] feat: make file --- GNUmakefile | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index e6f52c24e9..15fc8cbf67 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -200,8 +200,4 @@ changelog: .PHONY: build sweep test testacc fmt fmtcheck lint tools test-compile doc hooks website website-lint website-test internal-build: - python ./scripts/yunti-process-code.py - yq eval 'keys' ./scripts/yunti-code.yaml | awk '{print $2}' |grep -v 'go.mod'| xargs -I {} goimports -w {} - yq eval 'keys' ./scripts/yunti-code.yaml | awk '{print $2}' |grep -v 'go.mod'| xargs -I {} go fmt {} - go mod vendor - goimports -w + ./scripts/internal-version-build.sh From 6ee03835c2e7997e81c43ab53caf79fec63c24da Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Fri, 8 Dec 2023 19:24:59 +0800 Subject: [PATCH 42/45] feat: make file --- GNUmakefile | 4 +- scripts/internal-version-build.sh | 2 +- ...i-code.yaml => internal-version-code.yaml} | 0 scripts/internal-version-process.py | 47 ++++++++++ scripts/yunti-process-code.py | 91 ------------------- 5 files changed, 50 insertions(+), 94 deletions(-) rename scripts/{yunti-code.yaml => internal-version-code.yaml} (100%) create mode 100644 scripts/internal-version-process.py delete mode 100644 scripts/yunti-process-code.py diff --git a/GNUmakefile b/GNUmakefile index 15fc8cbf67..cfabd500fa 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -199,5 +199,5 @@ changelog: .PHONY: build sweep test testacc fmt fmtcheck lint tools test-compile doc hooks website website-lint website-test -internal-build: - ./scripts/internal-version-build.sh +internal-version-build: + ./scripts/internal-build.sh diff --git a/scripts/internal-version-build.sh b/scripts/internal-version-build.sh index 02183e9ab7..5ec7809722 100755 --- a/scripts/internal-version-build.sh +++ b/scripts/internal-version-build.sh @@ -1,4 +1,4 @@ -python ./scripts/yunti-process-code.py +python ./scripts/internal-version-process.py go mod vendor yq eval 'keys' ./scripts/yunti-code.yaml | awk '{print $2}' |grep -v 'go.mod'| xargs -I {} goimports -w {} yq eval 'keys' ./scripts/yunti-code.yaml | awk '{print $2}' |grep -v 'go.mod'| xargs -I {} go fmt {} diff --git a/scripts/yunti-code.yaml b/scripts/internal-version-code.yaml similarity index 100% rename from scripts/yunti-code.yaml rename to scripts/internal-version-code.yaml diff --git a/scripts/internal-version-process.py b/scripts/internal-version-process.py new file mode 100644 index 0000000000..101e789f31 --- /dev/null +++ b/scripts/internal-version-process.py @@ -0,0 +1,47 @@ +import yaml +import re + +YAML_FILE = "scripts/internal-version-code.yaml" +EXTENSION_BILLING_FILE = "tencentcloud/extension_billing.go" +SERVICE_TENCENTCLOUD_BILLING_FILE = "tencentcloud/service_tencentcloud_billing.go" +GO_MOD_FILE = "go.mod" +MARK_BEGIN = "//internal version: replace {} begin.*?//internal version: replace {} end" + +def replace_code(dictionary, code): + for key, value in dictionary.items(): + mark_str = MARK_BEGIN.format(key, key) + if key in code: + code = re.sub(mark_str, value, code, flags=re.DOTALL) + return code + +def replace(dictionary): + for file_name, content in dictionary.items(): + if file_name in [EXTENSION_BILLING_FILE, SERVICE_TENCENTCLOUD_BILLING_FILE]: + with open(file_name, "w") as file: + file.write(content["all"]) + continue + + if file_name == GO_MOD_FILE: + with open(file_name, "a") as file: + file.write(content) + continue + + with open(file_name, "r") as file: + code = file.read() + + replaced_code = replace_code(content, code) + + with open(file_name, "w") as file: + file.write(replaced_code) + + print("Success replace") + +def run(): + with open(YAML_FILE, "r") as f: + yaml_data = yaml.safe_load(f) + + dictionary = yaml_data + + replace(dictionary) + +run() \ No newline at end of file diff --git a/scripts/yunti-process-code.py b/scripts/yunti-process-code.py deleted file mode 100644 index 5a257e9cda..0000000000 --- a/scripts/yunti-process-code.py +++ /dev/null @@ -1,91 +0,0 @@ -import yaml -import json -import re - -def replace_code(dictionary, code): - - matches = re.finditer(r"//internal version: replace (\w+) begin.*?//internal version: replace \w+ end", code, flags=re.DOTALL) - - for match in matches: - key = match.group(1) - print(key) - if key in dictionary: - # 使用字典中的代码替换 - replacement_code = dictionary[key] - else: - replacement_code="" - # testKey=re.search(r"//internal version: replace \w+ begin.*?//internal version: replace \w+ end") - # print(testKey,replacement_code) - mark_str="//internal version: replace %s begin.*?//internal version: replace %s end"%(key,key) - code = re.sub(r"%s"%mark_str, replacement_code, code, flags=re.DOTALL) - return code -# -# def mark_replace_code(dictionary, code): -# str="//yunti mark (\w+)" -# strDe="//yunti mark %s" -# -# strRe="//internal version: replace %s begin\n//internal version: replace %s end" -# matches = re.finditer(r"%s"%str, code, flags=re.DOTALL) -# -# for match in matches: -# key = match.group(1) -# print(key) -# print("%s"%strDe) -# code = re.sub(strDe%key, strRe%(key,key), code, flags=re.DOTALL) -# return code - -def replace(dictionary): - for file_name, content in dictionary.items(): - if file_name in "tencentcloud/extension_billing.go" or file_name in "tencentcloud/service_tencentcloud_billing.go": - with open(file_name, "w") as file: - file.write(content["all"]) - continue - - if file_name in "go.mod": - with open(file_name, "a") as file: - file.write(content) - # 打开文件并读取内容 - with open(file_name, "r") as file: - code = file.read() - - # 替换代码 - replaced_code = replace_code(content, code) - - # 将修改后的内容写回文件 - with open(file_name, "w") as file: - file.write(replaced_code) - - print("Success replace") - -# -# def mark(dictionary): -# for file_name, content in dictionary.items(): -# if file_name in "tencentcloud/extension_billing.go" or file_name in "tencentcloud/service_tencentcloud_billing.go": -# continue -# with open( + file_name, "r") as file: -# code = file.read() -# # 替换代码 -# replaced_code = mark_replace_code(content, code) -# -# # 将修改后的内容写回文件 -# with open( + file_name, "w") as file: -# file.write(replaced_code) - -def run(): - # 读取YAML文件 - yaml_file = "scripts/yunti-code.yaml" - - # 将YAML文件转换为JSON - with open(yaml_file, "r") as f: - yaml_data = yaml.safe_load(f) - json_data = json.dumps(yaml_data) - - # 将JSON转换为字典 - dictionary = json.loads(json_data) - - replace(dictionary) - # mark(dictionary) - - - -run() From 008e3e9ffc4240ee824e272ab6b22c146e6495a9 Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Fri, 8 Dec 2023 19:36:20 +0800 Subject: [PATCH 43/45] feat: make file --- GNUmakefile | 2 +- scripts/internal-version-build.sh | 4 ++-- scripts/internal-version-process.py | 34 +++++++++++++++++++---------- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index cfabd500fa..1c3809c2b9 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -200,4 +200,4 @@ changelog: .PHONY: build sweep test testacc fmt fmtcheck lint tools test-compile doc hooks website website-lint website-test internal-version-build: - ./scripts/internal-build.sh + ./scripts/internal-version-build.sh diff --git a/scripts/internal-version-build.sh b/scripts/internal-version-build.sh index 5ec7809722..e1b2df6b5d 100755 --- a/scripts/internal-version-build.sh +++ b/scripts/internal-version-build.sh @@ -1,4 +1,4 @@ python ./scripts/internal-version-process.py go mod vendor -yq eval 'keys' ./scripts/yunti-code.yaml | awk '{print $2}' |grep -v 'go.mod'| xargs -I {} goimports -w {} -yq eval 'keys' ./scripts/yunti-code.yaml | awk '{print $2}' |grep -v 'go.mod'| xargs -I {} go fmt {} +yq eval 'keys' ./scripts/internal-version-code.yaml | awk '{print $2}' |grep -v 'go.mod'| xargs -I {} goimports -w {} +yq eval 'keys' ./scripts/internal-version-code.yaml | awk '{print $2}' |grep -v 'go.mod'| xargs -I {} go fmt {} diff --git a/scripts/internal-version-process.py b/scripts/internal-version-process.py index 101e789f31..5843de7160 100644 --- a/scripts/internal-version-process.py +++ b/scripts/internal-version-process.py @@ -1,31 +1,38 @@ import yaml import re +import json YAML_FILE = "scripts/internal-version-code.yaml" EXTENSION_BILLING_FILE = "tencentcloud/extension_billing.go" SERVICE_TENCENTCLOUD_BILLING_FILE = "tencentcloud/service_tencentcloud_billing.go" GO_MOD_FILE = "go.mod" -MARK_BEGIN = "//internal version: replace {} begin.*?//internal version: replace {} end" +MARK_MATCH = "//internal version: replace (\w+) begin.*?//internal version: replace \w+ end" +MARK_REPLACE = "//internal version: replace %s begin.*?//internal version: replace %s end" def replace_code(dictionary, code): - for key, value in dictionary.items(): - mark_str = MARK_BEGIN.format(key, key) - if key in code: - code = re.sub(mark_str, value, code, flags=re.DOTALL) + + matches = re.finditer(r"%s"%MARK_MATCH, code, flags=re.DOTALL) + + for match in matches: + key = match.group(1) + if key in dictionary: + replacement_code = dictionary[key] + else: + replacement_code="" + mark_str=MARK_REPLACE%(key,key) + code = re.sub(r"%s"%mark_str, replacement_code, code, flags=re.DOTALL) return code def replace(dictionary): for file_name, content in dictionary.items(): - if file_name in [EXTENSION_BILLING_FILE, SERVICE_TENCENTCLOUD_BILLING_FILE]: + if file_name in [SERVICE_TENCENTCLOUD_BILLING_FILE,EXTENSION_BILLING_FILE]: with open(file_name, "w") as file: file.write(content["all"]) continue - if file_name == GO_MOD_FILE: + if file_name in GO_MOD_FILE: with open(file_name, "a") as file: file.write(content) - continue - with open(file_name, "r") as file: code = file.read() @@ -37,11 +44,14 @@ def replace(dictionary): print("Success replace") def run(): - with open(YAML_FILE, "r") as f: + + yaml_file = YAML_FILE + with open(yaml_file, "r") as f: yaml_data = yaml.safe_load(f) + json_data = json.dumps(yaml_data) - dictionary = yaml_data + dictionary = json.loads(json_data) replace(dictionary) -run() \ No newline at end of file +run() From e52d1f31df4e981feaa7b9aceb4a268f91fb6d76 Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Mon, 11 Dec 2023 14:58:52 +0800 Subject: [PATCH 44/45] feat: update code yaml --- scripts/internal-version-code.yaml | 24 ++----- scripts/internal-version-process.py | 4 +- tencentcloud/connectivity/client.go | 12 ++-- tencentcloud/internal/helper/transform.go | 4 +- tencentcloud/provider.go | 8 +-- tencentcloud/resource_tc_cynosdb_cluster.go | 32 +++++----- .../resource_tc_elasticsearch_instance.go | 31 +++++---- tencentcloud/resource_tc_mongodb_instance.go | 20 +++--- tencentcloud/resource_tc_mysql_instance.go | 28 ++++---- .../resource_tc_postgresql_instance.go | 32 +++++----- tencentcloud/resource_tc_redis_instance.go | 64 +++++++++---------- tencentcloud/resource_tc_tdmq_instance.go | 24 ++++--- tencentcloud/service_tencentcloud_tag.go | 8 +-- 13 files changed, 140 insertions(+), 151 deletions(-) diff --git a/scripts/internal-version-code.yaml b/scripts/internal-version-code.yaml index 2fd5ba555f..041eb82956 100644 --- a/scripts/internal-version-code.yaml +++ b/scripts/internal-version-code.yaml @@ -99,13 +99,10 @@ tencentcloud/resource_tc_elasticsearch_instance.go: var: | var ( client = meta.(*TencentCloudClient).apiV3Conn - elasticsearchService = ElasticsearchService{client: client} billingService = BillingService{client: client} tagService = TagService{client: client} region = client.Region chargeType string - - request = es.NewCreateInstanceRequest() ) strCharge: "chargeType = v.(string)" reqTag: | @@ -547,13 +544,9 @@ tencentcloud/resource_tc_redis_instance.go: tencentcloud/resource_tc_tdmq_instance.go: client: | - var ( - logId = getLogId(contextNil) - ctx = context.WithValue(context.TODO(), logIdKey, logId) - client = meta.(*TencentCloudClient).apiV3Conn - tagService = TagService{client: client} - region = client.Region - ) + client := meta.(*TencentCloudClient).apiV3Conn + tagService := TagService{client: client} + region := client.Region buildName: "resourceName := BuildTagResourceName(\"tdmq\", \"cluster\", region, clusterId)" waitTag: | // Wait the tags enabled @@ -562,15 +555,8 @@ tencentcloud/resource_tc_tdmq_instance.go: return err } var: | - var ( - logId = getLogId(contextNil) - ctx = context.WithValue(context.TODO(), logIdKey, logId) - client = meta.(*TencentCloudClient).apiV3Conn - service = TdmqService{client: client} - tagService = TagService{client: client} - region = client.Region - id = d.Id() - ) + tagService := TagService{client: meta.(*TencentCloudClient).apiV3Conn} + region := meta.(*TencentCloudClient).apiV3Conn.Region setTag: | oldTags, newTags := d.GetChange("tags") replaceTags, deleteTags := diffTags(oldTags.(map[string]interface{}), newTags.(map[string]interface{})) diff --git a/scripts/internal-version-process.py b/scripts/internal-version-process.py index 5843de7160..e2bb4cc1bc 100644 --- a/scripts/internal-version-process.py +++ b/scripts/internal-version-process.py @@ -8,7 +8,7 @@ GO_MOD_FILE = "go.mod" MARK_MATCH = "//internal version: replace (\w+) begin.*?//internal version: replace \w+ end" MARK_REPLACE = "//internal version: replace %s begin.*?//internal version: replace %s end" - +ANNOTATION_TAIL=", please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation." def replace_code(dictionary, code): matches = re.finditer(r"%s"%MARK_MATCH, code, flags=re.DOTALL) @@ -20,7 +20,7 @@ def replace_code(dictionary, code): else: replacement_code="" mark_str=MARK_REPLACE%(key,key) - code = re.sub(r"%s"%mark_str, replacement_code, code, flags=re.DOTALL) + code = re.sub(r"%s"%mark_str+ANNOTATION_TAIL, replacement_code, code, flags=re.DOTALL) return code def replace(dictionary): diff --git a/tencentcloud/connectivity/client.go b/tencentcloud/connectivity/client.go index 80db8d550e..1d63b4d15d 100644 --- a/tencentcloud/connectivity/client.go +++ b/tencentcloud/connectivity/client.go @@ -103,8 +103,8 @@ import ( ssl "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/wss/v20180426" ) -//internal version: replace import begin -//internal version: replace import end +//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. +//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. const ( PROVIDER_CVM_REQUEST_TIMEOUT = "TENCENTCLOUD_CVM_REQUEST_TIMEOUT" @@ -199,8 +199,8 @@ type TencentCloudClient struct { trocketConn *trocket.Client biConn *bi.Client cdwpgConn *cdwpg.Client - //internal version: replace client begin - //internal version: replace client end + //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. + //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. } // NewClientProfile returns a new ClientProfile @@ -1376,8 +1376,8 @@ func (me *TencentCloudClient) UseCdwpgClient() *cdwpg.Client { return me.cdwpgConn } -//internal version: replace useClient begin -//internal version: replace useClient end +//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. +//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. func getEnvDefault(key string, defVal int) int { val, ex := os.LookupEnv(key) diff --git a/tencentcloud/internal/helper/transform.go b/tencentcloud/internal/helper/transform.go index 411d041b47..bec3864562 100644 --- a/tencentcloud/internal/helper/transform.go +++ b/tencentcloud/internal/helper/transform.go @@ -271,8 +271,8 @@ func StrToBool(s string) (i bool) { return } -//internal version: replace boolStr begin -//internal version: replace boolStr end +//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. +//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. func StrListToStr(strList []*string) string { res := "" diff --git a/tencentcloud/provider.go b/tencentcloud/provider.go index ff00e75460..82ccce0341 100644 --- a/tencentcloud/provider.go +++ b/tencentcloud/provider.go @@ -27,8 +27,8 @@ const ( PROVIDER_REGION = "TENCENTCLOUD_REGION" PROVIDER_PROTOCOL = "TENCENTCLOUD_PROTOCOL" PROVIDER_DOMAIN = "TENCENTCLOUD_DOMAIN" - //internal version: replace envYunti begin - //internal version: replace envYunti end + //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. + //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. PROVIDER_ASSUME_ROLE_ARN = "TENCENTCLOUD_ASSUME_ROLE_ARN" PROVIDER_ASSUME_ROLE_SESSION_NAME = "TENCENTCLOUD_ASSUME_ROLE_SESSION_NAME" PROVIDER_ASSUME_ROLE_SESSION_DURATION = "TENCENTCLOUD_ASSUME_ROLE_SESSION_DURATION" @@ -87,8 +87,8 @@ func Provider() *schema.Provider { DefaultFunc: schema.EnvDefaultFunc(PROVIDER_DOMAIN, nil), Description: "The root domain of the API request, Default is `tencentcloudapi.com`.", }, - //internal version: replace enableBpass begin - //internal version: replace enableBpass end + //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. + //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. "assume_role": { Type: schema.TypeSet, Optional: true, diff --git a/tencentcloud/resource_tc_cynosdb_cluster.go b/tencentcloud/resource_tc_cynosdb_cluster.go index 796e1de9ba..fb6ef6c174 100644 --- a/tencentcloud/resource_tc_cynosdb_cluster.go +++ b/tencentcloud/resource_tc_cynosdb_cluster.go @@ -39,12 +39,12 @@ func resourceTencentCloudCynosdbClusterCreate(d *schema.ResourceData, meta inter cynosdbService = CynosdbService{client: client} tagService = TagService{client: client} region = client.Region - //internal version: replace client begin - //internal version: replace client end + //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. + //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. request = cynosdb.NewCreateClustersRequest() ) - //internal version: replace varId begin - //internal version: replace varId end + //internal version: replace varId begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. + //internal version: replace varId end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. request.ProjectId = helper.IntInt64(d.Get("project_id").(int)) request.Zone = helper.String(d.Get("available_zone").(string)) request.VpcId = helper.String(d.Get("vpc_id").(string)) @@ -117,11 +117,11 @@ func resourceTencentCloudCynosdbClusterCreate(d *schema.ResourceData, meta inter } var chargeType int64 = 0 - //internal version: replace varCharge begin - //internal version: replace varCharge end + //internal version: replace varCharge begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. + //internal version: replace varCharge end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. if v, ok := d.GetOk("charge_type"); ok { - //internal version: replace strCharge begin - //internal version: replace strCharge end + //internal version: replace strCharge begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. + //internal version: replace strCharge end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. if v == CYNOSDB_CHARGE_TYPE_PREPAID { chargeType = 1 if vv, ok := d.GetOk("prepaid_period"); ok { @@ -149,8 +149,8 @@ func resourceTencentCloudCynosdbClusterCreate(d *schema.ResourceData, meta inter } } log.Printf("[CRITAL]%s api[%s] fail, reason:%s", logId, request.GetAction(), err.Error()) - //internal version: replace bpass begin - //internal version: replace bpass end + //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. + //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. return retryError(err) } return nil @@ -187,13 +187,13 @@ func resourceTencentCloudCynosdbClusterCreate(d *schema.ResourceData, meta inter if dealRes != nil && dealRes.Response != nil && len(dealRes.Response.BillingResourceInfos) != 1 { return fmt.Errorf("cynosdb cluster id count isn't 1") } - //internal version: replace normal begin + //internal version: replace normal begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. id := *dealRes.Response.BillingResourceInfos[0].ClusterId - //internal version: replace normal end + //internal version: replace normal end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. d.SetId(id) - //internal version: replace setTag begin - //internal version: replace setTag end + //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. + //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. _, _, has, err := cynosdbService.DescribeClusterById(ctx, id) if err != nil { return err @@ -649,8 +649,8 @@ func resourceTencentCloudCynosdbClusterUpdate(d *schema.ResourceData, meta inter return err } - //internal version: replace waitTag begin - //internal version: replace waitTag end + //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. + //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. } // update sg diff --git a/tencentcloud/resource_tc_elasticsearch_instance.go b/tencentcloud/resource_tc_elasticsearch_instance.go index 503314d756..c97dc84359 100755 --- a/tencentcloud/resource_tc_elasticsearch_instance.go +++ b/tencentcloud/resource_tc_elasticsearch_instance.go @@ -261,14 +261,13 @@ func resourceTencentCloudElasticsearchInstanceCreate(d *schema.ResourceData, met defer logElapsed("resource.tencentcloud_elasticsearch_instance.create")() logId := getLogId(contextNil) ctx := context.WithValue(context.TODO(), logIdKey, logId) - //internal version: replace null begin elasticsearchService := ElasticsearchService{ client: meta.(*TencentCloudClient).apiV3Conn, } request := es.NewCreateInstanceRequest() - //internal version: replace null end - //internal version: replace var begin - //internal version: replace var end + + //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. + //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. request.Zone = helper.String(d.Get("availability_zone").(string)) request.EsVersion = helper.String(d.Get("version").(string)) request.VpcId = helper.String(d.Get("vpc_id").(string)) @@ -278,9 +277,9 @@ func resourceTencentCloudElasticsearchInstanceCreate(d *schema.ResourceData, met request.InstanceName = helper.String(v.(string)) } if v, ok := d.GetOk("charge_type"); ok { - //internal version: replace strCharge begin + //internal version: replace strCharge begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. chargeType := v.(string) - //internal version: replace strCharge end + //internal version: replace strCharge end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. request.ChargeType = &chargeType if chargeType == ES_CHARGE_TYPE_PREPAID { if v, ok := d.GetOk("charge_period"); ok { @@ -360,8 +359,8 @@ func resourceTencentCloudElasticsearchInstanceCreate(d *schema.ResourceData, met request.NodeInfoList = append(request.NodeInfoList, &info) } } - //internal version: replace reqTag begin - //internal version: replace reqTag end + //internal version: replace reqTag begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. + //internal version: replace reqTag end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. instanceId := "" err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { ratelimit.Check(request.GetAction()) @@ -369,8 +368,8 @@ func resourceTencentCloudElasticsearchInstanceCreate(d *schema.ResourceData, met if err != nil { log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), err.Error()) - //internal version: replace bpass begin - //internal version: replace bpass end + //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. + //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. return retryError(err) } instanceId = *response.Response.InstanceId @@ -381,8 +380,8 @@ func resourceTencentCloudElasticsearchInstanceCreate(d *schema.ResourceData, met } d.SetId(instanceId) - //internal version: replace setTag begin - //internal version: replace setTag end + //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. + //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. instanceEmptyRetries := 5 err = resource.Retry(15*readRetryTimeout, func() *resource.RetryError { instance, errRet := elasticsearchService.DescribeInstanceById(ctx, instanceId) @@ -725,13 +724,13 @@ func resourceTencentCloudElasticsearchInstanceUpdate(d *schema.ResourceData, met } region := meta.(*TencentCloudClient).apiV3Conn.Region - //internal version: replace null begin + //internal version: replace null begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. resourceName := fmt.Sprintf("qcs::es:%s:uin/:instance/%s", region, instanceId) err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags) - //internal version: replace null end + //internal version: replace null end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. - //internal version: replace waitTag begin - //internal version: replace waitTag end + //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. + //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. if err != nil { return err diff --git a/tencentcloud/resource_tc_mongodb_instance.go b/tencentcloud/resource_tc_mongodb_instance.go index ff8d6c831d..c48bfd9b64 100644 --- a/tencentcloud/resource_tc_mongodb_instance.go +++ b/tencentcloud/resource_tc_mongodb_instance.go @@ -14,8 +14,8 @@ import ( "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/ratelimit" ) -//internal version: replace import begin -//internal version: replace import end +//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. +//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. func resourceTencentCloudMongodbInstance() *schema.Resource { mongodbInstanceInfo := map[string]*schema.Schema{ @@ -221,8 +221,8 @@ func mongodbCreateInstanceByMonth(ctx context.Context, d *schema.ResourceData, m response, err = meta.(*TencentCloudClient).apiV3Conn.UseMongodbClient().CreateDBInstance(request) if err != nil { log.Printf("[CRITAL]%s api[%s] fail, reason:%s", logId, request.GetAction(), err.Error()) - //internal version: replace bpass begin - //internal version: replace bpass end + //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. + //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. return retryError(err) } return nil @@ -268,8 +268,8 @@ func resourceTencentCloudMongodbInstanceCreate(d *schema.ResourceData, meta inte instanceId := d.Id() - //internal version: replace setTag begin - //internal version: replace setTag end + //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. + //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. _, has, err := mongodbService.DescribeInstanceById(ctx, instanceId) if err != nil { return err @@ -292,16 +292,16 @@ func resourceTencentCloudMongodbInstanceCreate(d *schema.ResourceData, meta inte if !has { return fmt.Errorf("[CRITAL]%s creating mongodb instance failed, instance doesn't exist", logId) } - //internal version: replace begin begin - //internal version: replace begin end + //internal version: replace begin begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. + //internal version: replace begin end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. if tags := helper.GetTags(d, "tags"); len(tags) > 0 { resourceName := BuildTagResourceName("mongodb", "instance", region, instanceId) if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil { return err } } - //internal version: replace end begin - //internal version: replace end end + //internal version: replace end begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. + //internal version: replace end end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. return resourceTencentCloudMongodbInstanceRead(d, meta) } diff --git a/tencentcloud/resource_tc_mysql_instance.go b/tencentcloud/resource_tc_mysql_instance.go index be4fbf2c61..6bb4bd7c4c 100644 --- a/tencentcloud/resource_tc_mysql_instance.go +++ b/tencentcloud/resource_tc_mysql_instance.go @@ -520,8 +520,8 @@ func mysqlCreateInstancePayByMonth(ctx context.Context, d *schema.ResourceData, request := cdb.NewCreateDBInstanceRequest() clientToken := helper.BuildToken() request.ClientToken = &clientToken - //internal version: replace var begin - //internal version: replace var end + //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. + //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. payType, oldOk := d.GetOkExists("pay_type") var period int @@ -550,8 +550,8 @@ func mysqlCreateInstancePayByMonth(ctx context.Context, d *schema.ResourceData, if inErr != nil { log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), inErr.Error()) - //internal version: replace bpass begin - //internal version: replace bpass end + //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. + //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. return retryError(inErr) } @@ -560,8 +560,8 @@ func mysqlCreateInstancePayByMonth(ctx context.Context, d *schema.ResourceData, } response = r - //internal version: replace instanceId begin - //internal version: replace instanceId end + //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. + //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. return nil }) @@ -573,9 +573,9 @@ func mysqlCreateInstancePayByMonth(ctx context.Context, d *schema.ResourceData, if len(response.Response.InstanceIds) != 1 { return fmt.Errorf("mysql CreateDBInstance return len(InstanceIds) is not 1,but %d", len(response.Response.InstanceIds)) } - //internal version: replace setId begin + //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. d.SetId(*response.Response.InstanceIds[0]) - //internal version: replace setId end + //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. return nil } @@ -633,9 +633,9 @@ func resourceTencentCloudMysqlInstanceCreate(d *schema.ResourceData, meta interf logId := getLogId(contextNil) ctx := context.WithValue(context.TODO(), logIdKey, logId) - //internal version: replace mysqlServer begin + //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. mysqlService := MysqlService{client: meta.(*TencentCloudClient).apiV3Conn} - //internal version: replace mysqlServer end + //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. payType := getPayType(d).(int) @@ -655,8 +655,8 @@ func resourceTencentCloudMysqlInstanceCreate(d *schema.ResourceData, meta interf mysqlID := d.Id() - //internal version: replace setTag begin - //internal version: replace setTag end + //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. + //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. err := resource.Retry(7*readRetryTimeout, func() *resource.RetryError { mysqlInfo, err := mysqlService.DescribeDBInstanceById(ctx, mysqlID) if err != nil { @@ -1160,8 +1160,8 @@ func mysqlAllInstanceRoleUpdate(ctx context.Context, d *schema.ResourceData, met if err != nil { return err } - //internal version: replace waitTag begin - //internal version: replace waitTag end + //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. + //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. } if d.HasChange("param_template_id") { diff --git a/tencentcloud/resource_tc_postgresql_instance.go b/tencentcloud/resource_tc_postgresql_instance.go index 642b589eb9..995fe85258 100644 --- a/tencentcloud/resource_tc_postgresql_instance.go +++ b/tencentcloud/resource_tc_postgresql_instance.go @@ -303,16 +303,16 @@ func resourceTencentCloudPostgresqlInstanceCreate(d *schema.ResourceData, meta i logId := getLogId(contextNil) ctx := context.WithValue(context.TODO(), logIdKey, logId) - //internal version: replace clientCreate begin + //internal version: replace clientCreate begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. postgresqlService := PostgresqlService{client: meta.(*TencentCloudClient).apiV3Conn} - //internal version: replace clientCreate end + //internal version: replace clientCreate end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. var ( name = d.Get("name").(string) dbVersion = d.Get("engine_version").(string) payType = d.Get("charge_type").(string) - //internal version: replace var begin - //internal version: replace var end + //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. + //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. projectId = d.Get("project_id").(int) subnetId = d.Get("subnet_id").(string) vpcId = d.Get("vpc_id").(string) @@ -468,8 +468,8 @@ func resourceTencentCloudPostgresqlInstanceCreate(d *schema.ResourceData, meta i voucherIds, ) if inErr != nil { - //internal version: replace bpass begin - //internal version: replace bpass end + //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. + //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. return retryError(inErr) } return nil @@ -480,8 +480,8 @@ func resourceTencentCloudPostgresqlInstanceCreate(d *schema.ResourceData, meta i d.SetId(instanceId) - //internal version: replace setTag begin - //internal version: replace setTag end + //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. + //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. // check creation done err := resource.Retry(20*readRetryTimeout, func() *resource.RetryError { @@ -552,7 +552,7 @@ func resourceTencentCloudPostgresqlInstanceCreate(d *schema.ResourceData, meta i return checkErr } - //internal version: replace null begin + //internal version: replace null begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. if tags := helper.GetTags(d, "tags"); len(tags) > 0 { tcClient := meta.(*TencentCloudClient).apiV3Conn tagService := &TagService{client: tcClient} @@ -561,7 +561,7 @@ func resourceTencentCloudPostgresqlInstanceCreate(d *schema.ResourceData, meta i return err } } - //internal version: replace null end + //internal version: replace null end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. // set pg params paramEntrys := make(map[string]string) @@ -624,9 +624,9 @@ func resourceTencentCloudPostgresqlInstanceUpdate(d *schema.ResourceData, meta i logId := getLogId(contextNil) ctx := context.WithValue(context.TODO(), logIdKey, logId) - //internal version: replace clientUpdate begin + //internal version: replace clientUpdate begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. postgresqlService := PostgresqlService{client: meta.(*TencentCloudClient).apiV3Conn} - //internal version: replace clientUpdate end + //internal version: replace clientUpdate end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. instanceId := d.Id() d.Partial(true) @@ -1071,17 +1071,17 @@ func resourceTencentCloudPostgresqlInstanceUpdate(d *schema.ResourceData, meta i oldValue, newValue := d.GetChange("tags") replaceTags, deleteTags := diffTags(oldValue.(map[string]interface{}), newValue.(map[string]interface{})) - //internal version: replace null begin + //internal version: replace null begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. tcClient := meta.(*TencentCloudClient).apiV3Conn tagService := &TagService{client: tcClient} - //internal version: replace null end + //internal version: replace null end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. resourceName := BuildTagResourceName("postgres", "DBInstanceId", tcClient.Region, d.Id()) err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags) if err != nil { return err } - //internal version: replace waitTag begin - //internal version: replace waitTag end + //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. + //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. } paramEntrys := make(map[string]string) if d.HasChange("max_standby_archive_delay") { diff --git a/tencentcloud/resource_tc_redis_instance.go b/tencentcloud/resource_tc_redis_instance.go index 344fb11330..e584b8798b 100644 --- a/tencentcloud/resource_tc_redis_instance.go +++ b/tencentcloud/resource_tc_redis_instance.go @@ -14,8 +14,8 @@ import ( "strings" ) -//internal version: replace import begin -//internal version: replace import end +//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. +//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. func resourceTencentCloudRedisInstance() *schema.Resource { types := []string{} @@ -180,8 +180,8 @@ func resourceTencentCloudRedisInstance() *schema.Resource { "tags": { Type: schema.TypeMap, Optional: true, - //internal version: replace tagComputed begin - //internal version: replace tagComputed end + //internal version: replace tagComputed begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. + //internal version: replace tagComputed end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. Description: "Instance tags.", }, @@ -261,8 +261,8 @@ func resourceTencentCloudRedisInstanceCreate(d *schema.ResourceData, meta interf client := meta.(*TencentCloudClient).apiV3Conn redisService := RedisService{client: client} tagService := TagService{client: client} - //internal version: replace clientCreate begin - //internal version: replace clientCreate end + //internal version: replace clientCreate begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. + //internal version: replace clientCreate end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. region := client.Region availabilityZone := d.Get("availability_zone").(string) @@ -387,16 +387,16 @@ func resourceTencentCloudRedisInstanceCreate(d *schema.ResourceData, meta interf requestSecurityGroup = append(requestSecurityGroup, v.(string)) } - //internal version: replace null begin + //internal version: replace null begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. service := RedisService{client: meta.(*TencentCloudClient).apiV3Conn} - //internal version: replace null end + //internal version: replace null end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. nodeInfo := make([]*redis.RedisNodeInfo, 0) if raw, ok := d.GetOk("replica_zone_ids"); ok { zoneIds := raw.([]interface{}) - //internal version: replace redisServer begin + //internal version: replace redisServer begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. masterZoneId, err := service.getZoneId(availabilityZone) - //internal version: replace redisServer end + //internal version: replace redisServer end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. if err != nil { return err @@ -438,26 +438,26 @@ func resourceTencentCloudRedisInstanceCreate(d *schema.ResourceData, meta interf replicasReadonly, paramsTemplateId, ) - //internal version: replace varId begin - //internal version: replace varId end + //internal version: replace varId begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. + //internal version: replace varId end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. if err != nil { - //internal version: replace bpass begin + //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. return err - //internal version: replace bpass end + //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. } if len(instanceIds) == 0 { return fmt.Errorf("redis api CreateInstances return empty redis id") } - //internal version: replace getId begin + //internal version: replace getId begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. var redisId = *instanceIds[0] - //internal version: replace getId end + //internal version: replace getId end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. - //internal version: replace setTag begin - //internal version: replace setTag end + //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. + //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. - //internal version: replace queryAndSetId begin + //internal version: replace queryAndSetId begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. _, _, _, err = redisService.CheckRedisOnlineOk(ctx, redisId, 20*readRetryTimeout) if err != nil { @@ -465,16 +465,16 @@ func resourceTencentCloudRedisInstanceCreate(d *schema.ResourceData, meta interf return err } d.SetId(redisId) - //internal version: replace queryAndSetId end + //internal version: replace queryAndSetId end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. - //internal version: replace null begin + //internal version: replace null begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. if tags := helper.GetTags(d, "tags"); len(tags) > 0 { resourceName := BuildTagResourceName("redis", "instance", region, d.Id()) if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil { return err } } - //internal version: replace null end + //internal version: replace null end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. return resourceTencentCloudRedisInstanceRead(d, meta) } @@ -485,9 +485,9 @@ func resourceTencentCloudRedisInstanceRead(d *schema.ResourceData, meta interfac logId := getLogId(contextNil) ctx := context.WithValue(context.TODO(), logIdKey, logId) - //internal version: replace clientRead begin + //internal version: replace clientRead begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. service := RedisService{client: meta.(*TencentCloudClient).apiV3Conn} - //internal version: replace clientRead end + //internal version: replace clientRead end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. var onlineHas = true var ( @@ -515,9 +515,9 @@ func resourceTencentCloudRedisInstanceRead(d *schema.ResourceData, meta interfac return nil }) if err != nil { - //internal version: replace redisFail begin + //internal version: replace redisFail begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. return fmt.Errorf("Fail to get info from redis, reaseon %s", err.Error()) - //internal version: replace redisFail end + //internal version: replace redisFail end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. } if !onlineHas { return nil @@ -614,11 +614,11 @@ func resourceTencentCloudRedisInstanceRead(d *schema.ResourceData, meta interfac _ = d.Set("replica_zone_ids", zoneIds) } } - //internal version: replace resourceTag begin + //internal version: replace resourceTag begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. tcClient := meta.(*TencentCloudClient).apiV3Conn tagService := &TagService{client: tcClient} tags, err := tagService.DescribeResourceTags(ctx, "redis", "instance", tcClient.Region, d.Id()) - //internal version: replace resourceTag end + //internal version: replace resourceTag end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. if err != nil { return err @@ -922,15 +922,15 @@ func resourceTencentCloudRedisInstanceUpdate(d *schema.ResourceData, meta interf if d.HasChange("tags") { oldTags, newTags := d.GetChange("tags") replaceTags, deleteTags := diffTags(oldTags.(map[string]interface{}), newTags.(map[string]interface{})) - //internal version: replace setTagUpdate begin + //internal version: replace setTagUpdate begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. resourceName := BuildTagResourceName("redis", "instance", region, id) - //internal version: replace setTagUpdate end + //internal version: replace setTagUpdate end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. if err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags); err != nil { return err } - //internal version: replace waitTag begin - //internal version: replace waitTag end + //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. + //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. } d.Partial(false) diff --git a/tencentcloud/resource_tc_tdmq_instance.go b/tencentcloud/resource_tc_tdmq_instance.go index 0c4f329392..28d01cabe3 100644 --- a/tencentcloud/resource_tc_tdmq_instance.go +++ b/tencentcloud/resource_tc_tdmq_instance.go @@ -49,10 +49,11 @@ func resourceTencentCloudTdmqInstance() *schema.Resource { func resourceTencentCloudTdmqCreate(d *schema.ResourceData, meta interface{}) error { defer logElapsed("resource.tencentcloud_tdmq_instance.create")() - //internal version: replace client begin logId := getLogId(contextNil) ctx := context.WithValue(context.TODO(), logIdKey, logId) - //internal version: replace client end + + //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. + //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. var ( request = tdmq.NewCreateClusterRequest() @@ -90,18 +91,18 @@ func resourceTencentCloudTdmqCreate(d *schema.ResourceData, meta interface{}) er clusterId := *response.Response.ClusterId if tags := helper.GetTags(d, "tags"); len(tags) > 0 { - //internal version: replace buildName begin + //internal version: replace buildName begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. tagService := TagService{client: meta.(*TencentCloudClient).apiV3Conn} region := meta.(*TencentCloudClient).apiV3Conn.Region resourceName := fmt.Sprintf("qcs::tdmq:%s:uin/:cluster/%s", region, clusterId) - //internal version: replace buildName end + //internal version: replace buildName end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil { return err } - //internal version: replace waitTag begin - //internal version: replace waitTag end + //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. + //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. } d.SetId(clusterId) @@ -151,14 +152,17 @@ func resourceTencentCloudTdmqRead(d *schema.ResourceData, meta interface{}) erro func resourceTencentCloudTdmqUpdate(d *schema.ResourceData, meta interface{}) error { defer logElapsed("resource.tencentcloud_tdmq_instance.update")() - //internal version: replace var begin + logId := getLogId(contextNil) ctx := context.WithValue(context.TODO(), logIdKey, logId) id := d.Id() service := TdmqService{client: meta.(*TencentCloudClient).apiV3Conn} - //internal version: replace var end + + //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. + //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. + var ( clusterName string remark string @@ -182,7 +186,7 @@ func resourceTencentCloudTdmqUpdate(d *schema.ResourceData, meta interface{}) er } if d.HasChange("tags") { - //internal version: replace setTag begin + //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. tcClient := meta.(*TencentCloudClient).apiV3Conn tagService := &TagService{client: tcClient} oldTags, newTags := d.GetChange("tags") @@ -191,7 +195,7 @@ func resourceTencentCloudTdmqUpdate(d *schema.ResourceData, meta interface{}) er if err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags); err != nil { return err } - //internal version: replace setTag end + //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. } return resourceTencentCloudTdmqRead(d, meta) } diff --git a/tencentcloud/service_tencentcloud_tag.go b/tencentcloud/service_tencentcloud_tag.go index f660645d84..281b6ed9b5 100644 --- a/tencentcloud/service_tencentcloud_tag.go +++ b/tencentcloud/service_tencentcloud_tag.go @@ -12,8 +12,8 @@ import ( "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/ratelimit" ) -//internal version: replace tagFmt begin -//internal version: replace tagFmt end +//internal version: replace tagFmt begin, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. +//internal version: replace tagFmt end, please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation. type TagService struct { client *connectivity.TencentCloudClient @@ -105,8 +105,8 @@ func (me *TagService) DescribeResourceTags(ctx context.Context, serviceType, res return } -//internal version: replace waitTag begin -//internal version: replace waitTag end +//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. +//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. func diffTags(oldTags, newTags map[string]interface{}) (replaceTags map[string]string, deleteTags []string) { replaceTags = make(map[string]string) From 33344ff6a016f5db012a9f0ed09feb914ccf66b2 Mon Sep 17 00:00:00 2001 From: Wmxs <54929266+WeiMengXS@users.noreply.github.com> Date: Mon, 11 Dec 2023 16:15:54 +0800 Subject: [PATCH 45/45] feat: fmt --- GNUmakefile | 2 - scripts/internal-version-build.sh | 4 - scripts/internal-version-code.yaml | 573 --------------------- scripts/internal-version-process.py | 57 -- tencentcloud/resource_tc_mysql_instance.go | 8 + tencentcloud/resource_tc_redis_instance.go | 9 +- 6 files changed, 13 insertions(+), 640 deletions(-) delete mode 100755 scripts/internal-version-build.sh delete mode 100644 scripts/internal-version-code.yaml delete mode 100644 scripts/internal-version-process.py diff --git a/GNUmakefile b/GNUmakefile index 1c3809c2b9..97bd4b5fa5 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -199,5 +199,3 @@ changelog: .PHONY: build sweep test testacc fmt fmtcheck lint tools test-compile doc hooks website website-lint website-test -internal-version-build: - ./scripts/internal-version-build.sh diff --git a/scripts/internal-version-build.sh b/scripts/internal-version-build.sh deleted file mode 100755 index e1b2df6b5d..0000000000 --- a/scripts/internal-version-build.sh +++ /dev/null @@ -1,4 +0,0 @@ -python ./scripts/internal-version-process.py -go mod vendor -yq eval 'keys' ./scripts/internal-version-code.yaml | awk '{print $2}' |grep -v 'go.mod'| xargs -I {} goimports -w {} -yq eval 'keys' ./scripts/internal-version-code.yaml | awk '{print $2}' |grep -v 'go.mod'| xargs -I {} go fmt {} diff --git a/scripts/internal-version-code.yaml b/scripts/internal-version-code.yaml deleted file mode 100644 index 041eb82956..0000000000 --- a/scripts/internal-version-code.yaml +++ /dev/null @@ -1,573 +0,0 @@ -tencentcloud/connectivity/client.go: - import: "import billing \"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/billing/v20180709\"" - client: "billingConn *billing.Client" - useClient: | - func (me *TencentCloudClient) UseBillingClient() *billing.Client { - if me.billingConn != nil { - return me.billingConn - } - - cpf := me.NewClientProfile(300) - me.billingConn, _ = billing.NewClient(me.Credential, me.Region, cpf) - me.billingConn.WithHttpTransport(&LogRoundTripper{}) - - return me.billingConn - } - -tencentcloud/extension_billing.go: - all: | - package tencentcloud - - var TRADE_RETRYABLE_ERROR = []string{ - "InternalError.TradeError", //mysql - "FailedOperation.PayFailed", //redis - } - - // deal status: https://cloud.tencent.com/document/product/555/19179 - - var DEAL_STATUS_CODE = []int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12} - - var DEAL_TERMINATE_STATUS_CODE = []int64{4, 5, 6, 7, 8, 9, 10, 11} - -tencentcloud/internal/helper/transform.go: - boolStr: | - func BoolToStr(b bool) (s string) { - s = "false" - if b { - s = "true" - } - return - } -tencentcloud/provider.go: - envYunti: " PROVIDER_ENABLE_YUNTI = \"TENCENTCLOUD_ENABLE_YUNTI\"" - enableBpass: | - "enable_bpass": { - Type: schema.TypeBool, - Optional: true, - Default: false, - DefaultFunc: schema.EnvDefaultFunc(PROVIDER_ENABLE_YUNTI, nil), - Description: "Use the yunti account or not, Default is `false`.", - }, -tencentcloud/resource_tc_cynosdb_cluster.go: - client: | - billingService = BillingService{client: client} - varId: " var id string" - varCharge: " var chargeTypeStr string" - strCharge: " chargeTypeStr = v.(string)" - bpass: | - if chargeTypeStr == CYNOSDB_CHARGE_TYPE_PREPAID { - regx := "\"dealNames\":\\\[\"(.*)\"\\\]" - // query deal by bpass - resourceId, billErr := billingService.QueryDealByBpass(ctx, regx, err) - if billErr != nil { - log.Printf("[CRITAL]%s api[QueryDealByBpass] fail, reason[%s]\\n", logId, billErr.Error()) - return resource.NonRetryableError(billErr) - } - // yunti prepaid user - if resourceId != nil { - id = *resourceId - return nil - } - } - normal: | - // normal user - if !billingService.isYunTiAccount() { - id = *dealRes.Response.BillingResourceInfos[0].ClusterId - } - setTag: | - // set tag before query the instance - if tags := helper.GetTags(d, "tags"); len(tags) > 0 { - resourceName := BuildTagResourceName("cynosdb", "cluster", region, id) - if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil { - return err - } - - // Wait the tags enabled - err = tagService.waitTagsEnable(ctx, "cynosdb", "cluster", id, region, tags) - if err != nil { - return err - } - } - waitTag: | - // Wait the tags enabled - err := tagService.waitTagsEnable(ctx, "cynosdb", "cluster", d.Id(), region, replaceTags) - if err != nil { - return err - } - -tencentcloud/resource_tc_elasticsearch_instance.go: - var: | - var ( - client = meta.(*TencentCloudClient).apiV3Conn - billingService = BillingService{client: client} - tagService = TagService{client: client} - region = client.Region - chargeType string - ) - strCharge: "chargeType = v.(string)" - reqTag: | - var tags map[string]string - if tags = helper.GetTags(d, "tags"); len(tags) > 0 { - if billingService.isYunTiAccount() { - request.TagList = make([]*es.TagInfo, 0, len(tags)) - for k, v := range tags { - tagInfo := &es.TagInfo{ - TagKey: helper.String(k), - TagValue: helper.String(v), - } - request.TagList = append(request.TagList, tagInfo) - } - } - } - bpass: | - if chargeType == ES_CHARGE_TYPE_PREPAID { - regx := "\"dealNames\":\\\[\"(.*)\"\\\]" - // query deal by bpass - id, billErr := billingService.QueryDealByBpass(ctx, regx, err) - if billErr != nil { - log.Printf("[CRITAL]%s api[QueryDealByBpass] fail, reason[%s]\\n", logId, billErr.Error()) - return resource.NonRetryableError(billErr) - } - // yunti prepaid user - if id != nil { - instanceId = *id - return nil - } - } - setTag: | - // set tag before query the instance - if len(tags) > 0 { - // resourceName := fmt.Sprintf("qcs::es:%s:uin/:instance/%s", region, instanceId) - resourceName := BuildTagResourceName("es", "instance", region, d.Id()) - if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil { - return err - } - - // Wait the tags enabled - err = tagService.waitTagsEnable(ctx, "es", "instance", d.Id(), region, tags) - if err != nil { - return err - } - } - waitTag: | - // resourceName := fmt.Sprintf("qcs::es:%s:uin/:instance/%s", region, instanceId) - resourceName := BuildTagResourceName("es", "instance", region, d.Id()) - if err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags); err != nil { - return err - } - - // Wait the tags enabled - err := tagService.waitTagsEnable(ctx, "es", "instance", d.Id(), region, replaceTags) - -tencentcloud/resource_tc_mongodb_instance.go: - import: "import sdkErrors \"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors\"" - bpass: | - // query deal by bpass - e, ok := err.(*sdkErrors.TencentCloudSDKError) - log.Printf("[DEBUG]%s query deal for PREPAID user, msg:[%s] \\n", logId, e.Error()) - - if ok && IsContains("InvalidParameterValue.InvalidTradeOperation", e.Code) { - // yunti prepaid user - return retryError(fmt.Errorf("[DEBUG] wait pass the bpass for yunti prepaid user, retry... error msg:[%s]", e.Message)) - } - - // if id != nil { - // // yunti prepaid user - // resourceId = *id - // return nil - // } - setTag: | - // set tag before query the instance - if tags := helper.GetTags(d, "tags"); len(tags) > 0 { - resourceName := BuildTagResourceName("mongodb", "instance", region, instanceId) - if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil { - return err - } - - // Wait the tags enabled - err := tagService.waitTagsEnable(ctx, "mongodb", "instance", instanceId, region, tags) - if err != nil { - return err - } - } - -tencentcloud/resource_tc_mysql_instance.go: - var: | - client := meta.(*TencentCloudClient).apiV3Conn - billingService := BillingService{client: client} - var instanceId string - bpass: | - // query deal by bpass - regx := "dealNames:\\\[\"(.*)\"\\\]\\\]," - id, billErr := billingService.QueryDealByBpass(ctx, regx, inErr) - if billErr != nil { - log.Printf("[CRITAL]%s api[DescribeDeals] fail, reason[%s]\\n", logId, billErr.Error()) - return resource.NonRetryableError(billErr) - } - // yunti prepaid user - if id != nil { - instanceId = *id - return nil - } - instanceId: "instanceId = *response.Response.InstanceIds[0]" - setId: "d.SetId(instanceId)" - mysqlServer: | - client := meta.(*TencentCloudClient).apiV3Conn - mysqlService := MysqlService{client: client} - tagService := &TagService{client: client} - setTag: | - // set tag before query the instance - if tags := helper.GetTags(d, "tags"); len(tags) > 0 { - resourceName := BuildTagResourceName("cdb", "instanceId", client.Region, d.Id()) - if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil { - return err - } - - // Wait the tags enabled - err := tagService.waitTagsEnable(ctx, "cdb", "instanceId", d.Id(), client.Region, tags) - if err != nil { - return err - } - // wait for describe enable - time.Sleep(3 * time.Second) - } - waitTag: - // Wait the tags enabled - err = tagService.waitTagsEnable(ctx, "cdb", "instanceId", d.Id(), region, replaceTags) - if err != nil { - return err - } - -tencentcloud/resource_tc_postgresql_instance.go: - clientCreate: | - client := meta.(*TencentCloudClient).apiV3Conn - postgresqlService := PostgresqlService{client: client} - tagService := TagService{client: client} - billingService := BillingService{client: client} - region := client.Region - var: "chargeType = d.Get(\"charge_type\").(string)" - bpass: | - log.Printf("[CRITAL]%s api[%s] fail, reason:%s", logId, "CreatePostgresqlInstance", inErr.Error()) - - if chargeType == COMMON_PAYTYPE_PREPAID { - regx := "\"dealNames\":\\\[\"(.*)\"\\\]" - // query deal by bpass - id, billErr := billingService.QueryDealByBpass(ctx, regx, inErr) - if billErr != nil { - log.Printf("[CRITAL]%s api[QueryDealByBpass] fail, reason[%s]\\n", logId, billErr.Error()) - return resource.NonRetryableError(billErr) - } - // yunti prepaid user - if id != nil { - instanceId = *id - return nil - } - } - setTag: | - // set tag before query the instance - if tags := helper.GetTags(d, "tags"); len(tags) > 0 { - resourceName := BuildTagResourceName("postgres", "DBInstanceId", region, d.Id()) - if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil { - return err - } - - // Wait the tags enabled - err := tagService.waitTagsEnable(ctx, "postgres", "DBInstanceId", d.Id(), region, tags) - if err != nil { - return err - } - } - clientUpdate: | - tcClient := meta.(*TencentCloudClient).apiV3Conn - tagService := &TagService{client: tcClient} - postgresqlService := PostgresqlService{client: tcClient} - waitTag: | - // Wait the tags enabled - err = tagService.waitTagsEnable(ctx, "postgres", "DBInstanceId", d.Id(), tcClient.Region, replaceTags) - if err != nil { - return err - } - - -tencentcloud/service_tencentcloud_tag.go: - tagFmt: "import \"fmt\"" - waitTag: | - func (me *TagService) waitTagsEnable(ctx context.Context, serviceType, resType, resId, region string, tags map[string]string) (retErr error) { - billingService := BillingService{client: me.client} - if !billingService.isYunTiAccount() { - return nil - } - retErr = resource.Retry(3*readRetryTimeout, func() *resource.RetryError { - ret, err := me.DescribeResourceTags(ctx, serviceType, resType, region, resId) - if err != nil { - return retryError(err) - } - if ret != nil { - if tagEqual(ret, tags) { - return nil - } - return resource.RetryableError(fmt.Errorf("the redis.instance %s is uncomplete, retry ...", resId)) - } - return resource.RetryableError(fmt.Errorf("the redis.instance %s's tags is nil, retry ...", resId)) - }) - return retErr - } - - func tagEqual(dst, orig map[string]string) bool { - for k := range orig { - if dst[k] == "" { - return false - } - if dst[k] != orig[k] { - return false - } - } - return true - } -tencentcloud/service_tencentcloud_billing.go: - all: | - package tencentcloud - - import ( - "context" - "fmt" - "log" - "os" - "regexp" - "strings" - "time" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" - "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/ratelimit" - - billing "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/billing/v20180709" - sdkErrors "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors" - "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/connectivity" - ) - - type BillingService struct { - client *connectivity.TencentCloudClient - } - - func (me *BillingService) DescribeDeals(ctx context.Context, dealId string) (deal *billing.Deal, errRet error) { - var ( - logId = getLogId(ctx) - request = billing.NewDescribeDealsByCondRequest() - response = billing.NewDescribeDealsByCondResponse() - dealList []*billing.Deal - ) - - defer func() { - if errRet != nil { - log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\\n", - logId, "query object", request.ToJsonString(), errRet.Error()) - } - }() - - request.OrderId = helper.String(dealId) - request.Limit = helper.IntInt64(20) - baseTime := time.Now().Local() - startTime := baseTime.AddDate(0, 0, -7).Format("2006-01-02 15:04:05") - endTime := baseTime.Format("2006-01-02 15:04:05") - request.StartTime = helper.String(startTime) - request.EndTime = helper.String(endTime) - - ratelimit.Check(request.GetAction()) - err := resource.Retry(20*readRetryTimeout, func() *resource.RetryError { - for _, dealState := range DEAL_STATUS_CODE { - request.Status = helper.Int64(dealState) - response, ee := me.client.UseBillingClient().DescribeDealsByCond(request) - if ee != nil { - return retryError(errRet, InternalError) - } - dealList = response.Response.Deals - if len(dealList) > 0 { - break - } - } - if len(dealList) != 1 { - log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\\n", - logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) - return nil - } - deal = dealList[0] - if in(*deal.Status, DEAL_TERMINATE_STATUS_CODE) { - log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\\n", - logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) - return nil - } - time.Sleep(3 * time.Second) - return resource.RetryableError(fmt.Errorf("deal status is not ready..., current is: %v", deal.Status)) - }) - - if err != nil { - errRet = err - return - } - return - } - - func (me *BillingService) isYunTiAccount() bool { - val, ok := os.LookupEnv(PROVIDER_ENABLE_YUNTI) - if ok && strings.ToLower(val) == "true" { - return true - } - return false - } - - //query deal by bpass - func (me *BillingService) QueryDealByBpass(ctx context.Context, dealRegx string, msg error) (resourceId *string, err error) { - logId := getLogId(ctx) - - if !me.isYunTiAccount() { - return - } - - e, ok := msg.(*sdkErrors.TencentCloudSDKError) - log.Printf("[DEBUG]%s query deal for PREPAID user, msg:[%s] \\n", logId, e.Error()) - - if ok && IsContains(TRADE_RETRYABLE_ERROR, e.Code) { - errStr := msg.Error() - - re := regexp.MustCompile(dealRegx) - result := re.FindStringSubmatch(errStr) - for i, str := range result { - log.Printf("[DEBUG] FindStringSubmatch sub[%v]:%s,\\n", i, str) - } - dealId := re.FindStringSubmatch(errStr)[1] - deal, billErr := me.DescribeDeals(ctx, dealId) - if billErr != nil { - log.Printf("[CRITAL]%s api[DescribeDeals] fail, reason[%s]\\n", logId, billErr.Error()) - return nil, billErr - } - resourceId = deal.ResourceId[0] - log.Printf("[DEBUG]%s query deal for PREPAID user succeed, dealId:[%s] resourceId:[%s]\\n", logId, dealId, *resourceId) - return resourceId, nil - } - return - } - - func in(target int64, intArr []int64) bool { - for _, element := range intArr { - if target == element { - return true - } - } - return false - } - -go.mod: | - require ( - github.com/hashicorp/terraform-plugin-sdk v1.7.0 - github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/billing v1.0.809 - ) - - -tencentcloud/resource_tc_redis_instance.go: - import: "import \"time\"" - tagComputed: " Computed: true," - clientCreate: " billingService := BillingService{client: client}" - redisServer: " masterZoneId, err := redisService.getZoneId(availabilityZone)" - varId: "var resourceId string" - bpass: | - log.Printf("[CRITAL]%s api[CreateInstances] fail, reason[%s]\\n", logId, err.Error()) - - if chargeType == REDIS_CHARGE_TYPE_PREPAID { - regx := "\"dealNames\":\\\[\"(.*)\"\\\]" // dealNames:\["(.*)"\] - // query deal by bpass - id, inErr := billingService.QueryDealByBpass(ctx, regx, err) - if inErr != nil { - return inErr - } - // yunti prepaid user - if id != nil { - resourceId = *id - } - } else { - return err - } - getId: | - // normal user - if !billingService.isYunTiAccount() || chargeType == REDIS_CHARGE_TYPE_POSTPAID { - resourceId = *instanceIds[0] - } - setTag: | - // set tag before query the instance - if tags := helper.GetTags(d, "tags"); len(tags) > 0 { - log.Printf("[DEBUG]%s begin to modify tags, len(tags):[%v], tags:[%s]\\n", logId, len(tags), tags) - for k, v := range tags { - log.Printf("[DEBUG]%s tags[k:%s, v:%s]", logId, k, v) - } - resourceName := BuildTagResourceName("redis", "instance", region, resourceId) - if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil { - log.Printf("[CRITAL]%s modify tags failed, reason:%s\\n", logId, err.Error()) - return err - } - - // Wait the tags enabled - err = tagService.waitTagsEnable(ctx, "redis", "instance", resourceId, region, tags) - if err != nil { - return err - } - // wait for describe enable - time.Sleep(3 * time.Second) - } - clientRead: | - tcClient := meta.(*TencentCloudClient).apiV3Conn - service := RedisService{client: tcClient} - tagService := &TagService{client: tcClient} - - instanceId := d.Id() - redisFail: | - log.Printf("[WARN]%s resource `tencentcloud_redis_instance` [%s] not found, please check if it has been deleted.", logId, instanceId) - return nil - resourceTag: | - var tags map[string]string - tags, err = tagService.DescribeResourceTags(ctx, "redis", "instance", tcClient.Region, instanceId) - setTagUpdate: "resourceName := BuildTagResourceName(\"redis\", \"instance\", region, d.Id())" - waitTag: | - // Wait the tags enabled - err := tagService.waitTagsEnable(ctx, "redis", "instance", d.Id(), region, replaceTags) - if err != nil { - return err - } - queryAndSetId: | - _, _, _, err = redisService.CheckRedisOnlineOk(ctx, resourceId, 20*readRetryTimeout) - - if err != nil { - log.Printf("[CRITAL]%s create redis task fail, reason:%s\\n", logId, err.Error()) - return err - } - - d.SetId(resourceId) - -tencentcloud/resource_tc_tdmq_instance.go: - client: | - client := meta.(*TencentCloudClient).apiV3Conn - tagService := TagService{client: client} - region := client.Region - buildName: "resourceName := BuildTagResourceName(\"tdmq\", \"cluster\", region, clusterId)" - waitTag: | - // Wait the tags enabled - err = tagService.waitTagsEnable(ctx, "tdmq", "cluster", clusterId, region, tags) - if err != nil { - return err - } - var: | - tagService := TagService{client: meta.(*TencentCloudClient).apiV3Conn} - region := meta.(*TencentCloudClient).apiV3Conn.Region - setTag: | - oldTags, newTags := d.GetChange("tags") - replaceTags, deleteTags := diffTags(oldTags.(map[string]interface{}), newTags.(map[string]interface{})) - resourceName := BuildTagResourceName("tdmq", "cluster", region, d.Id()) - if err := tagService.ModifyTags(ctx, resourceName, replaceTags, deleteTags); err != nil { - return err - } - - - // Wait the tags enabled - err := tagService.waitTagsEnable(ctx, "tdmq", "cluster", d.Id(), region, replaceTags) - if err != nil { - return err - } \ No newline at end of file diff --git a/scripts/internal-version-process.py b/scripts/internal-version-process.py deleted file mode 100644 index e2bb4cc1bc..0000000000 --- a/scripts/internal-version-process.py +++ /dev/null @@ -1,57 +0,0 @@ -import yaml -import re -import json - -YAML_FILE = "scripts/internal-version-code.yaml" -EXTENSION_BILLING_FILE = "tencentcloud/extension_billing.go" -SERVICE_TENCENTCLOUD_BILLING_FILE = "tencentcloud/service_tencentcloud_billing.go" -GO_MOD_FILE = "go.mod" -MARK_MATCH = "//internal version: replace (\w+) begin.*?//internal version: replace \w+ end" -MARK_REPLACE = "//internal version: replace %s begin.*?//internal version: replace %s end" -ANNOTATION_TAIL=", please do not modify this annotation and refrain from inserting any code between the beginning and end lines of the annotation." -def replace_code(dictionary, code): - - matches = re.finditer(r"%s"%MARK_MATCH, code, flags=re.DOTALL) - - for match in matches: - key = match.group(1) - if key in dictionary: - replacement_code = dictionary[key] - else: - replacement_code="" - mark_str=MARK_REPLACE%(key,key) - code = re.sub(r"%s"%mark_str+ANNOTATION_TAIL, replacement_code, code, flags=re.DOTALL) - return code - -def replace(dictionary): - for file_name, content in dictionary.items(): - if file_name in [SERVICE_TENCENTCLOUD_BILLING_FILE,EXTENSION_BILLING_FILE]: - with open(file_name, "w") as file: - file.write(content["all"]) - continue - - if file_name in GO_MOD_FILE: - with open(file_name, "a") as file: - file.write(content) - with open(file_name, "r") as file: - code = file.read() - - replaced_code = replace_code(content, code) - - with open(file_name, "w") as file: - file.write(replaced_code) - - print("Success replace") - -def run(): - - yaml_file = YAML_FILE - with open(yaml_file, "r") as f: - yaml_data = yaml.safe_load(f) - json_data = json.dumps(yaml_data) - - dictionary = json.loads(json_data) - - replace(dictionary) - -run() diff --git a/tencentcloud/resource_tc_mysql_instance.go b/tencentcloud/resource_tc_mysql_instance.go index 6bb4bd7c4c..2a3c20d940 100644 --- a/tencentcloud/resource_tc_mysql_instance.go +++ b/tencentcloud/resource_tc_mysql_instance.go @@ -656,6 +656,14 @@ func resourceTencentCloudMysqlInstanceCreate(d *schema.ResourceData, meta interf mysqlID := d.Id() //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. + if tags := helper.GetTags(d, "tags"); len(tags) > 0 { + tcClient := meta.(*TencentCloudClient).apiV3Conn + tagService := &TagService{client: tcClient} + resourceName := BuildTagResourceName("cdb", "instanceId", tcClient.Region, d.Id()) + if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil { + return err + } + } //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. err := resource.Retry(7*readRetryTimeout, func() *resource.RetryError { mysqlInfo, err := mysqlService.DescribeDBInstanceById(ctx, mysqlID) diff --git a/tencentcloud/resource_tc_redis_instance.go b/tencentcloud/resource_tc_redis_instance.go index e584b8798b..0de41c756f 100644 --- a/tencentcloud/resource_tc_redis_instance.go +++ b/tencentcloud/resource_tc_redis_instance.go @@ -3,15 +3,16 @@ package tencentcloud import ( "context" "fmt" + "log" + "sort" + "strconv" + "strings" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" sdkErrors "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors" redis "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/redis/v20180412" "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" - "log" - "sort" - "strconv" - "strings" ) //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.