Skip to content

Commit 271c7bd

Browse files
committed
Add "include_data_disks" option, fixes #141
Since there is no way to correlate the disk IDs we get back from the DescribeInstances with the data disk definitions we have in our template, we can't selectively exclude data disks from the image. But at least this is better than nothing.
1 parent b9a28dd commit 271c7bd

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ 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.
138+
137139
- `vpc_id` (string) - Specify vpc your cvm will be launched by.
138140

139141
- `vpc_name` (string) - Specify vpc name you will create. if `vpc_id` is not set, Packer will

builder/tencentcloud/cvm/builder.hcl2spec.go

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

builder/tencentcloud/cvm/run_config.go

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ type TencentCloudRunConfig struct {
6060
// type for all data disks, and each data disk size will use the origin
6161
// value in source image.
6262
DataDisks []TencentCloudDataDisk `mapstructure:"data_disks"`
63+
// Whether to include data disks in the resulting image. Defaults to true.
64+
IncludeDataDisks bool `mapstructure:"include_data_disks" required:"false" default:"true"`
6365
// Specify vpc your cvm will be launched by.
6466
VpcId string `mapstructure:"vpc_id" required:"false"`
6567
// Specify vpc name you will create. if `vpc_id` is not set, Packer will

builder/tencentcloud/cvm/step_create_image.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,17 @@ func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) mul
2828
req.ImageDescription = &config.ImageDescription
2929
req.InstanceId = instance.InstanceId
3030

31-
// TODO: We should allow user to specify which data disk should be
32-
// included into created image.
3331
var dataDiskIds []*string
34-
for _, disk := range instance.DataDisks {
35-
dataDiskIds = append(dataDiskIds, disk.DiskId)
32+
// There is no way to correlate instance disk IDs to our own data disk definitions,
33+
// so the best we can do is to either include all disks or include none.
34+
if config.IncludeDataDisks {
35+
for _, disk := range instance.DataDisks {
36+
dataDiskIds = append(dataDiskIds, disk.DiskId)
37+
}
38+
} else {
39+
Message(state, "Not including configured data disks in the resulting image", "")
3640
}
41+
3742
if len(dataDiskIds) > 0 {
3843
req.DataDiskIds = dataDiskIds
3944
}

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

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
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.
32+
3133
- `vpc_id` (string) - Specify vpc your cvm will be launched by.
3234

3335
- `vpc_name` (string) - Specify vpc name you will create. if `vpc_id` is not set, Packer will

0 commit comments

Comments
 (0)