Skip to content

Commit f85032c

Browse files
authored
fix(cvm): [128831586] tencentcloud_instance optimiz create function code logic (#3614)
* add * add * add
1 parent ef31b07 commit f85032c

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

.changelog/3614.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_instance: optimiz create function code logic
3+
```

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

Comments
 (0)