Skip to content

Commit

Permalink
internet_charge_type allow set to empty (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
likexian authored Nov 12, 2021
1 parent c473996 commit 4fd11cd
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
19 changes: 10 additions & 9 deletions builder/tencentcloud/cvm/run_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,22 +174,23 @@ func (cf *TencentCloudRunConfig) Prepare(ctx *interpolate.Context) []error {
cf.DiskSize = 50
}

if cf.InternetChargeType == "" {
cf.InternetChargeType = "TRAFFIC_POSTPAID_BY_HOUR"
}

validChargeTypes := map[string]int{
"TRAFFIC_POSTPAID_BY_HOUR": 0,
"BANDWIDTH_POSTPAID_BY_HOUR": 0,
"BANDWIDTH_PACKAGE": 0,
}
if _, ok := validChargeTypes[cf.InternetChargeType]; !ok {
errs = append(errs, fmt.Errorf("specified internet_charge_type(%s) is invalid.", cf.InternetChargeType))

if cf.InternetChargeType != "" {
if _, ok := validChargeTypes[cf.InternetChargeType]; !ok {
errs = append(errs, fmt.Errorf("specified internet_charge_type(%s) is invalid.", cf.InternetChargeType))
}
}

if cf.InternetChargeType == "BANDWIDTH_PACKAGE" && cf.BandwidthPackageId == "" {
errs = append(errs,
fmt.Errorf("bandwidth_package_id is required when internet_charge_type is BANDWIDTH_PACKAGE"))
if cf.InternetChargeType == "BANDWIDTH_PACKAGE" {
if cf.BandwidthPackageId == "" {
errs = append(errs,
fmt.Errorf("bandwidth_package_id is required when internet_charge_type is BANDWIDTH_PACKAGE"))
}
}

if cf.AssociatePublicIpAddress && cf.InternetMaxBandwidthOut <= 0 {
Expand Down
7 changes: 4 additions & 3 deletions builder/tencentcloud/cvm/step_run_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"log"

"github.com/hashicorp/packer-plugin-sdk/multistep"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
cvm "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312"
)

Expand Down Expand Up @@ -108,9 +107,11 @@ func (s *stepRunInstance) Run(ctx context.Context, state multistep.StateBag) mul
}
if s.AssociatePublicIpAddress {
req.InternetAccessible = &cvm.InternetAccessible{
InternetChargeType: &s.InternetChargeType,
PublicIpAssigned: &s.AssociatePublicIpAddress,
InternetMaxBandwidthOut: &s.InternetMaxBandwidthOut,
PublicIpAssigned: common.BoolPtr(true),
}
if s.InternetChargeType != "" {
req.InternetAccessible.InternetChargeType = &s.InternetChargeType
}
if s.BandwidthPackageId != "" {
req.InternetAccessible.BandwidthPackageId = &s.BandwidthPackageId
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ require (
github.com/hashicorp/hcl/v2 v2.10.1
github.com/hashicorp/packer-plugin-sdk v0.2.9
github.com/pkg/errors v0.9.1
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.273
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.273
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.273
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.283
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.283
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.283
github.com/zclconf/go-cty v1.9.1
)

Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -530,12 +530,12 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.273 h1:BUqNJfyBdYKrBqIEfrf2x8xYYatUKtvFb/19qxO9agU=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.273/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.273 h1:kJykBxc5g3u0pf9whWuuE2nw42mDZ+q0ojpSXx4CvKA=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.273/go.mod h1:AqyM/ZZMD7q5mHBqNY9YImbSpEpoEe7E/vrTbUWX+po=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.273 h1:Qfrp0vFj4cKjHrbJAH50DjmcokHwhw1rxNGjjgiIT74=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.273/go.mod h1:SKgeSsIfPEM6BeoIFiGHsWG9UsEXzkK0SkWx51H/OS8=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.283 h1:5haInk+Z3XuvzIOItsNEbUi5LN82SEYYv0iCD9PYtLw=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.283/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.283 h1:Pvq72nIS0MZ6wNsgNJybVHb+pgNFsGMItOg7n0Q5DOE=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.283/go.mod h1:AqyM/ZZMD7q5mHBqNY9YImbSpEpoEe7E/vrTbUWX+po=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.283 h1:P0ENpulfU1vFb1mY9JcBmTKg21NJHJ81Pf8fI4T9+wc=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.283/go.mod h1:SKgeSsIfPEM6BeoIFiGHsWG9UsEXzkK0SkWx51H/OS8=
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
github.com/ugorji/go v1.2.6 h1:tGiWC9HENWE2tqYycIqFTNorMmFRVhNwCpDOpWqnk8E=
github.com/ugorji/go v1.2.6/go.mod h1:anCg0y61KIhDlPZmnH+so+RQbysYVyDko0IMgJv0Nn0=
Expand Down

0 comments on commit 4fd11cd

Please sign in to comment.