Skip to content

Commit 6908a09

Browse files
ysicinglbajolet-hashicorp
authored andcommitted
feat(update): add InstanceChargeType support SPOTPAID
add InstanceChargeType support SPOTPAID Signed-off-by: ysicing <i@ysicing.me>
1 parent 5a6d197 commit 6908a09

5 files changed

Lines changed: 13 additions & 2 deletions

File tree

builder/tencentcloud/cvm/builder.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
107107
},
108108
&stepRunInstance{
109109
InstanceType: b.config.InstanceType,
110+
InstanceChargeType: b.config.InstanceChargeType,
110111
UserData: b.config.UserData,
111112
UserDataFile: b.config.UserDataFile,
112113
ZoneId: b.config.Zone,

builder/tencentcloud/cvm/builder.hcl2spec.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

builder/tencentcloud/cvm/run_config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ type TencentCloudRunConfig struct {
3131
// The base image name of Image you want to create your
3232
// customized image from.Conflict with SourceImageId.
3333
SourceImageName string `mapstructure:"source_image_name" required:"false"`
34+
// Charge type of cvm, values can be `POSTPAID_BY_HOUR` (default) `SPOTPAID`
35+
InstanceChargeType string `mapstructure:"instance_charge_type" required:"false"`
3436
// The instance type your cvm will be launched by.
3537
// You should reference Instace Type
3638
// for parameter taking.

builder/tencentcloud/cvm/step_run_instance.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
type stepRunInstance struct {
1515
InstanceType string
16+
InstanceChargeType string
1617
UserData string
1718
UserDataFile string
1819
instanceId string
@@ -51,15 +52,18 @@ func (s *stepRunInstance) Run(ctx context.Context, state multistep.StateBag) mul
5152
Say(state, "Trying to create a new instance", "")
5253

5354
// config RunInstances parameters
54-
POSTPAID_BY_HOUR := "POSTPAID_BY_HOUR"
5555
req := cvm.NewRunInstancesRequest()
5656
if s.ZoneId != "" {
5757
req.Placement = &cvm.Placement{
5858
Zone: &s.ZoneId,
5959
}
6060
}
61+
instanceChargeType := s.InstanceChargeType
62+
if instanceChargeType == "" {
63+
instanceChargeType = "POSTPAID_BY_HOUR"
64+
}
65+
req.InstanceChargeType = &instanceChargeType
6166
req.ImageId = source_image.ImageId
62-
req.InstanceChargeType = &POSTPAID_BY_HOUR
6367
req.InstanceType = &s.InstanceType
6468
// TODO: Add check for system disk size, it should be larger than image system disk size.
6569
req.SystemDisk = &cvm.SystemDisk{

docs-partials/builder/tencentcloud/cvm/TencentCloudRunConfig-not-required.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
- `source_image_name` (string) - The base image name of Image you want to create your
1010
customized image from.Conflict with SourceImageId.
1111

12+
- `instance_charge_type` (string) - Charge type of cvm, values can be `POSTPAID_BY_HOUR` (default) `SPOTPAID`
13+
1214
- `instance_name` (string) - Instance name.
1315

1416
- `disk_type` (string) - Root disk type your cvm will be launched by, default is `CLOUD_PREMIUM`. you could

0 commit comments

Comments
 (0)