Skip to content

Commit 5bc88cb

Browse files
committed
Use Trilean instead of boolean for IncludeDataDisks
"default" annotation has no effect, so we need to use a data type that supports "true/false/unset"
1 parent 271c7bd commit 5bc88cb

File tree

5 files changed

+10
-6
lines changed

5 files changed

+10
-6
lines changed

.web-docs/components/builder/cvm/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ a [communicator](/packer/docs/templates/legacy_json_templates/communicator) can
134134
type for all data disks, and each data disk size will use the origin
135135
value in source image.
136136

137-
- `include_data_disks` (bool) - Whether to include data disks in the resulting image. Defaults to true.
137+
- `include_data_disks` (boolean) - Whether to include data disks in the resulting image. Defaults to true.
138138

139139
- `vpc_id` (string) - Specify vpc your cvm will be launched by.
140140

builder/tencentcloud/cvm/builder.hcl2spec.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

builder/tencentcloud/cvm/run_config.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ type TencentCloudRunConfig struct {
6161
// value in source image.
6262
DataDisks []TencentCloudDataDisk `mapstructure:"data_disks"`
6363
// Whether to include data disks in the resulting image. Defaults to true.
64-
IncludeDataDisks bool `mapstructure:"include_data_disks" required:"false" default:"true"`
64+
IncludeDataDisks config.Trilean `mapstructure:"include_data_disks" required:"false"`
6565
// Specify vpc your cvm will be launched by.
6666
VpcId string `mapstructure:"vpc_id" required:"false"`
6767
// Specify vpc name you will create. if `vpc_id` is not set, Packer will
@@ -115,6 +115,11 @@ var ValidCBSType = []string{
115115
}
116116

117117
func (cf *TencentCloudRunConfig) Prepare(ctx *interpolate.Context) []error {
118+
// Include data disks by default
119+
if cf.IncludeDataDisks != config.TriFalse {
120+
cf.IncludeDataDisks = config.TriTrue
121+
}
122+
118123
packerId := fmt.Sprintf("packer_%s", uuid.TimeOrderedUUID()[:8])
119124
if cf.Comm.SSHKeyPairName == "" && cf.Comm.SSHTemporaryKeyPairName == "" &&
120125
cf.Comm.SSHPrivateKeyFile == "" && cf.Comm.SSHPassword == "" && cf.Comm.WinRMPassword == "" {

builder/tencentcloud/cvm/step_create_image.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package cvm
66
import (
77
"context"
88
"fmt"
9-
109
"github.com/hashicorp/packer-plugin-sdk/multistep"
1110
cvm "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312"
1211
)
@@ -31,7 +30,7 @@ func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) mul
3130
var dataDiskIds []*string
3231
// There is no way to correlate instance disk IDs to our own data disk definitions,
3332
// so the best we can do is to either include all disks or include none.
34-
if config.IncludeDataDisks {
33+
if config.IncludeDataDisks.True() {
3534
for _, disk := range instance.DataDisks {
3635
dataDiskIds = append(dataDiskIds, disk.DiskId)
3736
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
type for all data disks, and each data disk size will use the origin
2929
value in source image.
3030

31-
- `include_data_disks` (bool) - Whether to include data disks in the resulting image. Defaults to true.
31+
- `include_data_disks` (boolean) - Whether to include data disks in the resulting image. Defaults to true.
3232

3333
- `vpc_id` (string) - Specify vpc your cvm will be launched by.
3434

0 commit comments

Comments
 (0)