@@ -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 = CVM_CHARGE_TYPE_POSTPAID
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