From c8c982b10fb5a3bb50e3c50275dcfed0079ea180 Mon Sep 17 00:00:00 2001 From: Sam Stenvall Date: Fri, 25 Oct 2024 09:44:32 +0300 Subject: [PATCH 1/4] Rename "tencentCloudDataDisk" to "TencentCloudDataDisk" to match others --- .web-docs/components/builder/cvm/README.md | 2 +- builder/tencentcloud/cvm/builder.hcl2spec.go | 4 ++-- builder/tencentcloud/cvm/run_config.go | 6 +++--- .../tencentcloud/cvm/run_config.hcl2spec.go | 20 +++++++++---------- builder/tencentcloud/cvm/step_run_instance.go | 2 +- .../TencentCloudRunConfig-not-required.mdx | 2 +- .../cvm/tencentCloudDataDisk-not-required.mdx | 4 ++-- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/.web-docs/components/builder/cvm/README.md b/.web-docs/components/builder/cvm/README.md index 227bbb61..62f13e9c 100644 --- a/.web-docs/components/builder/cvm/README.md +++ b/.web-docs/components/builder/cvm/README.md @@ -127,7 +127,7 @@ a [communicator](/packer/docs/templates/legacy_json_templates/communicator) can - LOCAL_BASIC: 50 - Other: 50 ~ 1000 (need whitelist if > 50) -- `data_disks` ([]tencentCloudDataDisk) - Add one or more data disks to the instance before creating the image. +- `data_disks` ([]TencentCloudDataDisk) - Add one or more data disks to the instance before creating the image. Note that if the source image has data disk snapshots, this argument will be ignored, and the running instance will use source image data disk settings, in such case, `disk_type` argument will be used as disk diff --git a/builder/tencentcloud/cvm/builder.hcl2spec.go b/builder/tencentcloud/cvm/builder.hcl2spec.go index 51eadf70..e509687c 100644 --- a/builder/tencentcloud/cvm/builder.hcl2spec.go +++ b/builder/tencentcloud/cvm/builder.hcl2spec.go @@ -44,7 +44,7 @@ type FlatConfig struct { InstanceName *string `mapstructure:"instance_name" required:"false" cty:"instance_name" hcl:"instance_name"` DiskType *string `mapstructure:"disk_type" required:"false" cty:"disk_type" hcl:"disk_type"` DiskSize *int64 `mapstructure:"disk_size" required:"false" cty:"disk_size" hcl:"disk_size"` - DataDisks []FlattencentCloudDataDisk `mapstructure:"data_disks" cty:"data_disks" hcl:"data_disks"` + DataDisks []FlatTencentCloudDataDisk `mapstructure:"data_disks" cty:"data_disks" hcl:"data_disks"` VpcId *string `mapstructure:"vpc_id" required:"false" cty:"vpc_id" hcl:"vpc_id"` VpcName *string `mapstructure:"vpc_name" required:"false" cty:"vpc_name" hcl:"vpc_name"` SubnetId *string `mapstructure:"subnet_id" required:"false" cty:"subnet_id" hcl:"subnet_id"` @@ -160,7 +160,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "instance_name": &hcldec.AttrSpec{Name: "instance_name", Type: cty.String, Required: false}, "disk_type": &hcldec.AttrSpec{Name: "disk_type", Type: cty.String, Required: false}, "disk_size": &hcldec.AttrSpec{Name: "disk_size", Type: cty.Number, Required: false}, - "data_disks": &hcldec.BlockListSpec{TypeName: "data_disks", Nested: hcldec.ObjectSpec((*FlattencentCloudDataDisk)(nil).HCL2Spec())}, + "data_disks": &hcldec.BlockListSpec{TypeName: "data_disks", Nested: hcldec.ObjectSpec((*FlatTencentCloudDataDisk)(nil).HCL2Spec())}, "vpc_id": &hcldec.AttrSpec{Name: "vpc_id", Type: cty.String, Required: false}, "vpc_name": &hcldec.AttrSpec{Name: "vpc_name", Type: cty.String, Required: false}, "subnet_id": &hcldec.AttrSpec{Name: "subnet_id", Type: cty.String, Required: false}, diff --git a/builder/tencentcloud/cvm/run_config.go b/builder/tencentcloud/cvm/run_config.go index e4a45e11..658ca380 100644 --- a/builder/tencentcloud/cvm/run_config.go +++ b/builder/tencentcloud/cvm/run_config.go @@ -2,7 +2,7 @@ // SPDX-License-Identifier: MPL-2.0 //go:generate packer-sdc struct-markdown -//go:generate packer-sdc mapstructure-to-hcl2 -type tencentCloudDataDisk +//go:generate packer-sdc mapstructure-to-hcl2 -type TencentCloudDataDisk package cvm @@ -18,7 +18,7 @@ import ( "github.com/pkg/errors" ) -type tencentCloudDataDisk struct { +type TencentCloudDataDisk struct { DiskType string `mapstructure:"disk_type"` DiskSize int64 `mapstructure:"disk_size"` SnapshotId string `mapstructure:"disk_snapshot_id"` @@ -60,7 +60,7 @@ type TencentCloudRunConfig struct { // - `disk_type` - Type of the data disk. Valid choices: `CLOUD_BASIC`, `CLOUD_PREMIUM` and `CLOUD_SSD`. // - `disk_size` - Size of the data disk. // - `disk_snapshot_id` - Id of the snapshot for a data disk. - DataDisks []tencentCloudDataDisk `mapstructure:"data_disks"` + DataDisks []TencentCloudDataDisk `mapstructure:"data_disks"` // Specify vpc your cvm will be launched by. VpcId string `mapstructure:"vpc_id" required:"false"` // Specify vpc name you will create. if `vpc_id` is not set, Packer will diff --git a/builder/tencentcloud/cvm/run_config.hcl2spec.go b/builder/tencentcloud/cvm/run_config.hcl2spec.go index 0d0dfe9f..6b5b8bae 100644 --- a/builder/tencentcloud/cvm/run_config.hcl2spec.go +++ b/builder/tencentcloud/cvm/run_config.hcl2spec.go @@ -7,25 +7,25 @@ import ( "github.com/zclconf/go-cty/cty" ) -// FlattencentCloudDataDisk is an auto-generated flat version of tencentCloudDataDisk. +// FlatTencentCloudDataDisk is an auto-generated flat version of TencentCloudDataDisk. // Where the contents of a field with a `mapstructure:,squash` tag are bubbled up. -type FlattencentCloudDataDisk struct { +type FlatTencentCloudDataDisk struct { DiskType *string `mapstructure:"disk_type" cty:"disk_type" hcl:"disk_type"` DiskSize *int64 `mapstructure:"disk_size" cty:"disk_size" hcl:"disk_size"` SnapshotId *string `mapstructure:"disk_snapshot_id" cty:"disk_snapshot_id" hcl:"disk_snapshot_id"` } -// FlatMapstructure returns a new FlattencentCloudDataDisk. -// FlattencentCloudDataDisk is an auto-generated flat version of tencentCloudDataDisk. +// FlatMapstructure returns a new FlatTencentCloudDataDisk. +// FlatTencentCloudDataDisk is an auto-generated flat version of TencentCloudDataDisk. // Where the contents a fields with a `mapstructure:,squash` tag are bubbled up. -func (*tencentCloudDataDisk) FlatMapstructure() interface{ HCL2Spec() map[string]hcldec.Spec } { - return new(FlattencentCloudDataDisk) +func (*TencentCloudDataDisk) FlatMapstructure() interface{ HCL2Spec() map[string]hcldec.Spec } { + return new(FlatTencentCloudDataDisk) } -// HCL2Spec returns the hcl spec of a tencentCloudDataDisk. -// This spec is used by HCL to read the fields of tencentCloudDataDisk. -// The decoded values from this spec will then be applied to a FlattencentCloudDataDisk. -func (*FlattencentCloudDataDisk) HCL2Spec() map[string]hcldec.Spec { +// HCL2Spec returns the hcl spec of a TencentCloudDataDisk. +// This spec is used by HCL to read the fields of TencentCloudDataDisk. +// The decoded values from this spec will then be applied to a FlatTencentCloudDataDisk. +func (*FlatTencentCloudDataDisk) HCL2Spec() map[string]hcldec.Spec { s := map[string]hcldec.Spec{ "disk_type": &hcldec.AttrSpec{Name: "disk_type", Type: cty.String, Required: false}, "disk_size": &hcldec.AttrSpec{Name: "disk_size", Type: cty.Number, Required: false}, diff --git a/builder/tencentcloud/cvm/step_run_instance.go b/builder/tencentcloud/cvm/step_run_instance.go index 943eabf6..3113b561 100644 --- a/builder/tencentcloud/cvm/step_run_instance.go +++ b/builder/tencentcloud/cvm/step_run_instance.go @@ -31,7 +31,7 @@ type stepRunInstance struct { CamRoleName string AssociatePublicIpAddress bool Tags map[string]string - DataDisks []tencentCloudDataDisk + DataDisks []TencentCloudDataDisk } func (s *stepRunInstance) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { diff --git a/docs-partials/builder/tencentcloud/cvm/TencentCloudRunConfig-not-required.mdx b/docs-partials/builder/tencentcloud/cvm/TencentCloudRunConfig-not-required.mdx index 7d1fabb9..fa8338bc 100644 --- a/docs-partials/builder/tencentcloud/cvm/TencentCloudRunConfig-not-required.mdx +++ b/docs-partials/builder/tencentcloud/cvm/TencentCloudRunConfig-not-required.mdx @@ -21,7 +21,7 @@ - LOCAL_BASIC: 50 - Other: 50 ~ 1000 (need whitelist if > 50) -- `data_disks` ([]tencentCloudDataDisk) - Add one or more data disks to the instance before creating the image. +- `data_disks` ([]TencentCloudDataDisk) - Add one or more data disks to the instance before creating the image. Note that if the source image has data disk snapshots, this argument will be ignored, and the running instance will use source image data disk settings, in such case, `disk_type` argument will be used as disk diff --git a/docs-partials/builder/tencentcloud/cvm/tencentCloudDataDisk-not-required.mdx b/docs-partials/builder/tencentcloud/cvm/tencentCloudDataDisk-not-required.mdx index 8cdd0545..216bb64c 100644 --- a/docs-partials/builder/tencentcloud/cvm/tencentCloudDataDisk-not-required.mdx +++ b/docs-partials/builder/tencentcloud/cvm/tencentCloudDataDisk-not-required.mdx @@ -1,4 +1,4 @@ - + - `disk_type` (string) - Disk Type @@ -6,4 +6,4 @@ - `disk_snapshot_id` (string) - Snapshot Id - + From b9a28dd1ef29ea51d68e16b4703d392f4c23e90b Mon Sep 17 00:00:00 2001 From: Sam Stenvall Date: Tue, 3 Dec 2024 10:15:20 +0200 Subject: [PATCH 2/4] Make "disk_size" required (it is) and move documentation to the right place --- .web-docs/components/builder/cvm/README.md | 4 ---- builder/tencentcloud/cvm/run_config.go | 11 +++++------ builder/tencentcloud/cvm/run_config.hcl2spec.go | 4 ++-- .../cvm/TencentCloudDataDisk-required.mdx | 5 +++++ .../cvm/TencentCloudRunConfig-not-required.mdx | 4 ---- .../cvm/tencentCloudDataDisk-not-required.mdx | 6 ++---- 6 files changed, 14 insertions(+), 20 deletions(-) create mode 100644 docs-partials/builder/tencentcloud/cvm/TencentCloudDataDisk-required.mdx diff --git a/.web-docs/components/builder/cvm/README.md b/.web-docs/components/builder/cvm/README.md index 62f13e9c..21709250 100644 --- a/.web-docs/components/builder/cvm/README.md +++ b/.web-docs/components/builder/cvm/README.md @@ -133,10 +133,6 @@ a [communicator](/packer/docs/templates/legacy_json_templates/communicator) can disk settings, in such case, `disk_type` argument will be used as disk type for all data disks, and each data disk size will use the origin value in source image. - The data disks allow for the following argument: - - `disk_type` - Type of the data disk. Valid choices: `CLOUD_BASIC`, `CLOUD_PREMIUM` and `CLOUD_SSD`. - - `disk_size` - Size of the data disk. - - `disk_snapshot_id` - Id of the snapshot for a data disk. - `vpc_id` (string) - Specify vpc your cvm will be launched by. diff --git a/builder/tencentcloud/cvm/run_config.go b/builder/tencentcloud/cvm/run_config.go index 658ca380..841399ef 100644 --- a/builder/tencentcloud/cvm/run_config.go +++ b/builder/tencentcloud/cvm/run_config.go @@ -19,8 +19,11 @@ import ( ) type TencentCloudDataDisk struct { - DiskType string `mapstructure:"disk_type"` - DiskSize int64 `mapstructure:"disk_size"` + // The size of the data disk. + DiskSize int64 `mapstructure:"disk_size" required:"true"` + // The type of disk to use. See https://www.tencentcloud.com/document/api/213/15753#datadisk for valid values. + DiskType string `mapstructure:"disk_type"` + // The snapshot to use for the data disk. SnapshotId string `mapstructure:"disk_snapshot_id"` } @@ -56,10 +59,6 @@ type TencentCloudRunConfig struct { // disk settings, in such case, `disk_type` argument will be used as disk // type for all data disks, and each data disk size will use the origin // value in source image. - // The data disks allow for the following argument: - // - `disk_type` - Type of the data disk. Valid choices: `CLOUD_BASIC`, `CLOUD_PREMIUM` and `CLOUD_SSD`. - // - `disk_size` - Size of the data disk. - // - `disk_snapshot_id` - Id of the snapshot for a data disk. DataDisks []TencentCloudDataDisk `mapstructure:"data_disks"` // Specify vpc your cvm will be launched by. VpcId string `mapstructure:"vpc_id" required:"false"` diff --git a/builder/tencentcloud/cvm/run_config.hcl2spec.go b/builder/tencentcloud/cvm/run_config.hcl2spec.go index 6b5b8bae..ba40e9f6 100644 --- a/builder/tencentcloud/cvm/run_config.hcl2spec.go +++ b/builder/tencentcloud/cvm/run_config.hcl2spec.go @@ -10,8 +10,8 @@ import ( // FlatTencentCloudDataDisk is an auto-generated flat version of TencentCloudDataDisk. // Where the contents of a field with a `mapstructure:,squash` tag are bubbled up. type FlatTencentCloudDataDisk struct { + DiskSize *int64 `mapstructure:"disk_size" required:"true" cty:"disk_size" hcl:"disk_size"` DiskType *string `mapstructure:"disk_type" cty:"disk_type" hcl:"disk_type"` - DiskSize *int64 `mapstructure:"disk_size" cty:"disk_size" hcl:"disk_size"` SnapshotId *string `mapstructure:"disk_snapshot_id" cty:"disk_snapshot_id" hcl:"disk_snapshot_id"` } @@ -27,8 +27,8 @@ func (*TencentCloudDataDisk) FlatMapstructure() interface{ HCL2Spec() map[string // The decoded values from this spec will then be applied to a FlatTencentCloudDataDisk. func (*FlatTencentCloudDataDisk) HCL2Spec() map[string]hcldec.Spec { s := map[string]hcldec.Spec{ - "disk_type": &hcldec.AttrSpec{Name: "disk_type", Type: cty.String, Required: false}, "disk_size": &hcldec.AttrSpec{Name: "disk_size", Type: cty.Number, Required: false}, + "disk_type": &hcldec.AttrSpec{Name: "disk_type", Type: cty.String, Required: false}, "disk_snapshot_id": &hcldec.AttrSpec{Name: "disk_snapshot_id", Type: cty.String, Required: false}, } return s diff --git a/docs-partials/builder/tencentcloud/cvm/TencentCloudDataDisk-required.mdx b/docs-partials/builder/tencentcloud/cvm/TencentCloudDataDisk-required.mdx new file mode 100644 index 00000000..d8b49809 --- /dev/null +++ b/docs-partials/builder/tencentcloud/cvm/TencentCloudDataDisk-required.mdx @@ -0,0 +1,5 @@ + + +- `disk_size` (int64) - The size of the data disk. + + diff --git a/docs-partials/builder/tencentcloud/cvm/TencentCloudRunConfig-not-required.mdx b/docs-partials/builder/tencentcloud/cvm/TencentCloudRunConfig-not-required.mdx index fa8338bc..3d10d956 100644 --- a/docs-partials/builder/tencentcloud/cvm/TencentCloudRunConfig-not-required.mdx +++ b/docs-partials/builder/tencentcloud/cvm/TencentCloudRunConfig-not-required.mdx @@ -27,10 +27,6 @@ disk settings, in such case, `disk_type` argument will be used as disk type for all data disks, and each data disk size will use the origin value in source image. - The data disks allow for the following argument: - - `disk_type` - Type of the data disk. Valid choices: `CLOUD_BASIC`, `CLOUD_PREMIUM` and `CLOUD_SSD`. - - `disk_size` - Size of the data disk. - - `disk_snapshot_id` - Id of the snapshot for a data disk. - `vpc_id` (string) - Specify vpc your cvm will be launched by. diff --git a/docs-partials/builder/tencentcloud/cvm/tencentCloudDataDisk-not-required.mdx b/docs-partials/builder/tencentcloud/cvm/tencentCloudDataDisk-not-required.mdx index 216bb64c..6fc6e197 100644 --- a/docs-partials/builder/tencentcloud/cvm/tencentCloudDataDisk-not-required.mdx +++ b/docs-partials/builder/tencentcloud/cvm/tencentCloudDataDisk-not-required.mdx @@ -1,9 +1,7 @@ -- `disk_type` (string) - Disk Type +- `disk_type` (string) - The type of disk to use. See https://www.tencentcloud.com/document/api/213/15753#datadisk for valid values. -- `disk_size` (int64) - Disk Size - -- `disk_snapshot_id` (string) - Snapshot Id +- `disk_snapshot_id` (string) - The snapshot to use for the data disk. From 271c7bd5278339ec083192ed19f94444191ed3fe Mon Sep 17 00:00:00 2001 From: Sam Stenvall Date: Tue, 3 Dec 2024 10:59:41 +0200 Subject: [PATCH 3/4] 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. --- .web-docs/components/builder/cvm/README.md | 2 ++ builder/tencentcloud/cvm/builder.hcl2spec.go | 2 ++ builder/tencentcloud/cvm/run_config.go | 2 ++ builder/tencentcloud/cvm/step_create_image.go | 13 +++++++++---- .../cvm/TencentCloudRunConfig-not-required.mdx | 2 ++ 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.web-docs/components/builder/cvm/README.md b/.web-docs/components/builder/cvm/README.md index 21709250..95aec7a2 100644 --- a/.web-docs/components/builder/cvm/README.md +++ b/.web-docs/components/builder/cvm/README.md @@ -134,6 +134,8 @@ a [communicator](/packer/docs/templates/legacy_json_templates/communicator) can type for all data disks, and each data disk size will use the origin value in source image. +- `include_data_disks` (bool) - Whether to include data disks in the resulting image. Defaults to true. + - `vpc_id` (string) - Specify vpc your cvm will be launched by. - `vpc_name` (string) - Specify vpc name you will create. if `vpc_id` is not set, Packer will diff --git a/builder/tencentcloud/cvm/builder.hcl2spec.go b/builder/tencentcloud/cvm/builder.hcl2spec.go index e509687c..c8786338 100644 --- a/builder/tencentcloud/cvm/builder.hcl2spec.go +++ b/builder/tencentcloud/cvm/builder.hcl2spec.go @@ -45,6 +45,7 @@ type FlatConfig struct { DiskType *string `mapstructure:"disk_type" required:"false" cty:"disk_type" hcl:"disk_type"` DiskSize *int64 `mapstructure:"disk_size" required:"false" cty:"disk_size" hcl:"disk_size"` DataDisks []FlatTencentCloudDataDisk `mapstructure:"data_disks" cty:"data_disks" hcl:"data_disks"` + IncludeDataDisks *bool `mapstructure:"include_data_disks" required:"false" default:"true" cty:"include_data_disks" hcl:"include_data_disks"` VpcId *string `mapstructure:"vpc_id" required:"false" cty:"vpc_id" hcl:"vpc_id"` VpcName *string `mapstructure:"vpc_name" required:"false" cty:"vpc_name" hcl:"vpc_name"` SubnetId *string `mapstructure:"subnet_id" required:"false" cty:"subnet_id" hcl:"subnet_id"` @@ -161,6 +162,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "disk_type": &hcldec.AttrSpec{Name: "disk_type", Type: cty.String, Required: false}, "disk_size": &hcldec.AttrSpec{Name: "disk_size", Type: cty.Number, Required: false}, "data_disks": &hcldec.BlockListSpec{TypeName: "data_disks", Nested: hcldec.ObjectSpec((*FlatTencentCloudDataDisk)(nil).HCL2Spec())}, + "include_data_disks": &hcldec.AttrSpec{Name: "include_data_disks", Type: cty.Bool, Required: false}, "vpc_id": &hcldec.AttrSpec{Name: "vpc_id", Type: cty.String, Required: false}, "vpc_name": &hcldec.AttrSpec{Name: "vpc_name", Type: cty.String, Required: false}, "subnet_id": &hcldec.AttrSpec{Name: "subnet_id", Type: cty.String, Required: false}, diff --git a/builder/tencentcloud/cvm/run_config.go b/builder/tencentcloud/cvm/run_config.go index 841399ef..cacff6db 100644 --- a/builder/tencentcloud/cvm/run_config.go +++ b/builder/tencentcloud/cvm/run_config.go @@ -60,6 +60,8 @@ type TencentCloudRunConfig struct { // type for all data disks, and each data disk size will use the origin // value in source image. DataDisks []TencentCloudDataDisk `mapstructure:"data_disks"` + // Whether to include data disks in the resulting image. Defaults to true. + IncludeDataDisks bool `mapstructure:"include_data_disks" required:"false" default:"true"` // Specify vpc your cvm will be launched by. VpcId string `mapstructure:"vpc_id" required:"false"` // Specify vpc name you will create. if `vpc_id` is not set, Packer will diff --git a/builder/tencentcloud/cvm/step_create_image.go b/builder/tencentcloud/cvm/step_create_image.go index b337fbeb..50a40fa5 100644 --- a/builder/tencentcloud/cvm/step_create_image.go +++ b/builder/tencentcloud/cvm/step_create_image.go @@ -28,12 +28,17 @@ func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) mul req.ImageDescription = &config.ImageDescription req.InstanceId = instance.InstanceId - // TODO: We should allow user to specify which data disk should be - // included into created image. var dataDiskIds []*string - for _, disk := range instance.DataDisks { - dataDiskIds = append(dataDiskIds, disk.DiskId) + // There is no way to correlate instance disk IDs to our own data disk definitions, + // so the best we can do is to either include all disks or include none. + if config.IncludeDataDisks { + for _, disk := range instance.DataDisks { + dataDiskIds = append(dataDiskIds, disk.DiskId) + } + } else { + Message(state, "Not including configured data disks in the resulting image", "") } + if len(dataDiskIds) > 0 { req.DataDiskIds = dataDiskIds } diff --git a/docs-partials/builder/tencentcloud/cvm/TencentCloudRunConfig-not-required.mdx b/docs-partials/builder/tencentcloud/cvm/TencentCloudRunConfig-not-required.mdx index 3d10d956..1c873dfb 100644 --- a/docs-partials/builder/tencentcloud/cvm/TencentCloudRunConfig-not-required.mdx +++ b/docs-partials/builder/tencentcloud/cvm/TencentCloudRunConfig-not-required.mdx @@ -28,6 +28,8 @@ type for all data disks, and each data disk size will use the origin value in source image. +- `include_data_disks` (bool) - Whether to include data disks in the resulting image. Defaults to true. + - `vpc_id` (string) - Specify vpc your cvm will be launched by. - `vpc_name` (string) - Specify vpc name you will create. if `vpc_id` is not set, Packer will From 5bc88cbe8d51c5efbfee2a84cb15fb146cb85104 Mon Sep 17 00:00:00 2001 From: Sam Stenvall Date: Thu, 5 Dec 2024 10:07:29 +0200 Subject: [PATCH 4/4] 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" --- .web-docs/components/builder/cvm/README.md | 2 +- builder/tencentcloud/cvm/builder.hcl2spec.go | 2 +- builder/tencentcloud/cvm/run_config.go | 7 ++++++- builder/tencentcloud/cvm/step_create_image.go | 3 +-- .../cvm/TencentCloudRunConfig-not-required.mdx | 2 +- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.web-docs/components/builder/cvm/README.md b/.web-docs/components/builder/cvm/README.md index 95aec7a2..cf79bb7f 100644 --- a/.web-docs/components/builder/cvm/README.md +++ b/.web-docs/components/builder/cvm/README.md @@ -134,7 +134,7 @@ a [communicator](/packer/docs/templates/legacy_json_templates/communicator) can type for all data disks, and each data disk size will use the origin value in source image. -- `include_data_disks` (bool) - Whether to include data disks in the resulting image. Defaults to true. +- `include_data_disks` (boolean) - Whether to include data disks in the resulting image. Defaults to true. - `vpc_id` (string) - Specify vpc your cvm will be launched by. diff --git a/builder/tencentcloud/cvm/builder.hcl2spec.go b/builder/tencentcloud/cvm/builder.hcl2spec.go index c8786338..c5fc5896 100644 --- a/builder/tencentcloud/cvm/builder.hcl2spec.go +++ b/builder/tencentcloud/cvm/builder.hcl2spec.go @@ -45,7 +45,7 @@ type FlatConfig struct { DiskType *string `mapstructure:"disk_type" required:"false" cty:"disk_type" hcl:"disk_type"` DiskSize *int64 `mapstructure:"disk_size" required:"false" cty:"disk_size" hcl:"disk_size"` DataDisks []FlatTencentCloudDataDisk `mapstructure:"data_disks" cty:"data_disks" hcl:"data_disks"` - IncludeDataDisks *bool `mapstructure:"include_data_disks" required:"false" default:"true" cty:"include_data_disks" hcl:"include_data_disks"` + IncludeDataDisks *bool `mapstructure:"include_data_disks" required:"false" cty:"include_data_disks" hcl:"include_data_disks"` VpcId *string `mapstructure:"vpc_id" required:"false" cty:"vpc_id" hcl:"vpc_id"` VpcName *string `mapstructure:"vpc_name" required:"false" cty:"vpc_name" hcl:"vpc_name"` SubnetId *string `mapstructure:"subnet_id" required:"false" cty:"subnet_id" hcl:"subnet_id"` diff --git a/builder/tencentcloud/cvm/run_config.go b/builder/tencentcloud/cvm/run_config.go index cacff6db..86c2b89d 100644 --- a/builder/tencentcloud/cvm/run_config.go +++ b/builder/tencentcloud/cvm/run_config.go @@ -61,7 +61,7 @@ type TencentCloudRunConfig struct { // value in source image. DataDisks []TencentCloudDataDisk `mapstructure:"data_disks"` // Whether to include data disks in the resulting image. Defaults to true. - IncludeDataDisks bool `mapstructure:"include_data_disks" required:"false" default:"true"` + IncludeDataDisks config.Trilean `mapstructure:"include_data_disks" required:"false"` // Specify vpc your cvm will be launched by. VpcId string `mapstructure:"vpc_id" required:"false"` // Specify vpc name you will create. if `vpc_id` is not set, Packer will @@ -115,6 +115,11 @@ var ValidCBSType = []string{ } func (cf *TencentCloudRunConfig) Prepare(ctx *interpolate.Context) []error { + // Include data disks by default + if cf.IncludeDataDisks != config.TriFalse { + cf.IncludeDataDisks = config.TriTrue + } + packerId := fmt.Sprintf("packer_%s", uuid.TimeOrderedUUID()[:8]) if cf.Comm.SSHKeyPairName == "" && cf.Comm.SSHTemporaryKeyPairName == "" && cf.Comm.SSHPrivateKeyFile == "" && cf.Comm.SSHPassword == "" && cf.Comm.WinRMPassword == "" { diff --git a/builder/tencentcloud/cvm/step_create_image.go b/builder/tencentcloud/cvm/step_create_image.go index 50a40fa5..52c2a3ea 100644 --- a/builder/tencentcloud/cvm/step_create_image.go +++ b/builder/tencentcloud/cvm/step_create_image.go @@ -6,7 +6,6 @@ package cvm import ( "context" "fmt" - "github.com/hashicorp/packer-plugin-sdk/multistep" cvm "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312" ) @@ -31,7 +30,7 @@ func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) mul var dataDiskIds []*string // There is no way to correlate instance disk IDs to our own data disk definitions, // so the best we can do is to either include all disks or include none. - if config.IncludeDataDisks { + if config.IncludeDataDisks.True() { for _, disk := range instance.DataDisks { dataDiskIds = append(dataDiskIds, disk.DiskId) } diff --git a/docs-partials/builder/tencentcloud/cvm/TencentCloudRunConfig-not-required.mdx b/docs-partials/builder/tencentcloud/cvm/TencentCloudRunConfig-not-required.mdx index 1c873dfb..1ece68ef 100644 --- a/docs-partials/builder/tencentcloud/cvm/TencentCloudRunConfig-not-required.mdx +++ b/docs-partials/builder/tencentcloud/cvm/TencentCloudRunConfig-not-required.mdx @@ -28,7 +28,7 @@ type for all data disks, and each data disk size will use the origin value in source image. -- `include_data_disks` (bool) - Whether to include data disks in the resulting image. Defaults to true. +- `include_data_disks` (boolean) - Whether to include data disks in the resulting image. Defaults to true. - `vpc_id` (string) - Specify vpc your cvm will be launched by.