@@ -69,11 +69,14 @@ type TencentCloudRunConfig struct {
6969 CidrBlock string `mapstructure:"cidr_block" required:"false"` // 10.0.0.0/16(default), 172.16.0.0/12, 192.168.0.0/16
7070 // Specify cider block of the subnet you will create if
7171 // subnet_id not set
72- SubnectCidrBlock string `mapstructure:"subnect_cidr_block" required:"false"`
73- InternetChargeType string `mapstructure:"internet_charge_type"`
72+ SubnectCidrBlock string `mapstructure:"subnect_cidr_block" required:"false"`
73+ // Internet charge type of cvm, values can be TRAFFIC_POSTPAID_BY_HOUR, BANDWIDTH_POSTPAID_BY_HOUR, BANDWIDTH_PACKAGE
74+ InternetChargeType string `mapstructure:"internet_charge_type" required:"false"`
7475 // Max bandwidth out your cvm will be launched by(in MB).
7576 // values can be set between 1 ~ 100.
7677 InternetMaxBandwidthOut int64 `mapstructure:"internet_max_bandwidth_out" required:"false"`
78+ // When internet_charge_type is BANDWIDTH_PACKAGE, bandwidth_package_id is required
79+ BandwidthPackageId string `mapstructure:"bandwidth_package_id" required:"false"`
7780 // Specify securitygroup your cvm will be launched by.
7881 SecurityGroupId string `mapstructure:"security_group_id" required:"false"`
7982 // Specify security name you will create if security_group_id not set.
@@ -171,6 +174,24 @@ func (cf *TencentCloudRunConfig) Prepare(ctx *interpolate.Context) []error {
171174 cf .DiskSize = 50
172175 }
173176
177+ if cf .InternetChargeType == "" {
178+ cf .InternetChargeType = "TRAFFIC_POSTPAID_BY_HOUR"
179+ }
180+
181+ validChargeTypes := map [string ]int {
182+ "TRAFFIC_POSTPAID_BY_HOUR" : 0 ,
183+ "BANDWIDTH_POSTPAID_BY_HOUR" : 0 ,
184+ "BANDWIDTH_PACKAGE" : 0 ,
185+ }
186+ if _ , ok := validChargeTypes [cf .InternetChargeType ]; ! ok {
187+ errs = append (errs , fmt .Errorf ("specified internet_charge_type(%s) is invalid." , cf .InternetChargeType ))
188+ }
189+
190+ if cf .InternetChargeType == "BANDWIDTH_PACKAGE" && cf .BandwidthPackageId == "" {
191+ errs = append (errs ,
192+ fmt .Errorf ("bandwidth_package_id is required when internet_charge_type is BANDWIDTH_PACKAGE" ))
193+ }
194+
174195 if cf .AssociatePublicIpAddress && cf .InternetMaxBandwidthOut <= 0 {
175196 cf .InternetMaxBandwidthOut = 1
176197 }
0 commit comments