/etc/fstab does not include data disk configuration. Otherwise, instances created with this image cannot be started normally.






QcloudCVMFullAccess, QcloudCVMFinanceAccess, and QcloudAPIFullAccess preset policies to the sub-user.wget https://releases.hashicorp.com/packer/1.9.4/packer_1.9.4_linux_amd64.zip
unzip packer_1.9.4_linux_amd64.zip
/usr/local/bin.sudo mv packer /usr/local/bin
packer -v
vim tencentcloud.pkr.hcl
vim tencentcloud.json
i to enter file editing mode. Then, edit the custom image generator configurator and the instance information based on your actual situation.variable "secret_id" {type = stringdefault = env("TENCENTCLOUD_SECRET_ID")}variable "secret_key" {type = stringdefault = env("TENCENTCLOUD_SECRET_KEY")}source "tencentcloud-cvm" "basic" {secret_id = var.secret_idsecret_key = var.secret_keyregion = "ap-guangzhou"zone = "ap-guangzhou-6"instance_type = "SA3.MEDIUM2"disk_type = "CLOUD_PREMIUM"source_image_id = "img-9xqekomx"image_name = "packer-basic"ssh_username = "root"associate_public_ip_address = truerun_tags = {"packer" = "packer-test"}}build {sources = ["source.tencentcloud-cvm.basic"]provisioner "shell" {inline = ["sleep 30", "yum install redis.x86_64 -y"]}}
{"variables": {"secret_id": "{{env `TENCENTCLOUD_SECRET_ID`}}","secret_key": "{{env `TENCENTCLOUD_SECRET_KEY`}}"},"builders": [{"type": "tencentcloud-cvm","secret_id": "{{user `secret_id`}}","secret_key": "{{user `secret_key`}}","region":"ap-guangzhou","zone": "ap-guangzhou-6","instance_type": "SA3.MEDIUM2","disk_type": "CLOUD_PREMIUM","source_image_id": "img-9xqekomx","image_name": "packer-basic","ssh_username": "root","associate_public_ip_address": true,"run_tags": {"packer": "packer-test"}}],"provisioners": [{"type": "shell","inline": ["sleep 30", "yum install redis.x86_64 -y"]}]}
Parameter | Required or Not | Description |
secret_id | Yes | It is recommended to set the secret_id to the TENCENTCLOUD_SECRET_ID environment variable. |
secret_key | Yes | It is recommended to set the secret_key to the TENCENTCLOUD_SECRET_KEY environment variable. |
region | Yes | Region. The region where the temporary CVM is created, and the region where the image is created. Example value: ap-guangzhou |
zone | Yes | AZ. The AZ where the temporary CVM is created. Example value: ap-guangzhou-6 |
instance_type | Yes | Instance type. Different instance types specify different resource specifications. Example value: SA3.MEDIUM2 |
source_image_id | Yes | The base image ID, which is used to create a temporary CVM image, can be obtained from the public image list or queried through the DescribeImages API. Example value: img-9xqekomx |
image_name | Yes | Specify the name of the custom image. It consists of letters, numbers, and -, and cannot exceed 60 characters. Example value: packer-basic |
image_description | No | Image description. It cannot exceed 60 characters. |
associate_public_ip_address | No | Whether to enable a public IP address for the temporary CVM. The default value is false. If you connect via a public IP address, set the value to true. |
force_poweroff | No | Whether to force shut down the temporary CVM to create an image when the process of shutting down the temporary CVM to create an image fails. The default value is false. |
sysprep | No | Whether to enable Sysprep during Windows image creation. Example value: false |
image_copy_regions | No | The region to which the image will be copied after creation. Example value: ["ap-beijing"] |
image_share_accounts | No | The accounts to which the image will be shared after creation. Example value: ["10002297xxxx"] |
skip_region_validation | No | Region is not checked during validation. Example value: false |
internet_max_bandwidth_out | No | The maximum bandwidth for startup (in Mbps). The value can be set between 1 and 100. |
instance_name | No | Instance name. |
disk_type | No | |
disk_size | No | System disk size. Value range (in GB): LOCAL_BASIC: 50 Other: 50 to 1000 (>50 requires an allowlist) |
data_disks | No | |
vpc_id | No | The vpc_id required for creating the temporary CVM. |
vpc_name | No | The name of the vpc created before creating the CVM. If the name is not specified, a default value such as packer-**** is assigned. |
cidr_block | No | If vpc_id is not set, specify the CIDR block for the VPC to be created. Example value: false |
subnet_id | No | The subnet_id required for creating the temporary CVM. |
subnet_name | No | The name of the Subnet created before the CVM is created. If the name is not specified, a default value such as packer-**** is assigned. |
subnet_cidr_block | No | If subnet_id is not set, specify the CIDR block for the Subnet to be created. Example value: false |
security_group_id | No | The security group ID required for creating the temporary CVM. |
security_group_name | No | The name of the security group, required when a security group is created if security_group_id is not set. |
user_data | No | User data. |
user_data_file | No | User data file. |
host_name | No | Host name. |
run_tags | No | Tags, used to specify instance tags when the temporary CVM is created, and are not used for creating images. |
Parameter | Required or Not | Description |
disk_type | Yes | The type of data disk. Valid options: CLOUD_BASIC, CLOUD_PREMIUM, and CLOUD_SSD. |
disk_size | Yes | The size of the data disk. |
disk_snapshot_id | Yes | The ID of the data disk snapshot. |
export TENCENTCLOUD_SECRET_ID=xxxxexport TENCENTCLOUD_SECRET_KEY=xxxx
packer build tencentcloud.pkr.hcl
packer build tencentcloud.json
tencentcloud-cvm.basic: output will be in this color.==> tencentcloud-cvm.basic: Trying to check image name: packer-basic...tencentcloud-cvm.basic: Image name: useable==> tencentcloud-cvm.basic: Trying to check source image: img-9xqekomx...tencentcloud-cvm.basic: Image found: CentOS Stream 9 64bit==> tencentcloud-cvm.basic: Trying to create a new keypair: packer_656c7***...tencentcloud-cvm.basic: Keypair created: skey-2ekzd***==> tencentcloud-cvm.basic: Trying to create a new vpc...tencentcloud-cvm.basic: Vpc created: vpc-bm797***==> tencentcloud-cvm.basic: Trying to create a new subnet...tencentcloud-cvm.basic: Subnet created: subnet-74c4j***==> tencentcloud-cvm.basic: Trying to create a new securitygroup...tencentcloud-cvm.basic: Securitygroup created: sg-7kf8z***==> tencentcloud-cvm.basic: Trying to create securitygroup polices...tencentcloud-cvm.basic: Securitygroup polices created==> tencentcloud-cvm.basic: Trying to create a new instance...tencentcloud-cvm.basic: Waiting for instance readytencentcloud-cvm.basic: Instance created: ins-n6dp2***==> tencentcloud-cvm.basic: Using SSH communicator to connect: 1.14.***.***==> tencentcloud-cvm.basic: Waiting for SSH to become available...==> tencentcloud-cvm.basic: Connected to SSH!==> tencentcloud-cvm.basic: Provisioning with shell script: /var/folders/0_/xl3kk_6n79vbnpgj97******0000gn/T/packer-shell1288510462tencentcloud-cvm.basic: CentOS Stream 9 - AppStream 42 MB/s | 18 MB 00:00tencentcloud-cvm.basic: CentOS Stream 9 - BaseOS 31 MB/s | 7.9 MB 00:00tencentcloud-cvm.basic: Last metadata expiration check: 0:00:01 ago on Sun 03 Dec 2023 09:18:14 PM CST.tencentcloud-cvm.basic: Dependencies resolved.tencentcloud-cvm.basic: ================================================================================tencentcloud-cvm.basic: Package Architecture Version Repository Sizetencentcloud-cvm.basic: ================================================================================tencentcloud-cvm.basic: Installing:tencentcloud-cvm.basic: redis x86_64 6.2.7-1.el9 appstream 1.3 Mtencentcloud-cvm.basic:tencentcloud-cvm.basic: Transaction Summarytencentcloud-cvm.basic: ================================================================================tencentcloud-cvm.basic: Install 1 Packagetencentcloud-cvm.basic:tencentcloud-cvm.basic: Total download size: 1.3 Mtencentcloud-cvm.basic: Installed size: 4.7 Mtencentcloud-cvm.basic: Downloading Packages:tencentcloud-cvm.basic: redis-6.2.7-1.el9.x86_64.rpm 6.5 MB/s | 1.3 MB 00:00tencentcloud-cvm.basic: --------------------------------------------------------------------------------tencentcloud-cvm.basic: Total 6.5 MB/s | 1.3 MB 00:00tencentcloud-cvm.basic: Running transaction checktencentcloud-cvm.basic: Transaction check succeeded.tencentcloud-cvm.basic: Running transaction testtencentcloud-cvm.basic: Transaction test succeeded.tencentcloud-cvm.basic: Running transactiontencentcloud-cvm.basic: Preparing : 1/1tencentcloud-cvm.basic: Running scriptlet: redis-6.2.7-1.el9.x86_64 1/1tencentcloud-cvm.basic: Installing : redis-6.2.7-1.el9.x86_64 1/1tencentcloud-cvm.basic: Running scriptlet: redis-6.2.7-1.el9.x86_64 1/1tencentcloud-cvm.basic: Verifying : redis-6.2.7-1.el9.x86_64 1/1tencentcloud-cvm.basic:tencentcloud-cvm.basic: Installed:tencentcloud-cvm.basic: redis-6.2.7-1.el9.x86_64tencentcloud-cvm.basic:tencentcloud-cvm.basic: Complete!==> tencentcloud-cvm.basic: Trying to detach keypair: skey-2ekzdz0x...tencentcloud-cvm.basic: Waiting for keypair detachedtencentcloud-cvm.basic: Keypair detached==> tencentcloud-cvm.basic: Trying to create a new image: packer-basic...tencentcloud-cvm.basic: Waiting for image readytencentcloud-cvm.basic: Image created: img-pubkd***==> tencentcloud-cvm.basic: Cleaning up instance...==> tencentcloud-cvm.basic: Cleaning up securitygroup...==> tencentcloud-cvm.basic: Cleaning up subnet...==> tencentcloud-cvm.basic: Cleaning up vpc...==> tencentcloud-cvm.basic: Cleaning up keypair...Build 'tencentcloud-cvm.basic' finished after 3 minutes 38 seconds.==> Wait completed after 3 minutes 38 seconds==> Builds finished. The artifacts of successful builds are:--> tencentcloud-cvm.basic: Tencentcloud images(ap-guangzhou: img-pubkd***) were created.

