This topic describes the Alicloud Image Builder parameters that are used to implement DevOps when you use Packer to create Alibaba Cloud ECS custom images.

Parameter used to tag custom images

  • Field: tags{"key":"value"}.
  • Applicable scenario: If you have multiple custom images, you can tag them for easy management and retrieval. Alicloud Image Builder provides the tags parameter. If you set this parameter when you use Packer to create a custom image, the generated image will be bound with the tag you specified. For more information, see Tag overview.
  • Function: When you query images in the ECS console or by calling the DescribeImages operation, images are displayed with their tags. You can also filter images by tag. Tags bound to images can be used together with Terraform to standardize enterprise-grade DevOps processes.
  • Example: The following configuration file contains the version=v1.0.0 and app=web tags bound to the generated image and relative snapshot:
    {
      "variables": {
        "access_key": "{{env `ALICLOUD_ACCESS_KEY`}}",
        "secret_key": "{{env `ALICLOUD_SECRET_KEY`}}"
      },
      "builders": [{
        "type":"alicloud-ecs",
        "access_key":"{{user `access_key`}}",
        "secret_key":"{{user `secret_key`}}",
        "region":"cn-beijing",
        "image_name":"packer_basic",
        "source_image":"centos_7_03_64_20G_alibase_20170818.vhd",
        "ssh_username":"root",
        "instance_type":"ecs.t5-lc1m1.small",
        "internet_charge_type":"PayByTraffic",
        "io_optimized":"true",
        "tags": {
          "version": "v1.0.0",
          "app": "web"
        }
      }]
    }

Parameter used to control whether to create an image only based on a system disk

  • Field: image_ignore_data_disks. Data type: boolean.
  • Application scenario: By default, Packer creates images directly from ECS instances. If the ECS instances have data disks, the generated images contain data disk snapshots. You can use one of the following methods to create an instance that has data disks:
    • Method 1: Set data disk parameters in image_disk_mappings. For more information, see Alicloud Image Builder in Packer documentation.
    • Method 2: Select an instance type that comes with data disks by default, such as ecs.d1ne.2xlarge. The data disks that instance types come with by default are typically local disks. Snapshots cannot be created for local disks. Therefore, you cannot create images directly from instances of such instance types.
  • Function: If you want to select an instance type that comes with data disks by default, but you do not want the image created to contain data disk snapshots, you can add image_ignore_data_disks": "true" in the configuration file. This ensures that the image is created only based on the system disk.

Parameter used to set the snapshot timeout period

  • Field: wait_snapshot_ready_timeout. Data type: integer. Default value: 3600. Unit: seconds.
  • Applicable scenario: Images are created based on snapshots. The time it takes to create a snapshot for a disk depends on the disk size. The larger a disk is, the more time it takes.
  • Function: If a timeout error occurs when you create a snapshot for a large disk, specify a larger value for wait_snapshot_ready_timeout to prolong the snapshot timeout period.

Parameter used to control whether to connect to an instance by using a private IP address

  • Field: ssh_private_ip. Data type: boolean.
  • Applicable scenario: By default, Packer creates an Elastic IP address (EIP) and associates this EIP with the temporary ECS instance when Packer creates a custom image. Then, Packer uses the public IP address that corresponds to the EIP to connect to the instance and then installs software or runs commands on the instance. If Packer can use private IP addresses to connect to the instance, the public IP address is not needed.
  • Function: If you set ssh_private_ip to true, Packer does not assign an EIP or a public IP address to the temporary instance but uses private IP addresses to connect to the instance.

Parameter used to control whether to stop an instance

  • Field: disable_stop_instance. Data type: boolean.
  • Applicable scenario: By default, after Packer runs provisioners, it stops instances and then creates images from the instances. However, in some scenarios (for example, when you run Sysprep in Windows instances), instances must be in the Running state.

    For information about the applicable scenarios of Sysprep, see Modify the SID of a Windows ECS instance to create a domain environment.

  • Function: After you set disable_stop_instance to true, Packer does not stop instances but assumes that the command provided in the configuration (provisioners) automatically stops the instances.

Parameter used to specify the UserData file path for enabling WinRM

  • Field: user_data_file.
  • Applicable scenario: For security purposes, the Windows Remote Management (WinRM) function is disabled in Windows images by default. However, Packer must use the WinRM function to connect to a Windows instance and run commands on the instance. You can use the UserData file to enable WinRM when you create a Windows instance.
  • Function: You can use the user_data_file parameter to specify the path to the UserData file. For example, you can set the value of user_data_file to examples.ps1.
  • Example: In the following sample code, the UserData file is located in the relative path examples/alicloud/basic/winrm_enable_userdata.ps1.
    {
      "variables": {
        "access_key": "{{env `ALICLOUD_ACCESS_KEY`}}",
        "secret_key": "{{env `ALICLOUD_SECRET_KEY`}}"
      },
      "builders": [{
        "type":"alicloud-ecs",
        "access_key":"{{user `access_key`}}",
        "secret_key":"{{user `secret_key`}}",
        "region":"cn-beijing",
        "image_name":"packer_test",
        "source_image":"win2008r2_64_ent_sp1_zh-cn_40G_alibase_20181220.vhd",
        "instance_type":"ecs.n1.tiny",
        "io_optimized":"true",
        "internet_charge_type":"PayByTraffic",
        "image_force_delete":"true",
        "communicator": "winrm",
        "winrm_port": 5985,
        "winrm_username": "Administrator",
        "winrm_password": "Test1234",
        "user_data_file": "examples/alicloud/basic/winrm_enable_userdata.ps1"
      }],
      "provisioners": [{
        "type": "powershell",
        "inline": ["dir c:\\"]
      }]
    }
    Note
    • In the preceding sample code:
      • "communicator": "winrm" indicates that you are connected to the instance through WinRM.
      • "winrm_port": 5985 indicates that the communication port is port 5985.
      • "winrm_username": "Administrator" indicates that you are connected to the instance as an administrator.
      • "winrm_password": "Test1234" indicates that Password Test1234 is used.
    • "image_force_delete":"true" indicates that existing images are deleted if they have the same name as the image to be created.

Parameters used to create an image based on an on-premises ISO file and import the image to Alibaba Cloud ECS

  • Fields: builders{"type":"qemu"} and post-processors{"type":"alicloud-import"}.
  • Applicable scenario: If an on-premises ISO file runs in a non-QEMU-based virtualization environment, you can use Packer to create an image based on the file and import the image to Alibaba Cloud ECS.
  • Example: If the on-premises environment is based on QEMU, you can use Packer to create an image and then import the image to Alibaba Cloud ECS. For more information, see Create and import on-premises images by using Packer, which includes two important steps:
    1. Use an on-premises virtualization environment or a builder, such as QEMU Builder, to create an on-premises image.
    2. Define Alicloud Import Post-Processor to import the generated on-premises image to Alibaba Cloud ECS.

To import an ISO file to Alibaba Cloud ECS, you must first install a virtualization environment on premises and then create an image based on the file. The image must be in a format supported by Alibaba Cloud, such as the QCOW2, VHD, or RAW format. Then, you can import the image to Alibaba Cloud ECS. For more information, see Instructions for importing images.

References

Alicloud Image Builder and Examples.