Skip to content

Commit 9a11ecb

Browse files
committed
add
1 parent 228d331 commit 9a11ecb

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

tencentcloud/services/cvm/resource_tc_instance.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -579,9 +579,10 @@ func resourceTencentCloudInstanceCreate(d *schema.ResourceData, meta interface{}
579579
defer tccommon.LogElapsed("resource.tencentcloud_instance.create")()
580580

581581
var (
582-
logId = tccommon.GetLogId(tccommon.ContextNil)
583-
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
584-
cvmService = CvmService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
582+
logId = tccommon.GetLogId(tccommon.ContextNil)
583+
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
584+
cvmService = CvmService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
585+
instanceChargeType string
585586
)
586587

587588
request := cvm.NewRunInstancesRequest()
@@ -625,7 +626,7 @@ func resourceTencentCloudInstanceCreate(d *schema.ResourceData, meta interface{}
625626
}
626627

627628
if v, ok := d.GetOk("instance_charge_type"); ok {
628-
instanceChargeType := v.(string)
629+
instanceChargeType = v.(string)
629630
request.InstanceChargeType = &instanceChargeType
630631
if instanceChargeType == CVM_CHARGE_TYPE_PREPAID || instanceChargeType == CVM_CHARGE_TYPE_UNDERWRITE {
631632
request.InstanceChargePrepaid = &cvm.InstanceChargePrepaid{}
@@ -827,6 +828,10 @@ func resourceTencentCloudInstanceCreate(d *schema.ResourceData, meta interface{}
827828

828829
if deleteWithInstance, ok := value["delete_with_instance"]; ok {
829830
deleteWithInstanceBool := deleteWithInstance.(bool)
831+
if (instanceChargeType != CVM_CHARGE_TYPE_POSTPAID) && deleteWithInstanceBool {
832+
return fmt.Errorf("param `delete_with_instance` only can be true when `instance_charge_type` is %s", CVM_CHARGE_TYPE_POSTPAID)
833+
}
834+
830835
dataDisk.DeleteWithInstance = &deleteWithInstanceBool
831836
}
832837

0 commit comments

Comments
 (0)