builder unknown error will be reported. In contrast, Packer versions prior to 1.9.0 (for example, version 1.8.7) include the Plugin by default.QcloudCVMFullAccess, QcloudCVMFinanceAccess, and QcloudAPIFullAccess preset policies are granted to the sub-user.packer.exe command) and the Packer builder machine. It is recommended to configure a public network assignment ("associate_public_ip_address": true) in config.json, or ensure the client is another CVM within the same VPC as specified in config.json, to guarantee private network interconnection.packer.exe. Using the CMD command line, go to the extraction directory and run the following command to complete the Packer environment initialization.packer.exe plugins install github.com/hashicorp/tencentcloud
{"builders": [{"type": "tencentcloud-cvm","secret_id": "Your secret_id","secret_key": "Your secret_key","region": "ap-shanghai","zone": "ap-shanghai-5","instance_type": "S5.MEDIUM4","source_image_id": "img-m07ny34j","disk_size": 40,"disk_type": "CLOUD_PREMIUM","vpc_id": "vpc-9yabaw4m","subnet_id": "subnet-ih08bvf9","communicator": "winrm","winrm_port": 5985,"winrm_username": "Administrator","winrm_password": "A complex password consisting of uppercase letters, lowercase letters, and numbers","image_name": "test_Packer1","security_group_id": "sg-c65mz0li","packer_debug": true,"associate_public_ip_address": true,"run_tags": {"good": "luck"},"user_data_file": "winrm_enable_userdata.ps1"}],"provisioners": [{"type": "powershell","inline": ["mkdir C:\\\\test -force;wget http://windows-1251783334.cos.ap-shanghai.myqcloud.com/installChrome.ps1 -Outfile c:\\\\test\\\\packer.ps1;Start-Process powershell.exe -ArgumentList '-NoProfile -File c:\\\\test\\\\packer.ps1' -Wait;"]}]}
Parameter | Required | Description |
secret_id | Yes | It is recommended to set the TENCENTCLOUD_SECRET_ID environment variable. |
secret_key | Yes | It is recommended to set the TENCENTCLOUD_SECRET_KEY environment variable. |
region | Yes | Region. The region where the temporary CVM is created, and the region where the image is created. Example value: ap-guangzhou |
zone | Yes | AZ. The AZ where the temporary CVM is created. Example value: ap-guangzhou-4 |
instance_type | Yes | Instance type. Different instance types specify different resource specifications. Example value: S5.MEDIUM4 |
source_image_id | Yes | The base image ID, which is used to create a temporary CVM image, can be obtained from the public image list or queried through the DescribeImages API. Example value: img-m07ny34j |
image_name | Yes | The name of the custom image. It consists of letters, numbers, and -, and cannot exceed 60 characters.Example value: test_Packer1. |
communicator | Yes | Specifies the method for Packer to connect to the target machine. It is fixed to winrm and establishes communication with the machine via WinRM. |
winrm_port | Yes | The port number for WinRM connections, which is fixed to 5985. |
winrm_username | Yes | |
winrm_password | Yes | |
associate_public_ip_address | No | Whether to enable a public IP address for the temporary CVM. The default value is false. If you connect via a public IP address, set the value to true. |
disk_type | No | |
disk_size | No | The system disk size, measured in GB. For example, for 40GB, enter 40. |
vpc_id | No | The VPC ID required for creating the temporary CVM. |
subnet_id | No | The subnet ID required for creating the temporary CVM. |
security_group_id | No | The security group ID required for creating the temporary CVM. |
user_data_file | No | The path to the user data file. |
inline | No | The necessary business logic before the image is created. For example, automatically install the Chrome browser when a public network connection is available. |
config.json and winrm_enable_userdata.ps1 in the same directory as the Packer main program packer.exe.packer.exe build config.json
packer.exe, you can view the created builder machine in the CVM console. Do not operate this server. Regardless of whether the image creation succeeds or fails, this server will be automatically reclaimed in the end. If a reclamation exception occurs, contact Online Customer Service for assistance.==> tencentcloud-cvm: Waiting for image creating...==> tencentcloud-cvm: Image ID: img-xxxxxxBuild 'tencentcloud-cvm' finished after ...
Some builds didn't complete successfully and had errors: tencentcloud-cvm: Image name xxxx existsconfig.json, you need to update the image_name value when reusing it.Waiting for WinRM become available...config.json for winrm_password matches the password in winrm_enable_userdata.ps1. The password configuration location in winrm_enable_userdata.ps1 is as follows:
Script exited with non-zero exit status: 16001.
Was this page helpful?
You can also Contact sales or Submit a Ticket for help.
Help us improve! Rate your documentation experience in 5 mins.
Feedback