Skip to content

Commit 20b5283

Browse files
tongyimingmikatong
andauthored
fix: reserved_instance (#916)
* fix: reserved_instance * fix: tke unit test * fix: reserved instance * fix reserved_instance * fix: rollback tks unit test * fix: update vendor Co-authored-by: mikatong <[email protected]>
1 parent c9b58f8 commit 20b5283

File tree

13 files changed

+703
-579
lines changed

13 files changed

+703
-579
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ require (
3030
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.283
3131
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.199
3232
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.377
33-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.383
34-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.351
33+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.385
34+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.385
3535
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.359
3636
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dayu v1.0.335
3737
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dc v1.0.199

go.sum

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,10 +518,18 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.378 h1:o+GK
518518
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.378/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
519519
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.383 h1:1TFCoXSDga/8jO66SGD7K7jMveZGVNJaD4IhX+vfvL0=
520520
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.383/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
521+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.385 h1:bwgb0FZJRlPcDn3uRJfA7rI7dZejg7LZS0b8rUBE2CQ=
522+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.385/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
521523
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.199 h1:ajgJogYSIQ5u1PIbiV5nsvr5K0fYpm1/T7Dy+mxEM6U=
522524
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.199/go.mod h1:AqyM/ZZMD7q5mHBqNY9YImbSpEpoEe7E/vrTbUWX+po=
523525
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.351 h1:zqJsH5pxGT57La7NAOOyMQxsuM11pupNBwV1dzXcT24=
524526
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.351/go.mod h1:IZH6xMdFwRrdxy6nEOdxdor+1AwDoOu/GG4PfPajwzM=
527+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.381 h1:F8YmauCBhAgVxTymZHVe9PgzZyFU+USP4Rg/qvtJLeQ=
528+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.381/go.mod h1:nwt2812GuKjmWNGtp7ISkcfku5td24JdzrRmeAEMT80=
529+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.382 h1:wyCkL9Q/EnxWqZqPRw0/pziSHMn1vwxH+yIeE46utQA=
530+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.382/go.mod h1:te3A+aQ1UnK4TOK7DBzS0a8ABE5fPljB28EiRIevyIw=
531+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.385 h1:8bwloRxRwSADSK48KxaUeO9JHmmgniNGJbA7Or/HUEk=
532+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.385/go.mod h1:PMxA0L4o8Fbx/6+ju1cAMAU7x2bV4C6e/LTqVe745yM=
525533
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.199 h1:L0twFkJMOZzLkX08w8S14nX6oanD8YxMQDIaYXVim6A=
526534
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.199/go.mod h1:AvfGfE5JXkyMV6uGd6B++SIDp+VV/SSphg1q2RiANFw=
527535
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.359 h1:cNKqelPgUxrJkLY0Azd2QHr/UMYOPPnmqs88clt2akk=

tencentcloud/data_source_tc_reserved_instance_configs.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ func dataSourceTencentCloudReservedInstanceConfigs() *schema.Resource {
4343
Optional: true,
4444
Description: "The type of reserved instance.",
4545
},
46+
"offering_type": {
47+
Type: schema.TypeString,
48+
Optional: true,
49+
Description: "Filter by Payment Type. Such as All Upfront.",
50+
},
51+
"product_description": {
52+
Type: schema.TypeString,
53+
Optional: true,
54+
Description: "Filter by the Platform Description (that is, operating system) for Reserved Instance billing. Shaped like: linux.",
55+
},
4656
"result_output_file": {
4757
Type: schema.TypeString,
4858
Optional: true,
@@ -77,7 +87,7 @@ func dataSourceTencentCloudReservedInstanceConfigs() *schema.Resource {
7787
Description: "Validity period of the reserved instance.",
7888
},
7989
"price": {
80-
Type: schema.TypeInt,
90+
Type: schema.TypeFloat,
8191
Computed: true,
8292
Description: "Purchase price of the reserved instance.",
8393
},
@@ -91,6 +101,16 @@ func dataSourceTencentCloudReservedInstanceConfigs() *schema.Resource {
91101
Computed: true,
92102
Description: "Platform of the reserved instance.",
93103
},
104+
"offering_type": {
105+
Type: schema.TypeString,
106+
Computed: true,
107+
Description: "OfferingType of the reserved instance.",
108+
},
109+
"usage_price": {
110+
Type: schema.TypeFloat,
111+
Computed: true,
112+
Description: "UsagePrice of the reserved instance.",
113+
},
94114
},
95115
},
96116
},
@@ -118,6 +138,12 @@ func dataSourceTencentCloudReservedInstanceConfigsRead(d *schema.ResourceData, m
118138
if v, ok := d.GetOk("instance_type"); ok {
119139
filter["instance-type"] = v.(string)
120140
}
141+
if v, ok := d.GetOk("offering_type"); ok {
142+
filter["offering-type"] = v.(string)
143+
}
144+
if v, ok := d.GetOk("product_description"); ok {
145+
filter["product-description"] = v.(string)
146+
}
121147

122148
var configs []*cvm.ReservedInstancesOffering
123149
var errRet error
@@ -143,6 +169,8 @@ func dataSourceTencentCloudReservedInstanceConfigsRead(d *schema.ResourceData, m
143169
"price": config.FixedPrice,
144170
"currency_code": config.CurrencyCode,
145171
"platform": config.ProductDescription,
172+
"offering_type": config.OfferingType,
173+
"usage_price": config.UsagePrice,
146174
}
147175
configList = append(configList, mapping)
148176
ids = append(ids, *config.ReservedInstancesOfferingId)

tencentcloud/data_source_tc_reserved_instance_configs_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
func TestAccTencentCloudReservedInstanceConfigsDataSource(t *testing.T) {
1010
t.Parallel()
1111
resource.Test(t, resource.TestCase{
12-
PreCheck: func() { testAccPreCheck(t) },
12+
PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_INTERNATION) },
1313
Providers: testAccProviders,
1414
Steps: []resource.TestStep{
1515
{

tencentcloud/resource_tc_reserved_instance.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ func resourceTencentCloudReservedInstance() *schema.Resource {
5353
ValidateFunc: validateIntegerMin(1),
5454
Description: "Number of reserved instances to be purchased.",
5555
},
56+
"reserved_instance_name": {
57+
Type: schema.TypeString,
58+
Optional: true,
59+
Description: `Reserved Instance display name.
60+
- If you do not specify an instance display name, 'Unnamed' is displayed by default.
61+
- Up to 60 characters (including pattern strings) are supported.`,
62+
},
5663

5764
// computed
5865
"start_time": {
@@ -84,10 +91,14 @@ func resourceTencentCloudReservedInstanceCreate(d *schema.ResourceData, meta int
8491
cvmService := CvmService{
8592
client: meta.(*TencentCloudClient).apiV3Conn,
8693
}
94+
extendParams := make(map[string]interface{})
95+
if v, ok := d.GetOk("reserved_instance_name"); ok {
96+
extendParams["reserved_instance_name"] = v.(string)
97+
}
8798
var instanceId string
8899
var errRet error
89100
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
90-
instanceId, errRet = cvmService.CreateReservedInstance(ctx, configId, int64(count))
101+
instanceId, errRet = cvmService.CreateReservedInstance(ctx, configId, int64(count), extendParams)
91102
if errRet != nil {
92103
return retryError(errRet)
93104
}
@@ -137,6 +148,7 @@ func resourceTencentCloudReservedInstanceRead(d *schema.ResourceData, meta inter
137148
_ = d.Set("start_time", instance.StartTime)
138149
_ = d.Set("end_time", instance.EndTime)
139150
_ = d.Set("status", instance.State)
151+
_ = d.Set("reserved_instance_name", instance.ReservedInstanceName)
140152

141153
return nil
142154
}

tencentcloud/service_tencentcloud_cvm.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,11 +727,15 @@ func (me *CvmService) DescribeZones(ctx context.Context) (zones []*cvm.ZoneInfo,
727727
return
728728
}
729729

730-
func (me *CvmService) CreateReservedInstance(ctx context.Context, configId string, count int64) (instanceId string, errRet error) {
730+
func (me *CvmService) CreateReservedInstance(ctx context.Context, configId string, count int64, extendParams map[string]interface{}) (instanceId string, errRet error) {
731731
logId := getLogId(ctx)
732732
request := cvm.NewPurchaseReservedInstancesOfferingRequest()
733733
request.ReservedInstancesOfferingId = &configId
734734
request.InstanceCount = &count
735+
if v, ok := extendParams["reserved_instance_name"]; ok {
736+
reservedInstanceName := v.(string)
737+
request.ReservedInstanceName = &reservedInstanceName
738+
}
735739

736740
ratelimit.Check(request.GetAction())
737741
response, err := me.client.UseCvmClient().PurchaseReservedInstancesOffering(request)

vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http/request.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)