Skip to content

Implement "enhanced_service" block #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .web-docs/components/builder/cvm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -172,6 +172,10 @@ a [communicator](/packer/docs/templates/legacy_json_templates/communicator) can

- `cam_role_name` (string) - CAM role name.

- `enhanced_service` (\*TencentCloudEnhancedService) - Configure enhanced security for the instance. Enables you to disable automatic installation
of certain system services during initial provisioning. If omitted, default values are used
(see https://www.tencentcloud.com/document/api/213/15753#enhancedservice).

- `run_tags` (map[string]string) - Tags to apply to the instance that is _launched_ to create the image.
These tags are _not_ applied to the resulting image.

Expand Down
1 change: 1 addition & 0 deletions builder/tencentcloud/cvm/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
BandwidthPackageId: b.config.BandwidthPackageId,
AssociatePublicIpAddress: b.config.AssociatePublicIpAddress,
CamRoleName: b.config.CamRoleName,
EnhancedService: b.config.EnhancedService,
Tags: b.config.RunTags,
},
&communicator.StepConnect{
Expand Down
208 changes: 105 additions & 103 deletions builder/tencentcloud/cvm/builder.hcl2spec.go

Large diffs are not rendered by default.

22 changes: 19 additions & 3 deletions builder/tencentcloud/cvm/run_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,TencentCloudEnhancedService

package cvm

Expand All @@ -18,12 +18,24 @@ 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"`
}

type TencentCloudEnhancedService struct {
// Enables cloud security service. If this parameter is not specified,
// the cloud security service will be enabled by default.
SecurityService bool `mapstructure:"security_service" required:"false"`
// Enables cloud monitor service. If this parameter is not specified, //
// the cloud monitor service will be enabled by default.
MonitorService bool `mapstructure:"monitor_service" required:"false"`
// Whether to enable the TAT service. If this parameter is not specified,
// the TAT service is enabled for public images and disabled for other images by default.
AutomationService bool `mapstructure:"automation_service" required:"false"`
}

type TencentCloudRunConfig struct {
// Whether allocate public ip to your cvm.
// Default value is `false`.
Expand Down Expand Up @@ -60,7 +72,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
Expand Down Expand Up @@ -95,6 +107,10 @@ type TencentCloudRunConfig struct {
HostName string `mapstructure:"host_name" required:"false"`
// CAM role name.
CamRoleName string `mapstructure:"cam_role_name" required:"false"`
// Configure enhanced security for the instance. Enables you to disable automatic installation
// of certain system services during initial provisioning. If omitted, default values are used
// (see https://www.tencentcloud.com/document/api/213/15753#enhancedservice).
EnhancedService *TencentCloudEnhancedService `mapstructure:"enhanced_service,omitempty" required:"false"`
// Tags to apply to the instance that is _launched_ to create the image.
// These tags are _not_ applied to the resulting image.
RunTags map[string]string `mapstructure:"run_tags" required:"false"`
Expand Down
47 changes: 37 additions & 10 deletions builder/tencentcloud/cvm/run_config.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion builder/tencentcloud/cvm/step_run_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ type stepRunInstance struct {
InternetMaxBandwidthOut int64
BandwidthPackageId string
CamRoleName string
EnhancedService *TencentCloudEnhancedService
AssociatePublicIpAddress bool
Tags map[string]string
DataDisks []tencentCloudDataDisk
DataDisks []TencentCloudDataDisk
}

func (s *stepRunInstance) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
Expand Down Expand Up @@ -139,6 +140,20 @@ func (s *stepRunInstance) Run(ctx context.Context, state multistep.StateBag) mul
req.HostName = &s.HostName
req.UserData = &userData
req.CamRoleName = &s.CamRoleName

if s.EnhancedService != nil {
req.EnhancedService = &cvm.EnhancedService{
AutomationService: &cvm.RunAutomationServiceEnabled{
Enabled: &s.EnhancedService.AutomationService,
},
MonitorService: &cvm.RunMonitorServiceEnabled{
Enabled: &s.EnhancedService.MonitorService,
},
SecurityService: &cvm.RunSecurityServiceEnabled{
Enabled: &s.EnhancedService.SecurityService,
},
}
}
var tags []*cvm.Tag
for k, v := range s.Tags {
k := k
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!-- Code generated from the comments of the TencentCloudEnhancedService struct in builder/tencentcloud/cvm/run_config.go; DO NOT EDIT MANUALLY -->

- `security_service` (bool) - Enables cloud security service. If this parameter is not specified,
the cloud security service will be enabled by default.

- `monitor_service` (bool) - Enables cloud monitor service. If this parameter is not specified, //
the cloud monitor service will be enabled by default.

- `automation_service` (bool) - Whether to enable the TAT service. If this parameter is not specified,
the TAT service is enabled for public images and disabled for other images by default.

<!-- End of code generated from the comments of the TencentCloudEnhancedService struct in builder/tencentcloud/cvm/run_config.go; -->
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -66,6 +66,10 @@

- `cam_role_name` (string) - CAM role name.

- `enhanced_service` (\*TencentCloudEnhancedService) - Configure enhanced security for the instance. Enables you to disable automatic installation
of certain system services during initial provisioning. If omitted, default values are used
(see https://www.tencentcloud.com/document/api/213/15753#enhancedservice).

- `run_tags` (map[string]string) - Tags to apply to the instance that is _launched_ to create the image.
These tags are _not_ applied to the resulting image.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<!-- Code generated from the comments of the tencentCloudDataDisk struct in builder/tencentcloud/cvm/run_config.go; DO NOT EDIT MANUALLY -->
<!-- Code generated from the comments of the TencentCloudDataDisk struct in builder/tencentcloud/cvm/run_config.go; DO NOT EDIT MANUALLY -->

- `disk_type` (string) - Disk Type

- `disk_size` (int64) - Disk Size

- `disk_snapshot_id` (string) - Snapshot Id

<!-- End of code generated from the comments of the tencentCloudDataDisk struct in builder/tencentcloud/cvm/run_config.go; -->
<!-- End of code generated from the comments of the TencentCloudDataDisk struct in builder/tencentcloud/cvm/run_config.go; -->