Skip to content

Commit 6a0db71

Browse files
authored
Merge pull request #737 from tencentcloudstack/fix/cvm-spot-json
fix: cvm - omit field if spot arguments empty
2 parents 53ca84e + ac5be23 commit 6a0db71

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

tencentcloud/resource_tc_instance.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -557,14 +557,18 @@ func resourceTencentCloudInstanceCreate(d *schema.ResourceData, meta interface{}
557557
}
558558
}
559559
if instanceChargeType == CVM_CHARGE_TYPE_SPOTPAID {
560-
request.InstanceMarketOptions = &cvm.InstanceMarketOptionsRequest{}
561-
request.InstanceMarketOptions.MarketType = helper.String(CVM_MARKET_TYPE_SPOT)
562-
request.InstanceMarketOptions.SpotOptions = &cvm.SpotMarketOptions{}
563-
if v, ok := d.GetOk("spot_instance_type"); ok {
564-
request.InstanceMarketOptions.SpotOptions.SpotInstanceType = helper.String(strings.ToLower(v.(string)))
560+
spotInstanceType, sitOk := d.GetOk("spot_instance_type")
561+
spotMaxPrice, smpOk := d.GetOk("spot_max_price")
562+
if sitOk || smpOk {
563+
request.InstanceMarketOptions = &cvm.InstanceMarketOptionsRequest{}
564+
request.InstanceMarketOptions.MarketType = helper.String(CVM_MARKET_TYPE_SPOT)
565+
request.InstanceMarketOptions.SpotOptions = &cvm.SpotMarketOptions{}
565566
}
566-
if v, ok := d.GetOk("spot_max_price"); ok {
567-
request.InstanceMarketOptions.SpotOptions.MaxPrice = helper.String(v.(string))
567+
if sitOk {
568+
request.InstanceMarketOptions.SpotOptions.SpotInstanceType = helper.String(strings.ToLower(spotInstanceType.(string)))
569+
}
570+
if smpOk {
571+
request.InstanceMarketOptions.SpotOptions.MaxPrice = helper.String(spotMaxPrice.(string))
568572
}
569573
}
570574
if instanceChargeType == CVM_CHARGE_TYPE_CDHPAID {

0 commit comments

Comments
 (0)