From 9a11ecb4e567e3284ef825959f432eb420acda18 Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Tue, 25 Nov 2025 16:29:31 +0800 Subject: [PATCH 1/3] add --- tencentcloud/services/cvm/resource_tc_instance.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tencentcloud/services/cvm/resource_tc_instance.go b/tencentcloud/services/cvm/resource_tc_instance.go index 8fc61b9ac3..72c05a5096 100644 --- a/tencentcloud/services/cvm/resource_tc_instance.go +++ b/tencentcloud/services/cvm/resource_tc_instance.go @@ -579,9 +579,10 @@ func resourceTencentCloudInstanceCreate(d *schema.ResourceData, meta interface{} defer tccommon.LogElapsed("resource.tencentcloud_instance.create")() var ( - logId = tccommon.GetLogId(tccommon.ContextNil) - ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId) - cvmService = CvmService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId) + cvmService = CvmService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} + instanceChargeType string ) request := cvm.NewRunInstancesRequest() @@ -625,7 +626,7 @@ func resourceTencentCloudInstanceCreate(d *schema.ResourceData, meta interface{} } if v, ok := d.GetOk("instance_charge_type"); ok { - instanceChargeType := v.(string) + instanceChargeType = v.(string) request.InstanceChargeType = &instanceChargeType if instanceChargeType == CVM_CHARGE_TYPE_PREPAID || instanceChargeType == CVM_CHARGE_TYPE_UNDERWRITE { request.InstanceChargePrepaid = &cvm.InstanceChargePrepaid{} @@ -827,6 +828,10 @@ func resourceTencentCloudInstanceCreate(d *schema.ResourceData, meta interface{} if deleteWithInstance, ok := value["delete_with_instance"]; ok { deleteWithInstanceBool := deleteWithInstance.(bool) + if (instanceChargeType != CVM_CHARGE_TYPE_POSTPAID) && deleteWithInstanceBool { + return fmt.Errorf("param `delete_with_instance` only can be true when `instance_charge_type` is %s", CVM_CHARGE_TYPE_POSTPAID) + } + dataDisk.DeleteWithInstance = &deleteWithInstanceBool } From 434ad5d9dcf039ebf28ebab6021f5e48c4becc6a Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Tue, 25 Nov 2025 16:31:06 +0800 Subject: [PATCH 2/3] add --- .changelog/3614.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/3614.txt diff --git a/.changelog/3614.txt b/.changelog/3614.txt new file mode 100644 index 0000000000..95869f624b --- /dev/null +++ b/.changelog/3614.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/tencentcloud_instance: optimiz create function code logic +``` \ No newline at end of file From fbd98b42e14c44a6d2e8f155368ce2deb9bde7f7 Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Tue, 25 Nov 2025 16:34:01 +0800 Subject: [PATCH 3/3] add --- tencentcloud/services/cvm/resource_tc_instance.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tencentcloud/services/cvm/resource_tc_instance.go b/tencentcloud/services/cvm/resource_tc_instance.go index 72c05a5096..196bc4c8d5 100644 --- a/tencentcloud/services/cvm/resource_tc_instance.go +++ b/tencentcloud/services/cvm/resource_tc_instance.go @@ -582,7 +582,7 @@ func resourceTencentCloudInstanceCreate(d *schema.ResourceData, meta interface{} logId = tccommon.GetLogId(tccommon.ContextNil) ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId) cvmService = CvmService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} - instanceChargeType string + instanceChargeType = CVM_CHARGE_TYPE_POSTPAID ) request := cvm.NewRunInstancesRequest()