From ac5be2310df5306e0c355a066998cf281801a728 Mon Sep 17 00:00:00 2001 From: Kagashino Date: Tue, 16 Nov 2021 19:35:31 +0800 Subject: [PATCH] fix: cvm - omit field if spot arguments empty --- tencentcloud/resource_tc_instance.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tencentcloud/resource_tc_instance.go b/tencentcloud/resource_tc_instance.go index c73a5df687..c9e38083fd 100644 --- a/tencentcloud/resource_tc_instance.go +++ b/tencentcloud/resource_tc_instance.go @@ -557,14 +557,18 @@ func resourceTencentCloudInstanceCreate(d *schema.ResourceData, meta interface{} } } if instanceChargeType == CVM_CHARGE_TYPE_SPOTPAID { - request.InstanceMarketOptions = &cvm.InstanceMarketOptionsRequest{} - request.InstanceMarketOptions.MarketType = helper.String(CVM_MARKET_TYPE_SPOT) - request.InstanceMarketOptions.SpotOptions = &cvm.SpotMarketOptions{} - if v, ok := d.GetOk("spot_instance_type"); ok { - request.InstanceMarketOptions.SpotOptions.SpotInstanceType = helper.String(strings.ToLower(v.(string))) + spotInstanceType, sitOk := d.GetOk("spot_instance_type") + spotMaxPrice, smpOk := d.GetOk("spot_max_price") + if sitOk || smpOk { + request.InstanceMarketOptions = &cvm.InstanceMarketOptionsRequest{} + request.InstanceMarketOptions.MarketType = helper.String(CVM_MARKET_TYPE_SPOT) + request.InstanceMarketOptions.SpotOptions = &cvm.SpotMarketOptions{} } - if v, ok := d.GetOk("spot_max_price"); ok { - request.InstanceMarketOptions.SpotOptions.MaxPrice = helper.String(v.(string)) + if sitOk { + request.InstanceMarketOptions.SpotOptions.SpotInstanceType = helper.String(strings.ToLower(spotInstanceType.(string))) + } + if smpOk { + request.InstanceMarketOptions.SpotOptions.MaxPrice = helper.String(spotMaxPrice.(string)) } } if instanceChargeType == CVM_CHARGE_TYPE_CDHPAID {