From fc46f589fbe946eda2559fa2b314f83c777d03d1 Mon Sep 17 00:00:00 2001 From: Sk Lv Date: Mon, 3 Jul 2023 16:01:09 +0800 Subject: [PATCH 01/11] feat: support plugins documentations --- .docs/datasources/kmi/kmi.mdx | 83 +++++++++++++++++++ .../builder/AccessConfig-required.mdx | 12 +++ .../builder/CommonConfig-not-required.mdx | 50 +++++++++++ .../builder/KmiFilterOptions-not-required.mdx | 14 ++++ .../epc/KsyunEpcRunConfig-not-required.mdx | 43 ++++++++++ .../epc/KsyunEpcRunConfig-required.mdx | 7 ++ .../kec/KsyunEbsDataDisk-not-required.mdx | 5 ++ .../builder/kec/KsyunEbsDataDisk-required.mdx | 7 ++ .../kec/KsyunKecRunConfig-not-required.mdx | 32 +++++++ .../kec/KsyunKecRunConfig-required.mdx | 10 +++ .../datasource/kmi/DatasourceOutput.mdx | 13 +++ docs/datasources/kmi/kmi.mdx | 44 ++++++++++ 12 files changed, 320 insertions(+) create mode 100644 .docs/datasources/kmi/kmi.mdx create mode 100644 docs-partials/builder/AccessConfig-required.mdx create mode 100644 docs-partials/builder/CommonConfig-not-required.mdx create mode 100644 docs-partials/builder/KmiFilterOptions-not-required.mdx create mode 100644 docs-partials/builder/epc/KsyunEpcRunConfig-not-required.mdx create mode 100644 docs-partials/builder/epc/KsyunEpcRunConfig-required.mdx create mode 100644 docs-partials/builder/kec/KsyunEbsDataDisk-not-required.mdx create mode 100644 docs-partials/builder/kec/KsyunEbsDataDisk-required.mdx create mode 100644 docs-partials/builder/kec/KsyunKecRunConfig-not-required.mdx create mode 100644 docs-partials/builder/kec/KsyunKecRunConfig-required.mdx create mode 100644 docs-partials/datasource/kmi/DatasourceOutput.mdx create mode 100644 docs/datasources/kmi/kmi.mdx diff --git a/.docs/datasources/kmi/kmi.mdx b/.docs/datasources/kmi/kmi.mdx new file mode 100644 index 0000000..7248ca7 --- /dev/null +++ b/.docs/datasources/kmi/kmi.mdx @@ -0,0 +1,83 @@ +--- +description: | +The Ksyun KMI data source provides information from a KMI that will be fetched based +on the filter options provided in the configuration. + +page_title: Ksyun KMI - Data Source +nav_title: Ksyun KMI +--- + +# Ksyun KMI Data Source + +Type: `ksyun-kmi` + +The Ksyun KMI data source will filter and fetch a Ksyun Images, and output all the Ksyun Machine images information that will +be then available to use in the [Ksyun builders](./). + +-> **Note:** Data sources is a feature exclusively available to HCL2 templates. + +Basic example of usage: + +```hcl +data "ksyun-kmi" "foo" { + access_key = "ksyun access key" + secret_key = "ksyun secret key" + region = "cn-shanghai-2" + platform = "centos-7.5" + name_regex = "centos-7.5.*" + image_source = "system" // import, copy, share, extend, system. + most_recent = true +} +``` +This selects the most recent Centos 7.5 Ksyun Images from remote Ksyun. Note that the data source will fail unless +*exactly* one AMI is returned. In the above example, `most_recent` will cause this to succeed by selecting the newest image. + +## Configuration Reference + + + +- `most_recent` (bool) - Selects the newest created image when true. + This is most useful for selecting a daily distro build. + +- `image_source` (string) - ImageSource Valid values are import, copy, share, extend, system. + +- `name_regex` (string) - NameRegex A regex string to filter resulting images by name. + (Such as: `^CentOS 7.[1-2] 64` means CentOS 7.1 of 64-bit operating system or CentOS 7.2 of 64-bit operating system, + \"^Ubuntu 16.04 64\" means Ubuntu 16.04 of 64-bit operating system). + +- `platform` (string) - Platform type of the image system. + + + + + + +- `access_key` (string) - Ksyun access key must be provided unless `profile` is set, but it can + also be sourced from the `KSYUN_ACCESS_KEY` environment variable. + +- `secret_key` (string) - Ksyun secret key must be provided unless `profile` is set, but it can + also be sourced from the `KSYUN_SECRET_KEY` environment variable. + +- `region` (string) - Ksyun region must be provided unless `profile` is set, but it can + also be sourced from the `KSYUN_REGION` environment variable. + + + + +## Output Data + + + +- `id` (string) - The ID of the image. + +- `name` (string) - The name of the image. + +- `creation_date` (string) - The date of creation of the image. + +- `platform` (string) - Platform + +- `image_source` (string) - Image Source + + + + diff --git a/docs-partials/builder/AccessConfig-required.mdx b/docs-partials/builder/AccessConfig-required.mdx new file mode 100644 index 0000000..443828f --- /dev/null +++ b/docs-partials/builder/AccessConfig-required.mdx @@ -0,0 +1,12 @@ + + +- `access_key` (string) - Ksyun access key must be provided unless `profile` is set, but it can + also be sourced from the `KSYUN_ACCESS_KEY` environment variable. + +- `secret_key` (string) - Ksyun secret key must be provided unless `profile` is set, but it can + also be sourced from the `KSYUN_SECRET_KEY` environment variable. + +- `region` (string) - Ksyun region must be provided unless `profile` is set, but it can + also be sourced from the `KSYUN_REGION` environment variable. + + diff --git a/docs-partials/builder/CommonConfig-not-required.mdx b/docs-partials/builder/CommonConfig-not-required.mdx new file mode 100644 index 0000000..4889816 --- /dev/null +++ b/docs-partials/builder/CommonConfig-not-required.mdx @@ -0,0 +1,50 @@ + + +- `vpc_id` (string) - VPC ID allocated by the system. + +- `vpc_name` (string) - the default value is packer_vpc + +- `vpc_cidr_block` (string) - 172.16.0.0/16. When not specified, the default value is 172.16.0.0/16. + +- `subnet_id` (string) - The ID of the Subnet to be used. + +- `subnet_name` (string) - the default value is packer_subnet + +- `dns1` (string) - 172.16.0.0/24. When not specified, the default value is 172.16.0.0/24. + +- `dns2` (string) - DNS 2 + +- `subnet_cidr_block` (string) - Subnet Cidr Block + +- `availability_zone` (string) - availability_zone + +- `security_group_id` (string) - ID of the security group to which a newly + created instance belongs. Mutual access is allowed between instances in one + security group. If not specified, the newly created instance will be added + to the default security group. If the default group doesn’t exist, or the + number of instances in it has reached the maximum limit, a new security + group will be created automatically. + +- `security_group_name` (string) - The security group name. The default value + is blank. [2, 128] English or Chinese characters, must begin with an + uppercase/lowercase letter or Chinese character. Can contain numbers, ., + _ or -. It cannot begin with `http://` or `https://`. + the default value is packer_security_group + +- `private_ip_address` (string) - Private IP address, which specifies any valid value within the range of subnet IP address and represents + the primary IP address of the instance. Only one can be selected and bound to the primary network card. + If this parameter is not specified, the system will automatically select one from the valid address pool at random + Valid values: standard IP address format + +- `associate_public_ip_address` (bool) - Associate Public Ip Address + +- `public_ip_charge_type` (string) - PublicIp charge type, which can be + Daily TrafficMonthly DailyPaidByTransfer HourlyInstantSettlement + Default is Daily + +- `public_ip_band_width` (int) - [1-100] + Default is 1 + +- `project_id` (string) - Default is 0 + + diff --git a/docs-partials/builder/KmiFilterOptions-not-required.mdx b/docs-partials/builder/KmiFilterOptions-not-required.mdx new file mode 100644 index 0000000..492f601 --- /dev/null +++ b/docs-partials/builder/KmiFilterOptions-not-required.mdx @@ -0,0 +1,14 @@ + + +- `most_recent` (bool) - Selects the newest created image when true. + This is most useful for selecting a daily distro build. + +- `image_source` (string) - ImageSource Valid values are import, copy, share, extend, system. + +- `name_regex` (string) - NameRegex A regex string to filter resulting images by name. + (Such as: `^CentOS 7.[1-2] 64` means CentOS 7.1 of 64-bit operating system or CentOS 7.2 of 64-bit operating system, + \"^Ubuntu 16.04 64\" means Ubuntu 16.04 of 64-bit operating system). + +- `platform` (string) - Platform type of the image system. + + diff --git a/docs-partials/builder/epc/KsyunEpcRunConfig-not-required.mdx b/docs-partials/builder/epc/KsyunEpcRunConfig-not-required.mdx new file mode 100644 index 0000000..e3606f3 --- /dev/null +++ b/docs-partials/builder/epc/KsyunEpcRunConfig-not-required.mdx @@ -0,0 +1,43 @@ + + +- `raid` (string) - Raid + +- `network_interface_mode` (string) - Network Interface Mode + +- `host_name` (string) - Host Name + +- `computer_name` (string) - Computer Name + +- `host_charge_type` (string) - Host Charge Type + +- `security_agent` (string) - Security Agent + +- `container_agent` (string) - Container Agent + +- `cloud_monitor_agent` (string) - Cloud Monitor Agent + +- `system_file_type` (string) - System File Type + +- `data_file_type` (string) - Data File Type + +- `data_disk_catalogue` (string) - Data Disk Catalogue + +- `data_disk_catalogue_suffix` (string) - Data Disk Catalogue Suffix + +- `extension_subnet_id` (string) - Extension Subnet Id + +- `extension_subnet_name` (string) - Extension Subnet Name + +- `extension_subnet_cidr_block` (string) - Extension Subnet Cidr Block + +- `extension_private_ip_address` (string) - Extension Private Ip Address + +- `extension_dns1` (string) - Extension DNS 1 + +- `extension_dns2` (string) - Extension DNS 2 + +- `extension_security_group_id` (string) - Extension Security Group Id + +- `extension_security_group_name` (string) - Extension Security Group Name + + diff --git a/docs-partials/builder/epc/KsyunEpcRunConfig-required.mdx b/docs-partials/builder/epc/KsyunEpcRunConfig-required.mdx new file mode 100644 index 0000000..f250e5d --- /dev/null +++ b/docs-partials/builder/epc/KsyunEpcRunConfig-required.mdx @@ -0,0 +1,7 @@ + + +- `host_type` (string) - Host Type + +- `source_image_id` (string) - Source Image Id + + diff --git a/docs-partials/builder/kec/KsyunEbsDataDisk-not-required.mdx b/docs-partials/builder/kec/KsyunEbsDataDisk-not-required.mdx new file mode 100644 index 0000000..49ac421 --- /dev/null +++ b/docs-partials/builder/kec/KsyunEbsDataDisk-not-required.mdx @@ -0,0 +1,5 @@ + + +- `data_disk_snapshot_id` (string) - pattern ^[a-zA-Z0-9-]{36}$ + + diff --git a/docs-partials/builder/kec/KsyunEbsDataDisk-required.mdx b/docs-partials/builder/kec/KsyunEbsDataDisk-required.mdx new file mode 100644 index 0000000..7f8f57d --- /dev/null +++ b/docs-partials/builder/kec/KsyunEbsDataDisk-required.mdx @@ -0,0 +1,7 @@ + + +- `data_disk_type` (string) - SSD3.0|| EHDD + +- `data_disk_size` (int) - [10,16000] + + diff --git a/docs-partials/builder/kec/KsyunKecRunConfig-not-required.mdx b/docs-partials/builder/kec/KsyunKecRunConfig-not-required.mdx new file mode 100644 index 0000000..41624b5 --- /dev/null +++ b/docs-partials/builder/kec/KsyunKecRunConfig-not-required.mdx @@ -0,0 +1,32 @@ + + +- `system_disk_type` (string) - Local_SSD || SSD3.0 || EHDD + +- `system_disk_size` (int) - System Disk Size + +- `data_disks` ([]KsyunEbsDataDisk) - EbsDataDisk + +- `instance_name` (string) - Display name of the instance, which is a string of 2 to 128 Chinese or + English characters. It must begin with an uppercase/lowercase letter or + a Chinese charac displayed on the Alibaba Cloud console. If this + // parameter is not specified, the default value is InstanceId of the + // instance. It cannot begin with `http://` or `https://`.ter and can contain numerals, `.`, `_`, or `-`. The + instance name is packer_kec_instance + +- `sriov_net_support` (bool) - This parameter needs to satisfy the following two conditions: + IO optimized I1, calculation optimized C1, and IO optimized I2 are more than 8C packages + We use the standard image improved by Jinshan cloud or the user-defined image made by + the instance of starting the Jinshan cloud standard image + default : false + +- `local_volume_snapshot_id` (string) - Local Volume Snapshot Id + +- `data_disk_gb` (int) - The data volume capacity is in GB. The capacity limit changes according to the definition of the instance package + type. If it is not specified when calling, it is the minimum value of the corresponding instance package type. + When the instancetype is a general-purpose host N1, N2, N3 or a local nvme I4, this parameter + does not take effect. + +- `user_data` (string) - The user-defined data provided for instance startup needs to be encoded in Base64 mode, + and the maximum data size supported is 16kb + + diff --git a/docs-partials/builder/kec/KsyunKecRunConfig-required.mdx b/docs-partials/builder/kec/KsyunKecRunConfig-required.mdx new file mode 100644 index 0000000..5353e17 --- /dev/null +++ b/docs-partials/builder/kec/KsyunKecRunConfig-required.mdx @@ -0,0 +1,10 @@ + + +- `instance_type` (string) - Instance package type, if the instance package type is not specified when calling, the default value is I1.1A. + +- `source_image_id` (string) - Source Image Id + +- `instance_charge_type` (string) - PostPaidByDay or PostPaidByHour + default is PostPaidByDay + + diff --git a/docs-partials/datasource/kmi/DatasourceOutput.mdx b/docs-partials/datasource/kmi/DatasourceOutput.mdx new file mode 100644 index 0000000..3c10aa0 --- /dev/null +++ b/docs-partials/datasource/kmi/DatasourceOutput.mdx @@ -0,0 +1,13 @@ + + +- `id` (string) - The ID of the image. + +- `name` (string) - The name of the image. + +- `creation_date` (string) - The date of creation of the image. + +- `platform` (string) - Platform + +- `image_source` (string) - Image Source + + diff --git a/docs/datasources/kmi/kmi.mdx b/docs/datasources/kmi/kmi.mdx new file mode 100644 index 0000000..60245f2 --- /dev/null +++ b/docs/datasources/kmi/kmi.mdx @@ -0,0 +1,44 @@ +--- +description: | +The Ksyun KMI data source provides information from a KMI that will be fetched based +on the filter options provided in the configuration. + +page_title: Ksyun KMI - Data Source +nav_title: Ksyun KMI +--- + +# Ksyun KMI Data Source + +Type: `ksyun-kmi` + +The Ksyun KMI data source will filter and fetch a Ksyun Images, and output all the Ksyun Machine images information that will +be then available to use in the [Ksyun builders](./). + +-> **Note:** Data sources is a feature exclusively available to HCL2 templates. + +Basic example of usage: + +```hcl +data "ksyun-kmi" "foo" { + access_key = "ksyun access key" + secret_key = "ksyun secret key" + region = "cn-shanghai-2" + platform = "centos-7.5" + name_regex = "centos-7.5.*" + image_source = "system" // import, copy, share, extend, system. + most_recent = true +} +``` +This selects the most recent Centos 7.5 Ksyun Images from remote Ksyun. Note that the data source will fail unless +*exactly* one AMI is returned. In the above example, `most_recent` will cause this to succeed by selecting the newest image. + +## Configuration Reference + +@include 'builder/KmiFilterOptions-not-required.mdx' + +@include 'builder/AccessConfig-required.mdx' + +## Output Data + +@include 'datasource/kmi/DatasourceOutput.mdx' + From 089ec4d1ed43f8cb6fce7da09bea0bb00aab41b0 Mon Sep 17 00:00:00 2001 From: Sk Lv Date: Tue, 4 Jul 2023 10:51:56 +0800 Subject: [PATCH 02/11] feat: generate ksyun pakcer plugin documentation --- .docs/builders/kec/kec.mdx | 506 ++++++++++++++++++ .docs/datasources/kmi/kmi.mdx | 98 +++- builder/kec/image_config.go | 2 + builder/kec/run_config.go | 1 + .../kec/KsyunImageConfig-not-required.mdx | 17 + .../builder/kec/KsyunImageConfig-required.mdx | 8 + .../kec/KsyunKecDiskDevice-not-required.mdx | 9 + .../kec/KsyunKecDiskDevices-not-required.mdx | 7 + docs/builders/kec/kec.mdx | 65 +++ docs/datasources/kmi/kmi.mdx | 6 +- 10 files changed, 715 insertions(+), 4 deletions(-) create mode 100644 .docs/builders/kec/kec.mdx create mode 100644 docs-partials/builder/kec/KsyunImageConfig-not-required.mdx create mode 100644 docs-partials/builder/kec/KsyunImageConfig-required.mdx create mode 100644 docs-partials/builder/kec/KsyunKecDiskDevice-not-required.mdx create mode 100644 docs-partials/builder/kec/KsyunKecDiskDevices-not-required.mdx create mode 100644 docs/builders/kec/kec.mdx diff --git a/.docs/builders/kec/kec.mdx b/.docs/builders/kec/kec.mdx new file mode 100644 index 0000000..39d6ef3 --- /dev/null +++ b/.docs/builders/kec/kec.mdx @@ -0,0 +1,506 @@ +--- +description: > +The ksyun-kec Packer builder is able to create Ksyun Images backed by + +instance storage as the root device. + +page_title: Ksyun Instance(KEC) - Builders +nav_title: Instance(KEC) +--- + +# Ksyun Image Builder (kec) + +Type: `ksyun-kec` + +The `ksyun-kec` Packer builder is able to create Ksyun Images backed by +instance storage as the root device. + + +## Configuration Reference + +There are many configuration options available for the builder. In addition to +the items listed here, you will want to look at the general configuration +references for [Image](#image-configuration), +[DiskDevices](#disk-devices-configuration), +[Access](#access-configuration), +[Run](#run-configuration) and +[General](#general-configuration) +configuration references, which are +necessary for this build to succeed and can be found further down the page. + +## Run Configuration + +### Required: + + + +- `instance_type` (string) - Instance package type, if the instance package type is not specified when calling, the default value is I1.1A. + +- `source_image_id` (string) - Source Image Id + +- `instance_charge_type` (string) - PostPaidByDay or PostPaidByHour + default is PostPaidByDay + + + + +### Optional: + + + +- `system_disk_type` (string) - Local_SSD || SSD3.0 || EHDD + +- `system_disk_size` (int) - System Disk Size + +- `data_disks` ([]KsyunEbsDataDisk) - EbsDataDisk + +- `instance_name` (string) - Display name of the instance, which is a string of 2 to 128 Chinese or + English characters. It must begin with an uppercase/lowercase letter or + a Chinese charac displayed on the Alibaba Cloud console. If this + // parameter is not specified, the default value is InstanceId of the + // instance. It cannot begin with `http://` or `https://`.ter and can contain numerals, `.`, `_`, or `-`. The + instance name is packer_kec_instance + +- `sriov_net_support` (bool) - This parameter needs to satisfy the following two conditions: + IO optimized I1, calculation optimized C1, and IO optimized I2 are more than 8C packages + We use the standard image improved by Jinshan cloud or the user-defined image made by + the instance of starting the Jinshan cloud standard image + default : false + +- `local_volume_snapshot_id` (string) - Local Volume Snapshot Id + +- `data_disk_gb` (int) - The data volume capacity is in GB. The capacity limit changes according to the definition of the instance package + type. If it is not specified when calling, it is the minimum value of the corresponding instance package type. + When the instancetype is a general-purpose host N1, N2, N3 or a local nvme I4, this parameter + does not take effect. + +- `user_data` (string) - The user-defined data provided for instance startup needs to be encoded in Base64 mode, + and the maximum data size supported is 16kb + + + + +## Access Configuration + +### Required: + + + +- `access_key` (string) - Ksyun access key must be provided unless `profile` is set, but it can + also be sourced from the `KSYUN_ACCESS_KEY` environment variable. + +- `secret_key` (string) - Ksyun secret key must be provided unless `profile` is set, but it can + also be sourced from the `KSYUN_SECRET_KEY` environment variable. + +- `region` (string) - Ksyun region must be provided unless `profile` is set, but it can + also be sourced from the `KSYUN_REGION` environment variable. + + + + +## General Configuration + +### Optional: + + + +- `vpc_id` (string) - VPC ID allocated by the system. + +- `vpc_name` (string) - the default value is packer_vpc + +- `vpc_cidr_block` (string) - 172.16.0.0/16. When not specified, the default value is 172.16.0.0/16. + +- `subnet_id` (string) - The ID of the Subnet to be used. + +- `subnet_name` (string) - the default value is packer_subnet + +- `dns1` (string) - 172.16.0.0/24. When not specified, the default value is 172.16.0.0/24. + +- `dns2` (string) - DNS 2 + +- `subnet_cidr_block` (string) - Subnet Cidr Block + +- `availability_zone` (string) - availability_zone + +- `security_group_id` (string) - ID of the security group to which a newly + created instance belongs. Mutual access is allowed between instances in one + security group. If not specified, the newly created instance will be added + to the default security group. If the default group doesn’t exist, or the + number of instances in it has reached the maximum limit, a new security + group will be created automatically. + +- `security_group_name` (string) - The security group name. The default value + is blank. [2, 128] English or Chinese characters, must begin with an + uppercase/lowercase letter or Chinese character. Can contain numbers, ., + _ or -. It cannot begin with `http://` or `https://`. + the default value is packer_security_group + +- `private_ip_address` (string) - Private IP address, which specifies any valid value within the range of subnet IP address and represents + the primary IP address of the instance. Only one can be selected and bound to the primary network card. + If this parameter is not specified, the system will automatically select one from the valid address pool at random + Valid values: standard IP address format + +- `associate_public_ip_address` (bool) - Associate Public Ip Address + +- `public_ip_charge_type` (string) - PublicIp charge type, which can be + Daily TrafficMonthly DailyPaidByTransfer HourlyInstantSettlement + Default is Daily + +- `public_ip_band_width` (int) - [1-100] + Default is 1 + +- `project_id` (string) - Default is 0 + + + + +## Image Configuration + +### Required: + + + +- `image_name` (string) - The name of the user-defined image, [2, 64] English or Chinese + characters. It must begin with an uppercase/lowercase letter or a + Chinese character, and may contain numbers, `_` or `-`. It cannot begin + with `http://` or `https://`. + + + + +### Optional: + + + +- `image_type` (string) - The type of image + LocalImage (ebs) or CommonImage (ks3) + +- `image_ignore_data_disks` (bool) - If this value is true, the image created will not include any snapshot + of data disks. The default value is false. + +- `image_copy_regions` ([]string) - Copy to the regions. + +- `image_copy_names` ([]string) - Ksyun Image Copy Names + +- `image_share_accounts` ([]string) - Share image to other accounts + +- `image_warm_up` (bool) - Set the image as warm-up for fast boot + + + + +### Source Image Filter Configuration + + + +- `most_recent` (bool) - Selects the newest created image when true. + This is most useful for selecting a daily distro build. + +- `image_source` (string) - ImageSource Valid values are import, copy, share, extend, system. + +- `name_regex` (string) - NameRegex A regex string to filter resulting images by name. + (Such as: `^CentOS 7.[1-2] 64` means CentOS 7.1 of 64-bit operating system or CentOS 7.2 of 64-bit operating system, + \"^Ubuntu 16.04 64\" means Ubuntu 16.04 of 64-bit operating system). + +- `platform` (string) - Platform type of the image system. + + +SYUN_SECRET_KEY` environment variable. + +- `region` (string) - Ksyun region must be provided unless `profile` is set, but it can + also be sourced from the `KSYUN_REGION` environment variable. + + + + + + +- `instance_type` (string) - Instance package type, if the instance package type is not specified when calling, the default value is I1.1A. + +- `source_image_id` (string) - Source Image Id + +- `instance_charge_type` (string) - PostPaidByDay or PostPaidByHour + default is PostPaidByDay + + + + +### Optional: + + + +- `vpc_id` (string) - VPC ID allocated by the system. + +- `vpc_name` (string) - the default value is packer_vpc + +- `vpc_cidr_block` (string) - 172.16.0.0/16. When not specified, the default value is 172.16.0.0/16. + +- `subnet_id` (string) - The ID of the Subnet to be used. + +- `subnet_name` (string) - the default value is packer_subnet + +- `dns1` (string) - 172.16.0.0/24. When not specified, the default value is 172.16.0.0/24. + +- `dns2` (string) - DNS 2 + +- `subnet_cidr_block` (string) - Subnet Cidr Block + +- `availability_zone` (string) - availability_zone + +- `security_group_id` (string) - ID of the security group to which a newly + created instance belongs. Mutual access is allowed between instances in one + security group. If not specified, the newly created instance will be added + to the default security group. If the default group doesn’t exist, or the + number of instances in it has reached the maximum limit, a new security + group will be created automatically. + +- `security_group_name` (string) - The security group name. The default value + is blank. [2, 128] English or Chinese characters, must begin with an + uppercase/lowercase letter or Chinese character. Can contain numbers, ., + _ or -. It cannot begin with `http://` or `https://`. + the default value is packer_security_group + +- `private_ip_address` (string) - Private IP address, which specifies any valid value within the range of subnet IP address and represents + the primary IP address of the instance. Only one can be selected and bound to the primary network card. + If this parameter is not specified, the system will automatically select one from the valid address pool at random + Valid values: standard IP address format + +- `associate_public_ip_address` (bool) - Associate Public Ip Address + +- `public_ip_charge_type` (string) - PublicIp charge type, which can be + Daily TrafficMonthly DailyPaidByTransfer HourlyInstantSettlement + Default is Daily + +- `public_ip_band_width` (int) - [1-100] + Default is 1 + +- `project_id` (string) - Default is 0 + + + + + + +- `system_disk_type` (string) - Local_SSD || SSD3.0 || EHDD + +- `system_disk_size` (int) - System Disk Size + +- `data_disks` ([]KsyunEbsDataDisk) - EbsDataDisk + +- `instance_name` (string) - Display name of the instance, which is a string of 2 to 128 Chinese or + English characters. It must begin with an uppercase/lowercase letter or + a Chinese charac displayed on the Alibaba Cloud console. If this + // parameter is not specified, the default value is InstanceId of the + // instance. It cannot begin with `http://` or `https://`.ter and can contain numerals, `.`, `_`, or `-`. The + instance name is packer_kec_instance + +- `sriov_net_support` (bool) - This parameter needs to satisfy the following two conditions: + IO optimized I1, calculation optimized C1, and IO optimized I2 are more than 8C packages + We use the standard image improved by Jinshan cloud or the user-defined image made by + the instance of starting the Jinshan cloud standard image + default : false + +- `local_volume_snapshot_id` (string) - Local Volume Snapshot Id + +- `data_disk_gb` (int) - The data volume capacity is in GB. The capacity limit changes according to the definition of the instance package + type. If it is not specified when calling, it is the minimum value of the corresponding instance package type. + When the instancetype is a general-purpose host N1, N2, N3 or a local nvme I4, this parameter + does not take effect. + +- `user_data` (string) - The user-defined data provided for instance startup needs to be encoded in Base64 mode, + and the maximum data size supported is 16kb + + + + +## Image Configuration + +### Required: + + + +- `image_name` (string) - The name of the user-defined image, [2, 64] English or Chinese + characters. It must begin with an uppercase/lowercase letter or a + Chinese character, and may contain numbers, `_` or `-`. It cannot begin + with `http://` or `https://`. + + + + +### Optional: + + + +- `image_type` (string) - The type of image + LocalImage (ebs) or CommonImage (ks3) + +- `image_ignore_data_disks` (bool) - If this value is true, the image created will not include any snapshot + of data disks. The default value is false. + +- `image_copy_regions` ([]string) - Copy to the regions. + +- `image_copy_names` ([]string) - Ksyun Image Copy Names + +- `image_share_accounts` ([]string) - Share image to other accounts + +- `image_warm_up` (bool) - Set the image as warm-up for fast boot + + + + +### Source Image Filter Configuration + + + +- `most_recent` (bool) - Selects the newest created image when true. + This is most useful for selecting a daily distro build. + +- `image_source` (string) - ImageSource Valid values are import, copy, share, extend, system. + +- `name_regex` (string) - NameRegex A regex string to filter resulting images by name. + (Such as: `^CentOS 7.[1-2] 64` means CentOS 7.1 of 64-bit operating system or CentOS 7.2 of 64-bit operating system, + \"^Ubuntu 16.04 64\" means Ubuntu 16.04 of 64-bit operating system). + +- `platform` (string) - Platform type of the image system. + + +on must be provided unless `profile` is set, but it can + also be sourced from the `KSYUN_REGION` environment variable. + + + + + + +- `instance_type` (string) - Instance package type, if the instance package type is not specified when calling, the default value is I1.1A. + +- `source_image_id` (string) - Source Image Id + +- `instance_charge_type` (string) - PostPaidByDay or PostPaidByHour + default is PostPaidByDay + + + + +### Optional: + + + +- `vpc_id` (string) - VPC ID allocated by the system. + +- `vpc_name` (string) - the default value is packer_vpc + +- `vpc_cidr_block` (string) - 172.16.0.0/16. When not specified, the default value is 172.16.0.0/16. + +- `subnet_id` (string) - The ID of the Subnet to be used. + +- `subnet_name` (string) - the default value is packer_subnet + +- `dns1` (string) - 172.16.0.0/24. When not specified, the default value is 172.16.0.0/24. + +- `dns2` (string) - DNS 2 + +- `subnet_cidr_block` (string) - Subnet Cidr Block + +- `availability_zone` (string) - availability_zone + +- `security_group_id` (string) - ID of the security group to which a newly + created instance belongs. Mutual access is allowed between instances in one + security group. If not specified, the newly created instance will be added + to the default security group. If the default group doesn’t exist, or the + number of instances in it has reached the maximum limit, a new security + group will be created automatically. + +- `security_group_name` (string) - The security group name. The default value + is blank. [2, 128] English or Chinese characters, must begin with an + uppercase/lowercase letter or Chinese character. Can contain numbers, ., + _ or -. It cannot begin with `http://` or `https://`. + the default value is packer_security_group + +- `private_ip_address` (string) - Private IP address, which specifies any valid value within the range of subnet IP address and represents + the primary IP address of the instance. Only one can be selected and bound to the primary network card. + If this parameter is not specified, the system will automatically select one from the valid address pool at random + Valid values: standard IP address format + +- `associate_public_ip_address` (bool) - Associate Public Ip Address + +- `public_ip_charge_type` (string) - PublicIp charge type, which can be + Daily TrafficMonthly DailyPaidByTransfer HourlyInstantSettlement + Default is Daily + +- `public_ip_band_width` (int) - [1-100] + Default is 1 + +- `project_id` (string) - Default is 0 + + + + + + +- `system_disk_type` (string) - Local_SSD || SSD3.0 || EHDD + +- `system_disk_size` (int) - System Disk Size + +- `data_disks` ([]KsyunEbsDataDisk) - EbsDataDisk + +- `instance_name` (string) - Display name of the instance, which is a string of 2 to 128 Chinese or + English characters. It must begin with an uppercase/lowercase letter or + a Chinese charac displayed on the Alibaba Cloud console. If this + // parameter is not specified, the default value is InstanceId of the + // instance. It cannot begin with `http://` or `https://`.ter and can contain numerals, `.`, `_`, or `-`. The + instance name is packer_kec_instance + +- `sriov_net_support` (bool) - This parameter needs to satisfy the following two conditions: + IO optimized I1, calculation optimized C1, and IO optimized I2 are more than 8C packages + We use the standard image improved by Jinshan cloud or the user-defined image made by + the instance of starting the Jinshan cloud standard image + default : false + +- `local_volume_snapshot_id` (string) - Local Volume Snapshot Id + +- `data_disk_gb` (int) - The data volume capacity is in GB. The capacity limit changes according to the definition of the instance package + type. If it is not specified when calling, it is the minimum value of the corresponding instance package type. + When the instancetype is a general-purpose host N1, N2, N3 or a local nvme I4, this parameter + does not take effect. + +- `user_data` (string) - The user-defined data provided for instance startup needs to be encoded in Base64 mode, + and the maximum data size supported is 16kb + + + + +## Image Configuration + +### Required: + + + +- `image_name` (string) - The name of the user-defined image, [2, 64] English or Chinese + characters. It must begin with an uppercase/lowercase letter or a + Chinese character, and may contain numbers, `_` or `-`. It cannot begin + with `http://` or `https://`. + + + + +### Optional: + + + +- `image_type` (string) - The type of image + LocalImage (ebs) or CommonImage (ks3) + +- `image_ignore_data_disks` (bool) - If this value is true, the image created will not include any snapshot + of data disks. The default value is false. + +- `image_copy_regions` ([]string) - Copy to the regions. + +- `image_copy_names` ([]string) - Ksyun Image Copy Names + +- `image_share_accounts` ([]string) - Share image to other accounts + +- `image_warm_up` (bool) - Set the image as warm-up for fast boot + + +.mdx' \ No newline at end of file diff --git a/.docs/datasources/kmi/kmi.mdx b/.docs/datasources/kmi/kmi.mdx index 7248ca7..74038c6 100644 --- a/.docs/datasources/kmi/kmi.mdx +++ b/.docs/datasources/kmi/kmi.mdx @@ -34,6 +34,22 @@ This selects the most recent Centos 7.5 Ksyun Images from remote Ksyun. Note tha ## Configuration Reference +### Required: + + +- `access_key` (string) - Ksyun access key must be provided unless `profile` is set, but it can + also be sourced from the `KSYUN_ACCESS_KEY` environment variable. + +- `secret_key` (string) - Ksyun secret key must be provided unless `profile` is set, but it can + also be sourced from the `KSYUN_SECRET_KEY` environment variable. + +- `region` (string) - Ksyun region must be provided unless `profile` is set, but it can + also be sourced from the `KSYUN_REGION` environment variable. + + + + +### Optional: - `most_recent` (bool) - Selects the newest created image when true. @@ -50,9 +66,70 @@ This selects the most recent Centos 7.5 Ksyun Images from remote Ksyun. Note tha - +## Output Data -- `access_key` (string) - Ksyun access key must be provided unless `profile` is set, but it can + + +- `id` (string) - The ID of the image. + +- `name` (string) - The name of the image. + +- `creation_date` (string) - The date of creation of the image. + +- `platform` (string) - Platform + +- `image_source` (string) - Image Source + + + + +d unless `profile` is set, but it can + also be sourced from the `KSYUN_ACCESS_KEY` environment variable. + +- `secret_key` (string) - Ksyun secret key must be provided unless `profile` is set, but it can + also be sourced from the `KSYUN_SECRET_KEY` environment variable. + +- `region` (string) - Ksyun region must be provided unless `profile` is set, but it can + also be sourced from the `KSYUN_REGION` environment variable. + + + + +### Optional: + + +- `most_recent` (bool) - Selects the newest created image when true. + This is most useful for selecting a daily distro build. + +- `image_source` (string) - ImageSource Valid values are import, copy, share, extend, system. + +- `name_regex` (string) - NameRegex A regex string to filter resulting images by name. + (Such as: `^CentOS 7.[1-2] 64` means CentOS 7.1 of 64-bit operating system or CentOS 7.2 of 64-bit operating system, + \"^Ubuntu 16.04 64\" means Ubuntu 16.04 of 64-bit operating system). + +- `platform` (string) - Platform type of the image system. + + + + +## Output Data + + + +- `id` (string) - The ID of the image. + +- `name` (string) - The name of the image. + +- `creation_date` (string) - The date of creation of the image. + +- `platform` (string) - Platform + +- `image_source` (string) - Image Source + + + + +d unless `profile` is set, but it can also be sourced from the `KSYUN_ACCESS_KEY` environment variable. - `secret_key` (string) - Ksyun secret key must be provided unless `profile` is set, but it can @@ -64,6 +141,23 @@ This selects the most recent Centos 7.5 Ksyun Images from remote Ksyun. Note tha +### Optional: + + +- `most_recent` (bool) - Selects the newest created image when true. + This is most useful for selecting a daily distro build. + +- `image_source` (string) - ImageSource Valid values are import, copy, share, extend, system. + +- `name_regex` (string) - NameRegex A regex string to filter resulting images by name. + (Such as: `^CentOS 7.[1-2] 64` means CentOS 7.1 of 64-bit operating system or CentOS 7.2 of 64-bit operating system, + \"^Ubuntu 16.04 64\" means Ubuntu 16.04 of 64-bit operating system). + +- `platform` (string) - Platform type of the image system. + + + + ## Output Data diff --git a/builder/kec/image_config.go b/builder/kec/image_config.go index e713035..9612a0b 100644 --- a/builder/kec/image_config.go +++ b/builder/kec/image_config.go @@ -1,3 +1,5 @@ +//go:generate packer-sdc struct-markdown + package kec import ( diff --git a/builder/kec/run_config.go b/builder/kec/run_config.go index b17a23c..2d768bd 100644 --- a/builder/kec/run_config.go +++ b/builder/kec/run_config.go @@ -1,4 +1,5 @@ //go:generate packer-sdc struct-markdown + package kec import ( diff --git a/docs-partials/builder/kec/KsyunImageConfig-not-required.mdx b/docs-partials/builder/kec/KsyunImageConfig-not-required.mdx new file mode 100644 index 0000000..72836a0 --- /dev/null +++ b/docs-partials/builder/kec/KsyunImageConfig-not-required.mdx @@ -0,0 +1,17 @@ + + +- `image_type` (string) - The type of image + LocalImage (ebs) or CommonImage (ks3) + +- `image_ignore_data_disks` (bool) - If this value is true, the image created will not include any snapshot + of data disks. The default value is false. + +- `image_copy_regions` ([]string) - Copy to the regions. + +- `image_copy_names` ([]string) - Ksyun Image Copy Names + +- `image_share_accounts` ([]string) - Share image to other accounts + +- `image_warm_up` (bool) - Set the image as warm-up for fast boot + + diff --git a/docs-partials/builder/kec/KsyunImageConfig-required.mdx b/docs-partials/builder/kec/KsyunImageConfig-required.mdx new file mode 100644 index 0000000..0f20588 --- /dev/null +++ b/docs-partials/builder/kec/KsyunImageConfig-required.mdx @@ -0,0 +1,8 @@ + + +- `image_name` (string) - The name of the user-defined image, [2, 64] English or Chinese + characters. It must begin with an uppercase/lowercase letter or a + Chinese character, and may contain numbers, `_` or `-`. It cannot begin + with `http://` or `https://`. + + diff --git a/docs-partials/builder/kec/KsyunKecDiskDevice-not-required.mdx b/docs-partials/builder/kec/KsyunKecDiskDevice-not-required.mdx new file mode 100644 index 0000000..8bab61a --- /dev/null +++ b/docs-partials/builder/kec/KsyunKecDiskDevice-not-required.mdx @@ -0,0 +1,9 @@ + + +- `snapshot_id` (string) - The instance needs to create a snapshot ID of the image, which must contain a system disk snapshot ID + Can be default: Yes, this parameter cannot be default when creating image based on snapshot + +- `data_disk_id` (string) - The ID of the data disk that the instance needs to mirror + Default: Yes + + diff --git a/docs-partials/builder/kec/KsyunKecDiskDevices-not-required.mdx b/docs-partials/builder/kec/KsyunKecDiskDevices-not-required.mdx new file mode 100644 index 0000000..af48e92 --- /dev/null +++ b/docs-partials/builder/kec/KsyunKecDiskDevices-not-required.mdx @@ -0,0 +1,7 @@ + + +- `snapshot_ids` ([]KsyunKecDiskDevice) - Snapshot Ids + +- `data_disk_ids` ([]KsyunKecDiskDevice) - Data Disk Ids + + diff --git a/docs/builders/kec/kec.mdx b/docs/builders/kec/kec.mdx new file mode 100644 index 0000000..806f20f --- /dev/null +++ b/docs/builders/kec/kec.mdx @@ -0,0 +1,65 @@ +--- +description: > +The ksyun-kec Packer builder is able to create Ksyun Images backed by + +instance storage as the root device. + +page_title: Ksyun Instance(KEC) - Builders +nav_title: Instance(KEC) +--- + +# Ksyun Image Builder (kec) + +Type: `ksyun-kec` + +The `ksyun-kec` Packer builder is able to create Ksyun Images backed by +instance storage as the root device. + + +## Configuration Reference + +There are many configuration options available for the builder. In addition to +the items listed here, you will want to look at the general configuration +references for [Image](#image-configuration), +[DiskDevices](#disk-devices-configuration), +[Access](#access-configuration), +[Run](#run-configuration) and +[General](#general-configuration) +configuration references, which are +necessary for this build to succeed and can be found further down the page. + +## Run Configuration + +### Required: + +@include 'builder/kec/KsyunKecRunConfig-required.mdx' + +### Optional: + +@include 'builder/kec/KsyunKecRunConfig-not-required.mdx' + +## Access Configuration + +### Required: + +@include 'builder/AccessConfig-required.mdx' + +## General Configuration + +### Optional: + +@include 'builder/CommonConfig-not-required.mdx' + +## Image Configuration + +### Required: + +@include 'builder/kec/KsyunImageConfig-required.mdx' + +### Optional: + +@include 'builder/kec/KsyunImageConfig-not-required.mdx' + +### Source Image Filter Configuration + +@include 'builder/KmiFilterOptions-not-required.mdx' \ No newline at end of file diff --git a/docs/datasources/kmi/kmi.mdx b/docs/datasources/kmi/kmi.mdx index 60245f2..bfcff90 100644 --- a/docs/datasources/kmi/kmi.mdx +++ b/docs/datasources/kmi/kmi.mdx @@ -34,10 +34,12 @@ This selects the most recent Centos 7.5 Ksyun Images from remote Ksyun. Note tha ## Configuration Reference -@include 'builder/KmiFilterOptions-not-required.mdx' - +### Required: @include 'builder/AccessConfig-required.mdx' +### Optional: +@include 'builder/KmiFilterOptions-not-required.mdx' + ## Output Data @include 'datasource/kmi/DatasourceOutput.mdx' From d61523d51eff2b447136ab8945da8118eaa85999 Mon Sep 17 00:00:00 2001 From: Sk Lv Date: Tue, 4 Jul 2023 11:56:41 +0800 Subject: [PATCH 03/11] docs: add basic example --- .docs/builders/kec/kec.mdx | 201 ++++++++++++++++++++++++++++++++++ .docs/datasources/kmi/kmi.mdx | 46 ++++++++ docs/builders/kec/kec.mdx | 72 +++++++++++- 3 files changed, 318 insertions(+), 1 deletion(-) diff --git a/.docs/builders/kec/kec.mdx b/.docs/builders/kec/kec.mdx index 39d6ef3..0919b18 100644 --- a/.docs/builders/kec/kec.mdx +++ b/.docs/builders/kec/kec.mdx @@ -189,6 +189,207 @@ necessary for this build to succeed and can be found further down the page. +### Source Image Filter Configuration + + + +- `most_recent` (bool) - Selects the newest created image when true. + This is most useful for selecting a daily distro build. + +- `image_source` (string) - ImageSource Valid values are import, copy, share, extend, system. + +- `name_regex` (string) - NameRegex A regex string to filter resulting images by name. + (Such as: `^CentOS 7.[1-2] 64` means CentOS 7.1 of 64-bit operating system or CentOS 7.2 of 64-bit operating system, + \"^Ubuntu 16.04 64\" means Ubuntu 16.04 of 64-bit operating system). + +- `platform` (string) - Platform type of the image system. + + + + +## Basic Example + +Here is a basic example. It is completely valid but excludes the access keys: + +```hcl +packer { + required_plugins { + ksyun = { + version = ">=0.1.0" + source = "github.com/kingsoftcloud/ksyun" + } + } +} + +variable ak { + type = string + default = "${env("KSYUN_ACCESS_KEY")}" +} + +variable sk { + type = string + default = "${env("KSYUN_SECRET_KEY")}" +} + +source "ksyun-kec" "test" { + access_key = var.ak + secret_key = var.sk + region = "cn-shanghai-2" + image_name = "packer_test" + source_image_id = "IMG-05f198b3-9df6-4f94-a3e3-dcee4b48c4aa" + instance_type = "N3.1B" + ssh_username = "root" + + # 此参数用于跳过ssh + # communicator = "none" + + # 如需使用ssh,须保证网络能通,如果不在同一个网络环境下就要挂公网ip + associate_public_ip_address = true + + ssh_clear_authorized_keys = true + + # 此参数为true时,data_disks的硬盘不会打快照加入镜像 + image_ignore_data_disks = true + + data_disks { + data_disk_type = "SSD3.0" + data_disk_size = 50 + } + + # 复制镜像到以下region + image_copy_regions = ["cn-beijing-6", "cn-guangzhou-1"] + + # 镜像复制后的名称, 不命名则使用原镜像的名称 + image_copy_names = ["copy-test"] + + # 开启镜像预热 + image_warm_up = true + + # 镜像共享给其他用户 + # image_share_accounts = ["xxxxxxxx", "xxxxxxxx"] +} + +build { + sources = ["source.ksyun-kec.test"] + provisioner "shell" { + inline = ["sleep 10", "df -h"] + } +} +```(string) - The user-defined data provided for instance startup needs to be encoded in Base64 mode, + and the maximum data size supported is 16kb + + + + +## Access Configuration + +### Required: + + + +- `access_key` (string) - Ksyun access key must be provided unless `profile` is set, but it can + also be sourced from the `KSYUN_ACCESS_KEY` environment variable. + +- `secret_key` (string) - Ksyun secret key must be provided unless `profile` is set, but it can + also be sourced from the `KSYUN_SECRET_KEY` environment variable. + +- `region` (string) - Ksyun region must be provided unless `profile` is set, but it can + also be sourced from the `KSYUN_REGION` environment variable. + + + + +## General Configuration + +### Optional: + + + +- `vpc_id` (string) - VPC ID allocated by the system. + +- `vpc_name` (string) - the default value is packer_vpc + +- `vpc_cidr_block` (string) - 172.16.0.0/16. When not specified, the default value is 172.16.0.0/16. + +- `subnet_id` (string) - The ID of the Subnet to be used. + +- `subnet_name` (string) - the default value is packer_subnet + +- `dns1` (string) - 172.16.0.0/24. When not specified, the default value is 172.16.0.0/24. + +- `dns2` (string) - DNS 2 + +- `subnet_cidr_block` (string) - Subnet Cidr Block + +- `availability_zone` (string) - availability_zone + +- `security_group_id` (string) - ID of the security group to which a newly + created instance belongs. Mutual access is allowed between instances in one + security group. If not specified, the newly created instance will be added + to the default security group. If the default group doesn’t exist, or the + number of instances in it has reached the maximum limit, a new security + group will be created automatically. + +- `security_group_name` (string) - The security group name. The default value + is blank. [2, 128] English or Chinese characters, must begin with an + uppercase/lowercase letter or Chinese character. Can contain numbers, ., + _ or -. It cannot begin with `http://` or `https://`. + the default value is packer_security_group + +- `private_ip_address` (string) - Private IP address, which specifies any valid value within the range of subnet IP address and represents + the primary IP address of the instance. Only one can be selected and bound to the primary network card. + If this parameter is not specified, the system will automatically select one from the valid address pool at random + Valid values: standard IP address format + +- `associate_public_ip_address` (bool) - Associate Public Ip Address + +- `public_ip_charge_type` (string) - PublicIp charge type, which can be + Daily TrafficMonthly DailyPaidByTransfer HourlyInstantSettlement + Default is Daily + +- `public_ip_band_width` (int) - [1-100] + Default is 1 + +- `project_id` (string) - Default is 0 + + + + +## Image Configuration + +### Required: + + + +- `image_name` (string) - The name of the user-defined image, [2, 64] English or Chinese + characters. It must begin with an uppercase/lowercase letter or a + Chinese character, and may contain numbers, `_` or `-`. It cannot begin + with `http://` or `https://`. + + + + +### Optional: + + + +- `image_type` (string) - The type of image + LocalImage (ebs) or CommonImage (ks3) + +- `image_ignore_data_disks` (bool) - If this value is true, the image created will not include any snapshot + of data disks. The default value is false. + +- `image_copy_regions` ([]string) - Copy to the regions. + +- `image_copy_names` ([]string) - Ksyun Image Copy Names + +- `image_share_accounts` ([]string) - Share image to other accounts + +- `image_warm_up` (bool) - Set the image as warm-up for fast boot + + + + ### Source Image Filter Configuration diff --git a/.docs/datasources/kmi/kmi.mdx b/.docs/datasources/kmi/kmi.mdx index 74038c6..e610f96 100644 --- a/.docs/datasources/kmi/kmi.mdx +++ b/.docs/datasources/kmi/kmi.mdx @@ -175,3 +175,49 @@ d unless `profile` is set, but it can +d unless `profile` is set, but it can + also be sourced from the `KSYUN_ACCESS_KEY` environment variable. + +- `secret_key` (string) - Ksyun secret key must be provided unless `profile` is set, but it can + also be sourced from the `KSYUN_SECRET_KEY` environment variable. + +- `region` (string) - Ksyun region must be provided unless `profile` is set, but it can + also be sourced from the `KSYUN_REGION` environment variable. + + + + +### Optional: + + +- `most_recent` (bool) - Selects the newest created image when true. + This is most useful for selecting a daily distro build. + +- `image_source` (string) - ImageSource Valid values are import, copy, share, extend, system. + +- `name_regex` (string) - NameRegex A regex string to filter resulting images by name. + (Such as: `^CentOS 7.[1-2] 64` means CentOS 7.1 of 64-bit operating system or CentOS 7.2 of 64-bit operating system, + \"^Ubuntu 16.04 64\" means Ubuntu 16.04 of 64-bit operating system). + +- `platform` (string) - Platform type of the image system. + + + + +## Output Data + + + +- `id` (string) - The ID of the image. + +- `name` (string) - The name of the image. + +- `creation_date` (string) - The date of creation of the image. + +- `platform` (string) - Platform + +- `image_source` (string) - Image Source + + + + diff --git a/docs/builders/kec/kec.mdx b/docs/builders/kec/kec.mdx index 806f20f..f03d7e5 100644 --- a/docs/builders/kec/kec.mdx +++ b/docs/builders/kec/kec.mdx @@ -62,4 +62,74 @@ necessary for this build to succeed and can be found further down the page. ### Source Image Filter Configuration -@include 'builder/KmiFilterOptions-not-required.mdx' \ No newline at end of file +@include 'builder/KmiFilterOptions-not-required.mdx' + +## Basic Example + +Here is a basic example. It is completely valid but excludes the access keys: + +```hcl +packer { + required_plugins { + ksyun = { + version = ">=0.1.0" + source = "github.com/kingsoftcloud/ksyun" + } + } +} + +variable ak { + type = string + default = "${env("KSYUN_ACCESS_KEY")}" +} + +variable sk { + type = string + default = "${env("KSYUN_SECRET_KEY")}" +} + +source "ksyun-kec" "test" { + access_key = var.ak + secret_key = var.sk + region = "cn-shanghai-2" + image_name = "packer_test" + source_image_id = "IMG-05f198b3-9df6-4f94-a3e3-dcee4b48c4aa" + instance_type = "N3.1B" + ssh_username = "root" + + # 此参数用于跳过ssh + # communicator = "none" + + # 如需使用ssh,须保证网络能通,如果不在同一个网络环境下就要挂公网ip + associate_public_ip_address = true + + ssh_clear_authorized_keys = true + + # 此参数为true时,data_disks的硬盘不会打快照加入镜像 + image_ignore_data_disks = true + + data_disks { + data_disk_type = "SSD3.0" + data_disk_size = 50 + } + + # 复制镜像到以下region + image_copy_regions = ["cn-beijing-6", "cn-guangzhou-1"] + + # 镜像复制后的名称, 不命名则使用原镜像的名称 + image_copy_names = ["copy-test"] + + # 开启镜像预热 + image_warm_up = true + + # 镜像共享给其他用户 + # image_share_accounts = ["xxxxxxxx", "xxxxxxxx"] +} + +build { + sources = ["source.ksyun-kec.test"] + provisioner "shell" { + inline = ["sleep 10", "df -h"] + } +} +``` \ No newline at end of file From 38774c8c5b4996d4d0cd9d5fbce014bc6f30948f Mon Sep 17 00:00:00 2001 From: Sk Lv Date: Tue, 4 Jul 2023 17:26:40 +0800 Subject: [PATCH 04/11] docs: add datasource example usage --- .goreleaser.yml | 11 ++++++-- Makefile | 5 ++-- docs/builders/kec/kec.mdx | 2 ++ docs/datasources/kmi/kmi.mdx | 51 ++++++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 4 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index 64e4393..91e0117 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -5,6 +5,9 @@ before: # this is just an example and not a requirement for provider building/publishing - go mod tidy - go mod vendor + # As part of the release doc files are included as a separate deliverable for + # consumption by Packer.io. To include a separate docs.zip uncomment the following command. + - make ci-release-docs builds: - env: # goreleaser does not work with CGO, it could also complicate @@ -51,7 +54,11 @@ signs: - "--detach-sign" - "${artifact}" release: -# If you want to manually examine the release before its live, uncomment this line: -# draft: true + # If you want to manually examine the release before its live, uncomment this line: + # draft: true + # As part of the release doc files are included as a separate deliverable for consumption by Packer.io. + # To include a separate docs.zip uncomment the extra_files config and the docs.zip command hook above. + extra_files: + - glob: ./docs.zip changelog: skip: true diff --git a/Makefile b/Makefile index 96e0259..6a0eebb 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,9 @@ test_integration: install-packer-sdc: ## Install packer sofware development command go install github.com/hashicorp/packer-plugin-sdk/cmd/packer-sdc@${HASHICORP_PACKER_PLUGIN_SDK_VERSION} +ci-release-docs: install-packer-sdc + @packer-sdc renderdocs -src docs -partials docs-partials/ -dst docs/ + @/bin/sh -c "[ -d docs ] && zip -r docs.zip docs/" lint: go vet . @@ -26,7 +29,5 @@ install: build generate: install-packer-sdc go generate ./... - packer-sdc renderdocs -src ./docs -dst ./.docs -partials ./docs-partials - .PHONY: default test test_integration lint build install diff --git a/docs/builders/kec/kec.mdx b/docs/builders/kec/kec.mdx index f03d7e5..9f6f34d 100644 --- a/docs/builders/kec/kec.mdx +++ b/docs/builders/kec/kec.mdx @@ -68,6 +68,8 @@ necessary for this build to succeed and can be found further down the page. Here is a basic example. It is completely valid but excludes the access keys: +### Example Usage + ```hcl packer { required_plugins { diff --git a/docs/datasources/kmi/kmi.mdx b/docs/datasources/kmi/kmi.mdx index bfcff90..9913be6 100644 --- a/docs/datasources/kmi/kmi.mdx +++ b/docs/datasources/kmi/kmi.mdx @@ -44,3 +44,54 @@ This selects the most recent Centos 7.5 Ksyun Images from remote Ksyun. Note tha @include 'datasource/kmi/DatasourceOutput.mdx' +## Basic Example + +Here is a basic example. It is completely valid but excludes the access keys: + +### Example Usage + +```hcl +packer { + required_plugins { + ksyun = { + version = ">=0.1.0" + source = "github.com/kingsoftcloud/ksyun" + } + } +} + +variable ak { + type = string + default = "${env("KSYUN_ACCESS_KEY")}" +} + +variable sk { + type = string + default = "${env("KSYUN_SECRET_KEY")}" +} + +data "ksyun-kmi" "foo" { + access_key = var.ak + secret_key = var.sk + region = "cn-shanghai-2" + platform = "centos-7.5" + name_regex = "centos-7.5.*" + image_source = "system" // import, copy, share, extend, system. + most_recent = true +} + + +source "ksyun-kec" "test" { + access_key = var.ak + secret_key = var.sk + region = "cn-shanghai-2" + image_name = "packer_test" + source_image_id = "IMG-05f198b3-9df6-4f94-a3e3-dcee4b48c4aa" + instance_type = "N3.1B" + ssh_username = "root" +} + +build { + sources = ["source.ksyun-kec.test"] +} +``` \ No newline at end of file From 35555b359eec6856ad32900062925bb864ed24a6 Mon Sep 17 00:00:00 2001 From: "Sk.Lv" Date: Tue, 1 Aug 2023 10:26:10 +0800 Subject: [PATCH 05/11] docs: completed documents --- .docs/builders/epc/epc.mdx | 61 ++ .docs/builders/kec/kec.mdx | 590 +----------------- .docs/datasources/kmi/kmi.mdx | 171 ++--- Makefile | 2 +- builder/epc/image_config.go | 8 +- builder/epc/run_config.go | 76 ++- builder/kec/image_config.go | 3 +- builder/kec/run_config.go | 2 +- .../epc/KsyunEpcRunConfig-not-required.mdx | 40 +- .../epc/KsyunEpcRunConfig-required.mdx | 5 +- .../epc/KsyunImageConfig-not-required.mdx | 8 + .../kec/KsyunImageConfig-not-required.mdx | 2 +- .../kec/KsyunKecRunConfig-not-required.mdx | 12 + docs/builders/kec/kec.mdx | 137 ---- docs/datasources/kmi/kmi.mdx | 97 --- 15 files changed, 224 insertions(+), 990 deletions(-) create mode 100644 .docs/builders/epc/epc.mdx create mode 100644 docs-partials/builder/epc/KsyunImageConfig-not-required.mdx delete mode 100644 docs/builders/kec/kec.mdx delete mode 100644 docs/datasources/kmi/kmi.mdx diff --git a/.docs/builders/epc/epc.mdx b/.docs/builders/epc/epc.mdx new file mode 100644 index 0000000..eecc377 --- /dev/null +++ b/.docs/builders/epc/epc.mdx @@ -0,0 +1,61 @@ +--- +description: > +The ksyun-epc Packer builder is able to create Ksyun Images backed by + +instance storage as the root device. + +page_title: Ksyun EPC - Builders +nav_title: Epc +--- + +# Ksyun Image Builder (epc) + +Type: `ksyun-epc` + +The `ksyun-epc` Packer builder is able to create Ksyun Images backed by +bare metal instance storage as the root device. + + +## Configuration Reference + +There are many configuration options available for the builder. In addition to +the items listed here, you will want to look at the general configuration +references for [Image](#image-configuration), +[Access](#access-configuration), +[Run](#run-configuration) and +[General](#general-configuration) +configuration references, which are +necessary for this build to succeed and can be found further down the page. + +## Run Configuration +### Required: + +@include 'builder/epc/KsyunEpcRunConfig-required.mdx' + +### Optional: + +@include 'builder/epc/KsyunEpcRunConfig-not-required.mdx' + +## Access Configuration + +### Required: + +@include 'builder/AccessConfig-required.mdx' + +## General Configuration + +### Optional: + +@include 'builder/CommonConfig-not-required.mdx' + +## Image Configuration + +### Optional: + +@include 'builder/epc/KsyunImageConfig-not-required.mdx' + +## Basic Example + +Here is a basic example. It is completely valid but excludes the access keys: + +### Example Usage diff --git a/.docs/builders/kec/kec.mdx b/.docs/builders/kec/kec.mdx index 0919b18..9f6f34d 100644 --- a/.docs/builders/kec/kec.mdx +++ b/.docs/builders/kec/kec.mdx @@ -32,185 +32,44 @@ necessary for this build to succeed and can be found further down the page. ### Required: - - -- `instance_type` (string) - Instance package type, if the instance package type is not specified when calling, the default value is I1.1A. - -- `source_image_id` (string) - Source Image Id - -- `instance_charge_type` (string) - PostPaidByDay or PostPaidByHour - default is PostPaidByDay - - - +@include 'builder/kec/KsyunKecRunConfig-required.mdx' ### Optional: - - -- `system_disk_type` (string) - Local_SSD || SSD3.0 || EHDD - -- `system_disk_size` (int) - System Disk Size - -- `data_disks` ([]KsyunEbsDataDisk) - EbsDataDisk - -- `instance_name` (string) - Display name of the instance, which is a string of 2 to 128 Chinese or - English characters. It must begin with an uppercase/lowercase letter or - a Chinese charac displayed on the Alibaba Cloud console. If this - // parameter is not specified, the default value is InstanceId of the - // instance. It cannot begin with `http://` or `https://`.ter and can contain numerals, `.`, `_`, or `-`. The - instance name is packer_kec_instance - -- `sriov_net_support` (bool) - This parameter needs to satisfy the following two conditions: - IO optimized I1, calculation optimized C1, and IO optimized I2 are more than 8C packages - We use the standard image improved by Jinshan cloud or the user-defined image made by - the instance of starting the Jinshan cloud standard image - default : false - -- `local_volume_snapshot_id` (string) - Local Volume Snapshot Id - -- `data_disk_gb` (int) - The data volume capacity is in GB. The capacity limit changes according to the definition of the instance package - type. If it is not specified when calling, it is the minimum value of the corresponding instance package type. - When the instancetype is a general-purpose host N1, N2, N3 or a local nvme I4, this parameter - does not take effect. - -- `user_data` (string) - The user-defined data provided for instance startup needs to be encoded in Base64 mode, - and the maximum data size supported is 16kb - - - +@include 'builder/kec/KsyunKecRunConfig-not-required.mdx' ## Access Configuration ### Required: - - -- `access_key` (string) - Ksyun access key must be provided unless `profile` is set, but it can - also be sourced from the `KSYUN_ACCESS_KEY` environment variable. - -- `secret_key` (string) - Ksyun secret key must be provided unless `profile` is set, but it can - also be sourced from the `KSYUN_SECRET_KEY` environment variable. - -- `region` (string) - Ksyun region must be provided unless `profile` is set, but it can - also be sourced from the `KSYUN_REGION` environment variable. - - - +@include 'builder/AccessConfig-required.mdx' ## General Configuration ### Optional: - - -- `vpc_id` (string) - VPC ID allocated by the system. - -- `vpc_name` (string) - the default value is packer_vpc - -- `vpc_cidr_block` (string) - 172.16.0.0/16. When not specified, the default value is 172.16.0.0/16. - -- `subnet_id` (string) - The ID of the Subnet to be used. - -- `subnet_name` (string) - the default value is packer_subnet - -- `dns1` (string) - 172.16.0.0/24. When not specified, the default value is 172.16.0.0/24. - -- `dns2` (string) - DNS 2 - -- `subnet_cidr_block` (string) - Subnet Cidr Block - -- `availability_zone` (string) - availability_zone - -- `security_group_id` (string) - ID of the security group to which a newly - created instance belongs. Mutual access is allowed between instances in one - security group. If not specified, the newly created instance will be added - to the default security group. If the default group doesn’t exist, or the - number of instances in it has reached the maximum limit, a new security - group will be created automatically. - -- `security_group_name` (string) - The security group name. The default value - is blank. [2, 128] English or Chinese characters, must begin with an - uppercase/lowercase letter or Chinese character. Can contain numbers, ., - _ or -. It cannot begin with `http://` or `https://`. - the default value is packer_security_group - -- `private_ip_address` (string) - Private IP address, which specifies any valid value within the range of subnet IP address and represents - the primary IP address of the instance. Only one can be selected and bound to the primary network card. - If this parameter is not specified, the system will automatically select one from the valid address pool at random - Valid values: standard IP address format - -- `associate_public_ip_address` (bool) - Associate Public Ip Address - -- `public_ip_charge_type` (string) - PublicIp charge type, which can be - Daily TrafficMonthly DailyPaidByTransfer HourlyInstantSettlement - Default is Daily - -- `public_ip_band_width` (int) - [1-100] - Default is 1 - -- `project_id` (string) - Default is 0 - - - +@include 'builder/CommonConfig-not-required.mdx' ## Image Configuration ### Required: - - -- `image_name` (string) - The name of the user-defined image, [2, 64] English or Chinese - characters. It must begin with an uppercase/lowercase letter or a - Chinese character, and may contain numbers, `_` or `-`. It cannot begin - with `http://` or `https://`. - - - +@include 'builder/kec/KsyunImageConfig-required.mdx' ### Optional: - - -- `image_type` (string) - The type of image - LocalImage (ebs) or CommonImage (ks3) - -- `image_ignore_data_disks` (bool) - If this value is true, the image created will not include any snapshot - of data disks. The default value is false. - -- `image_copy_regions` ([]string) - Copy to the regions. - -- `image_copy_names` ([]string) - Ksyun Image Copy Names - -- `image_share_accounts` ([]string) - Share image to other accounts - -- `image_warm_up` (bool) - Set the image as warm-up for fast boot - - - +@include 'builder/kec/KsyunImageConfig-not-required.mdx' ### Source Image Filter Configuration - - -- `most_recent` (bool) - Selects the newest created image when true. - This is most useful for selecting a daily distro build. - -- `image_source` (string) - ImageSource Valid values are import, copy, share, extend, system. - -- `name_regex` (string) - NameRegex A regex string to filter resulting images by name. - (Such as: `^CentOS 7.[1-2] 64` means CentOS 7.1 of 64-bit operating system or CentOS 7.2 of 64-bit operating system, - \"^Ubuntu 16.04 64\" means Ubuntu 16.04 of 64-bit operating system). - -- `platform` (string) - Platform type of the image system. - - - +@include 'builder/KmiFilterOptions-not-required.mdx' ## Basic Example Here is a basic example. It is completely valid but excludes the access keys: +### Example Usage + ```hcl packer { required_plugins { @@ -275,433 +134,4 @@ build { inline = ["sleep 10", "df -h"] } } -```(string) - The user-defined data provided for instance startup needs to be encoded in Base64 mode, - and the maximum data size supported is 16kb - - - - -## Access Configuration - -### Required: - - - -- `access_key` (string) - Ksyun access key must be provided unless `profile` is set, but it can - also be sourced from the `KSYUN_ACCESS_KEY` environment variable. - -- `secret_key` (string) - Ksyun secret key must be provided unless `profile` is set, but it can - also be sourced from the `KSYUN_SECRET_KEY` environment variable. - -- `region` (string) - Ksyun region must be provided unless `profile` is set, but it can - also be sourced from the `KSYUN_REGION` environment variable. - - - - -## General Configuration - -### Optional: - - - -- `vpc_id` (string) - VPC ID allocated by the system. - -- `vpc_name` (string) - the default value is packer_vpc - -- `vpc_cidr_block` (string) - 172.16.0.0/16. When not specified, the default value is 172.16.0.0/16. - -- `subnet_id` (string) - The ID of the Subnet to be used. - -- `subnet_name` (string) - the default value is packer_subnet - -- `dns1` (string) - 172.16.0.0/24. When not specified, the default value is 172.16.0.0/24. - -- `dns2` (string) - DNS 2 - -- `subnet_cidr_block` (string) - Subnet Cidr Block - -- `availability_zone` (string) - availability_zone - -- `security_group_id` (string) - ID of the security group to which a newly - created instance belongs. Mutual access is allowed between instances in one - security group. If not specified, the newly created instance will be added - to the default security group. If the default group doesn’t exist, or the - number of instances in it has reached the maximum limit, a new security - group will be created automatically. - -- `security_group_name` (string) - The security group name. The default value - is blank. [2, 128] English or Chinese characters, must begin with an - uppercase/lowercase letter or Chinese character. Can contain numbers, ., - _ or -. It cannot begin with `http://` or `https://`. - the default value is packer_security_group - -- `private_ip_address` (string) - Private IP address, which specifies any valid value within the range of subnet IP address and represents - the primary IP address of the instance. Only one can be selected and bound to the primary network card. - If this parameter is not specified, the system will automatically select one from the valid address pool at random - Valid values: standard IP address format - -- `associate_public_ip_address` (bool) - Associate Public Ip Address - -- `public_ip_charge_type` (string) - PublicIp charge type, which can be - Daily TrafficMonthly DailyPaidByTransfer HourlyInstantSettlement - Default is Daily - -- `public_ip_band_width` (int) - [1-100] - Default is 1 - -- `project_id` (string) - Default is 0 - - - - -## Image Configuration - -### Required: - - - -- `image_name` (string) - The name of the user-defined image, [2, 64] English or Chinese - characters. It must begin with an uppercase/lowercase letter or a - Chinese character, and may contain numbers, `_` or `-`. It cannot begin - with `http://` or `https://`. - - - - -### Optional: - - - -- `image_type` (string) - The type of image - LocalImage (ebs) or CommonImage (ks3) - -- `image_ignore_data_disks` (bool) - If this value is true, the image created will not include any snapshot - of data disks. The default value is false. - -- `image_copy_regions` ([]string) - Copy to the regions. - -- `image_copy_names` ([]string) - Ksyun Image Copy Names - -- `image_share_accounts` ([]string) - Share image to other accounts - -- `image_warm_up` (bool) - Set the image as warm-up for fast boot - - - - -### Source Image Filter Configuration - - - -- `most_recent` (bool) - Selects the newest created image when true. - This is most useful for selecting a daily distro build. - -- `image_source` (string) - ImageSource Valid values are import, copy, share, extend, system. - -- `name_regex` (string) - NameRegex A regex string to filter resulting images by name. - (Such as: `^CentOS 7.[1-2] 64` means CentOS 7.1 of 64-bit operating system or CentOS 7.2 of 64-bit operating system, - \"^Ubuntu 16.04 64\" means Ubuntu 16.04 of 64-bit operating system). - -- `platform` (string) - Platform type of the image system. - - -SYUN_SECRET_KEY` environment variable. - -- `region` (string) - Ksyun region must be provided unless `profile` is set, but it can - also be sourced from the `KSYUN_REGION` environment variable. - - - - - - -- `instance_type` (string) - Instance package type, if the instance package type is not specified when calling, the default value is I1.1A. - -- `source_image_id` (string) - Source Image Id - -- `instance_charge_type` (string) - PostPaidByDay or PostPaidByHour - default is PostPaidByDay - - - - -### Optional: - - - -- `vpc_id` (string) - VPC ID allocated by the system. - -- `vpc_name` (string) - the default value is packer_vpc - -- `vpc_cidr_block` (string) - 172.16.0.0/16. When not specified, the default value is 172.16.0.0/16. - -- `subnet_id` (string) - The ID of the Subnet to be used. - -- `subnet_name` (string) - the default value is packer_subnet - -- `dns1` (string) - 172.16.0.0/24. When not specified, the default value is 172.16.0.0/24. - -- `dns2` (string) - DNS 2 - -- `subnet_cidr_block` (string) - Subnet Cidr Block - -- `availability_zone` (string) - availability_zone - -- `security_group_id` (string) - ID of the security group to which a newly - created instance belongs. Mutual access is allowed between instances in one - security group. If not specified, the newly created instance will be added - to the default security group. If the default group doesn’t exist, or the - number of instances in it has reached the maximum limit, a new security - group will be created automatically. - -- `security_group_name` (string) - The security group name. The default value - is blank. [2, 128] English or Chinese characters, must begin with an - uppercase/lowercase letter or Chinese character. Can contain numbers, ., - _ or -. It cannot begin with `http://` or `https://`. - the default value is packer_security_group - -- `private_ip_address` (string) - Private IP address, which specifies any valid value within the range of subnet IP address and represents - the primary IP address of the instance. Only one can be selected and bound to the primary network card. - If this parameter is not specified, the system will automatically select one from the valid address pool at random - Valid values: standard IP address format - -- `associate_public_ip_address` (bool) - Associate Public Ip Address - -- `public_ip_charge_type` (string) - PublicIp charge type, which can be - Daily TrafficMonthly DailyPaidByTransfer HourlyInstantSettlement - Default is Daily - -- `public_ip_band_width` (int) - [1-100] - Default is 1 - -- `project_id` (string) - Default is 0 - - - - - - -- `system_disk_type` (string) - Local_SSD || SSD3.0 || EHDD - -- `system_disk_size` (int) - System Disk Size - -- `data_disks` ([]KsyunEbsDataDisk) - EbsDataDisk - -- `instance_name` (string) - Display name of the instance, which is a string of 2 to 128 Chinese or - English characters. It must begin with an uppercase/lowercase letter or - a Chinese charac displayed on the Alibaba Cloud console. If this - // parameter is not specified, the default value is InstanceId of the - // instance. It cannot begin with `http://` or `https://`.ter and can contain numerals, `.`, `_`, or `-`. The - instance name is packer_kec_instance - -- `sriov_net_support` (bool) - This parameter needs to satisfy the following two conditions: - IO optimized I1, calculation optimized C1, and IO optimized I2 are more than 8C packages - We use the standard image improved by Jinshan cloud or the user-defined image made by - the instance of starting the Jinshan cloud standard image - default : false - -- `local_volume_snapshot_id` (string) - Local Volume Snapshot Id - -- `data_disk_gb` (int) - The data volume capacity is in GB. The capacity limit changes according to the definition of the instance package - type. If it is not specified when calling, it is the minimum value of the corresponding instance package type. - When the instancetype is a general-purpose host N1, N2, N3 or a local nvme I4, this parameter - does not take effect. - -- `user_data` (string) - The user-defined data provided for instance startup needs to be encoded in Base64 mode, - and the maximum data size supported is 16kb - - - - -## Image Configuration - -### Required: - - - -- `image_name` (string) - The name of the user-defined image, [2, 64] English or Chinese - characters. It must begin with an uppercase/lowercase letter or a - Chinese character, and may contain numbers, `_` or `-`. It cannot begin - with `http://` or `https://`. - - - - -### Optional: - - - -- `image_type` (string) - The type of image - LocalImage (ebs) or CommonImage (ks3) - -- `image_ignore_data_disks` (bool) - If this value is true, the image created will not include any snapshot - of data disks. The default value is false. - -- `image_copy_regions` ([]string) - Copy to the regions. - -- `image_copy_names` ([]string) - Ksyun Image Copy Names - -- `image_share_accounts` ([]string) - Share image to other accounts - -- `image_warm_up` (bool) - Set the image as warm-up for fast boot - - - - -### Source Image Filter Configuration - - - -- `most_recent` (bool) - Selects the newest created image when true. - This is most useful for selecting a daily distro build. - -- `image_source` (string) - ImageSource Valid values are import, copy, share, extend, system. - -- `name_regex` (string) - NameRegex A regex string to filter resulting images by name. - (Such as: `^CentOS 7.[1-2] 64` means CentOS 7.1 of 64-bit operating system or CentOS 7.2 of 64-bit operating system, - \"^Ubuntu 16.04 64\" means Ubuntu 16.04 of 64-bit operating system). - -- `platform` (string) - Platform type of the image system. - - -on must be provided unless `profile` is set, but it can - also be sourced from the `KSYUN_REGION` environment variable. - - - - - - -- `instance_type` (string) - Instance package type, if the instance package type is not specified when calling, the default value is I1.1A. - -- `source_image_id` (string) - Source Image Id - -- `instance_charge_type` (string) - PostPaidByDay or PostPaidByHour - default is PostPaidByDay - - - - -### Optional: - - - -- `vpc_id` (string) - VPC ID allocated by the system. - -- `vpc_name` (string) - the default value is packer_vpc - -- `vpc_cidr_block` (string) - 172.16.0.0/16. When not specified, the default value is 172.16.0.0/16. - -- `subnet_id` (string) - The ID of the Subnet to be used. - -- `subnet_name` (string) - the default value is packer_subnet - -- `dns1` (string) - 172.16.0.0/24. When not specified, the default value is 172.16.0.0/24. - -- `dns2` (string) - DNS 2 - -- `subnet_cidr_block` (string) - Subnet Cidr Block - -- `availability_zone` (string) - availability_zone - -- `security_group_id` (string) - ID of the security group to which a newly - created instance belongs. Mutual access is allowed between instances in one - security group. If not specified, the newly created instance will be added - to the default security group. If the default group doesn’t exist, or the - number of instances in it has reached the maximum limit, a new security - group will be created automatically. - -- `security_group_name` (string) - The security group name. The default value - is blank. [2, 128] English or Chinese characters, must begin with an - uppercase/lowercase letter or Chinese character. Can contain numbers, ., - _ or -. It cannot begin with `http://` or `https://`. - the default value is packer_security_group - -- `private_ip_address` (string) - Private IP address, which specifies any valid value within the range of subnet IP address and represents - the primary IP address of the instance. Only one can be selected and bound to the primary network card. - If this parameter is not specified, the system will automatically select one from the valid address pool at random - Valid values: standard IP address format - -- `associate_public_ip_address` (bool) - Associate Public Ip Address - -- `public_ip_charge_type` (string) - PublicIp charge type, which can be - Daily TrafficMonthly DailyPaidByTransfer HourlyInstantSettlement - Default is Daily - -- `public_ip_band_width` (int) - [1-100] - Default is 1 - -- `project_id` (string) - Default is 0 - - - - - - -- `system_disk_type` (string) - Local_SSD || SSD3.0 || EHDD - -- `system_disk_size` (int) - System Disk Size - -- `data_disks` ([]KsyunEbsDataDisk) - EbsDataDisk - -- `instance_name` (string) - Display name of the instance, which is a string of 2 to 128 Chinese or - English characters. It must begin with an uppercase/lowercase letter or - a Chinese charac displayed on the Alibaba Cloud console. If this - // parameter is not specified, the default value is InstanceId of the - // instance. It cannot begin with `http://` or `https://`.ter and can contain numerals, `.`, `_`, or `-`. The - instance name is packer_kec_instance - -- `sriov_net_support` (bool) - This parameter needs to satisfy the following two conditions: - IO optimized I1, calculation optimized C1, and IO optimized I2 are more than 8C packages - We use the standard image improved by Jinshan cloud or the user-defined image made by - the instance of starting the Jinshan cloud standard image - default : false - -- `local_volume_snapshot_id` (string) - Local Volume Snapshot Id - -- `data_disk_gb` (int) - The data volume capacity is in GB. The capacity limit changes according to the definition of the instance package - type. If it is not specified when calling, it is the minimum value of the corresponding instance package type. - When the instancetype is a general-purpose host N1, N2, N3 or a local nvme I4, this parameter - does not take effect. - -- `user_data` (string) - The user-defined data provided for instance startup needs to be encoded in Base64 mode, - and the maximum data size supported is 16kb - - - - -## Image Configuration - -### Required: - - - -- `image_name` (string) - The name of the user-defined image, [2, 64] English or Chinese - characters. It must begin with an uppercase/lowercase letter or a - Chinese character, and may contain numbers, `_` or `-`. It cannot begin - with `http://` or `https://`. - - - - -### Optional: - - - -- `image_type` (string) - The type of image - LocalImage (ebs) or CommonImage (ks3) - -- `image_ignore_data_disks` (bool) - If this value is true, the image created will not include any snapshot - of data disks. The default value is false. - -- `image_copy_regions` ([]string) - Copy to the regions. - -- `image_copy_names` ([]string) - Ksyun Image Copy Names - -- `image_share_accounts` ([]string) - Share image to other accounts - -- `image_warm_up` (bool) - Set the image as warm-up for fast boot - - -.mdx' \ No newline at end of file +``` \ No newline at end of file diff --git a/.docs/datasources/kmi/kmi.mdx b/.docs/datasources/kmi/kmi.mdx index e610f96..a22a3a2 100644 --- a/.docs/datasources/kmi/kmi.mdx +++ b/.docs/datasources/kmi/kmi.mdx @@ -83,141 +83,54 @@ This selects the most recent Centos 7.5 Ksyun Images from remote Ksyun. Note tha -d unless `profile` is set, but it can - also be sourced from the `KSYUN_ACCESS_KEY` environment variable. - -- `secret_key` (string) - Ksyun secret key must be provided unless `profile` is set, but it can - also be sourced from the `KSYUN_SECRET_KEY` environment variable. - -- `region` (string) - Ksyun region must be provided unless `profile` is set, but it can - also be sourced from the `KSYUN_REGION` environment variable. - - - - -### Optional: - - -- `most_recent` (bool) - Selects the newest created image when true. - This is most useful for selecting a daily distro build. - -- `image_source` (string) - ImageSource Valid values are import, copy, share, extend, system. - -- `name_regex` (string) - NameRegex A regex string to filter resulting images by name. - (Such as: `^CentOS 7.[1-2] 64` means CentOS 7.1 of 64-bit operating system or CentOS 7.2 of 64-bit operating system, - \"^Ubuntu 16.04 64\" means Ubuntu 16.04 of 64-bit operating system). - -- `platform` (string) - Platform type of the image system. - - - - -## Output Data - - - -- `id` (string) - The ID of the image. - -- `name` (string) - The name of the image. +## Basic Example -- `creation_date` (string) - The date of creation of the image. - -- `platform` (string) - Platform - -- `image_source` (string) - Image Source - - - - -d unless `profile` is set, but it can - also be sourced from the `KSYUN_ACCESS_KEY` environment variable. - -- `secret_key` (string) - Ksyun secret key must be provided unless `profile` is set, but it can - also be sourced from the `KSYUN_SECRET_KEY` environment variable. - -- `region` (string) - Ksyun region must be provided unless `profile` is set, but it can - also be sourced from the `KSYUN_REGION` environment variable. - - - - -### Optional: - - -- `most_recent` (bool) - Selects the newest created image when true. - This is most useful for selecting a daily distro build. - -- `image_source` (string) - ImageSource Valid values are import, copy, share, extend, system. - -- `name_regex` (string) - NameRegex A regex string to filter resulting images by name. - (Such as: `^CentOS 7.[1-2] 64` means CentOS 7.1 of 64-bit operating system or CentOS 7.2 of 64-bit operating system, - \"^Ubuntu 16.04 64\" means Ubuntu 16.04 of 64-bit operating system). - -- `platform` (string) - Platform type of the image system. - - +Here is a basic example. It is completely valid but excludes the access keys: +### Example Usage -## Output Data - - - -- `id` (string) - The ID of the image. - -- `name` (string) - The name of the image. - -- `creation_date` (string) - The date of creation of the image. - -- `platform` (string) - Platform - -- `image_source` (string) - Image Source - - - - -d unless `profile` is set, but it can - also be sourced from the `KSYUN_ACCESS_KEY` environment variable. - -- `secret_key` (string) - Ksyun secret key must be provided unless `profile` is set, but it can - also be sourced from the `KSYUN_SECRET_KEY` environment variable. - -- `region` (string) - Ksyun region must be provided unless `profile` is set, but it can - also be sourced from the `KSYUN_REGION` environment variable. - - - - -### Optional: - - -- `most_recent` (bool) - Selects the newest created image when true. - This is most useful for selecting a daily distro build. - -- `image_source` (string) - ImageSource Valid values are import, copy, share, extend, system. - -- `name_regex` (string) - NameRegex A regex string to filter resulting images by name. - (Such as: `^CentOS 7.[1-2] 64` means CentOS 7.1 of 64-bit operating system or CentOS 7.2 of 64-bit operating system, - \"^Ubuntu 16.04 64\" means Ubuntu 16.04 of 64-bit operating system). - -- `platform` (string) - Platform type of the image system. - - - - -## Output Data - - - -- `id` (string) - The ID of the image. - -- `name` (string) - The name of the image. +```hcl +packer { + required_plugins { + ksyun = { + version = ">=0.1.0" + source = "github.com/kingsoftcloud/ksyun" + } + } +} -- `creation_date` (string) - The date of creation of the image. +variable ak { + type = string + default = "${env("KSYUN_ACCESS_KEY")}" +} -- `platform` (string) - Platform +variable sk { + type = string + default = "${env("KSYUN_SECRET_KEY")}" +} -- `image_source` (string) - Image Source +data "ksyun-kmi" "foo" { + access_key = var.ak + secret_key = var.sk + region = "cn-shanghai-2" + platform = "centos-7.5" + name_regex = "centos-7.5.*" + image_source = "system" // import, copy, share, extend, system. + most_recent = true +} - +source "ksyun-kec" "test" { + access_key = var.ak + secret_key = var.sk + region = "cn-shanghai-2" + image_name = "packer_test" + source_image_id = "IMG-05f198b3-9df6-4f94-a3e3-dcee4b48c4aa" + instance_type = "N3.1B" + ssh_username = "root" +} +build { + sources = ["source.ksyun-kec.test"] +} +``` \ No newline at end of file diff --git a/Makefile b/Makefile index 6a0eebb..2e458f8 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ install-packer-sdc: ## Install packer sofware development command go install github.com/hashicorp/packer-plugin-sdk/cmd/packer-sdc@${HASHICORP_PACKER_PLUGIN_SDK_VERSION} ci-release-docs: install-packer-sdc - @packer-sdc renderdocs -src docs -partials docs-partials/ -dst docs/ + @packer-sdc renderdocs -src .docs -partials docs-partials/ -dst docs/ @/bin/sh -c "[ -d docs ] && zip -r docs.zip docs/" lint: diff --git a/builder/epc/image_config.go b/builder/epc/image_config.go index 68f6002..2482189 100644 --- a/builder/epc/image_config.go +++ b/builder/epc/image_config.go @@ -1,12 +1,18 @@ +//go:generate packer-sdc struct-markdown package epc import ( "fmt" - "github.com/hashicorp/packer-plugin-sdk/template/interpolate" "regexp" + + "github.com/hashicorp/packer-plugin-sdk/template/interpolate" ) type KsyunImageConfig struct { + // The name of the user-defined image, [2, 64] English or Chinese + // characters. It must begin with an uppercase/lowercase letter or a + // Chinese character, and may contain numbers, `_` or `-`. It cannot begin + // with `http://` or `https://`. KsyunImageName string `mapstructure:"image_name" required:"false"` } diff --git a/builder/epc/run_config.go b/builder/epc/run_config.go index 1d90b8b..358aeae 100644 --- a/builder/epc/run_config.go +++ b/builder/epc/run_config.go @@ -3,37 +3,67 @@ package epc import ( "fmt" + "github.com/hashicorp/packer-plugin-sdk/template/interpolate" "github.com/hashicorp/packer-plugin-sdk/uuid" ksyun "github.com/kingsoftcloud/packer-plugin-ksyun/builder" ) type KsyunEpcRunConfig struct { - HostType string `mapstructure:"host_type" required:"true"` - Raid string `mapstructure:"raid" required:"false"` - SourceImageId string `mapstructure:"source_image_id" required:"true"` - NetworkInterfaceMode string `mapstructure:"network_interface_mode" required:"false"` - HostName string `mapstructure:"host_name" required:"false"` - ComputerName string `mapstructure:"computer_name" required:"false"` - HostChargeType string `mapstructure:"host_charge_type" required:"false"` - SecurityAgent string `mapstructure:"security_agent" required:"false"` - ContainerAgent string `mapstructure:"container_agent" required:"false"` - CloudMonitorAgent string `mapstructure:"cloud_monitor_agent" required:"false"` - SystemFileType string `mapstructure:"system_file_type" required:"false"` - DataFileType string `mapstructure:"data_file_type" required:"false"` - DataDiskCatalogue string `mapstructure:"data_disk_catalogue" required:"false"` - DataDiskCatalogueSuffix string `mapstructure:"data_disk_catalogue_suffix" required:"false"` - ExtensionSubnetId string `mapstructure:"extension_subnet_id" required:"false"` - ExtensionSubnetName string `mapstructure:"extension_subnet_name" required:"false"` - ExtensionSubnetCidrBlock string `mapstructure:"extension_subnet_cidr_block" required:"false"` - ExtensionPrivateIpAddress string `mapstructure:"extension_private_ip_address" required:"false"` - ExtensionDNS1 string `mapstructure:"extension_dns1" required:"false"` - ExtensionDNS2 string `mapstructure:"extension_dns2" required:"false"` + // Machine type of epc. + // Valid Options: see the [HostType of epc information](https://docs.ksyun.com/documents/651) + HostType string `mapstructure:"host_type" required:"true"` + // Data Disk Raid level. Valid options: `Raid1`, `Raid5`, `Raid10`, `Raid50` and `SRaid0`, + // the details see the [Raid of epc information](https://docs.ksyun.com/documents/651) + Raid string `mapstructure:"raid" required:"false"` + // Source image id whose root volume will be copied and provisioned on the currently running instance. + SourceImageId string `mapstructure:"source_image_id" required:"true"` + // Network interface mode. Valid options: `bond4`, `single` and `dual`. + NetworkInterfaceMode string `mapstructure:"network_interface_mode" required:"false"` + // The name of epc host. Default value: `ksc_epc`. + HostName string `mapstructure:"host_name" required:"false"` + // The system name of this epc computer. + ComputerName string `mapstructure:"computer_name" required:"false"` + HostChargeType string `mapstructure:"host_charge_type" required:"false"` + // Security component type. Valid options: `classic` and `no`. + SecurityAgent string `mapstructure:"security_agent" required:"false"` + // Container engine component type. Valid options: `supported` and `unsupported`, Default `unsupported`. + ContainerAgent string `mapstructure:"container_agent" required:"false"` + // The monitor agent. + CloudMonitorAgent string `mapstructure:"cloud_monitor_agent" required:"false"` + // The system disk file type. Valid options: `EXT4` and `XFS`. Default `EXT4`. + SystemFileType string `mapstructure:"system_file_type" required:"false"` + // The Data disk file type. Valid options: `EXT4` and `XFS`. Default `EXT4`. + DataFileType string `mapstructure:"data_file_type" required:"false"` + // The catalogue of data disk. Valid options: `/DATA/disk` and `/data`. Default `/data`. + DataDiskCatalogue string `mapstructure:"data_disk_catalogue" required:"false"` + // The suffix of data disk catalogue. + // `NoSuffix`: creating data disk catalogue without suffix, but it's valid, when there is one data disk. + // `NaturalNumber`: creating data disk catalogue with suffix that increment from 1. + // `NaturalNumberFromZero`: creating data disk catalogue with suffix that increment from 0. + // Valid options: `NoSuffix`, `NaturalNumber` and `NaturalNumberFromZero`. + // Default `NaturalNumber` + DataDiskCatalogueSuffix string `mapstructure:"data_disk_catalogue_suffix" required:"false"` + // The subnet id of secondary network interface + ExtensionSubnetId string `mapstructure:"extension_subnet_id" required:"false"` + // The subnet name of secondary network interface + ExtensionSubnetName string `mapstructure:"extension_subnet_name" required:"false"` + // The subnet cidr block of secondary network interface. + ExtensionSubnetCidrBlock string `mapstructure:"extension_subnet_cidr_block" required:"false"` + // The private ip address under the vpc of secondary network interface. + ExtensionPrivateIpAddress string `mapstructure:"extension_private_ip_address" required:"false"` + // The address of first dns server. + ExtensionDNS1 string `mapstructure:"extension_dns1" required:"false"` + // The address of second dns server. + ExtensionDNS2 string `mapstructure:"extension_dns2" required:"false"` + ExtensionSecurityGroupId string `mapstructure:"extension_security_group_id" required:"false"` ExtensionSecurityGroupName string `mapstructure:"extension_security_group_name" required:"false"` - TempSubnetId string - TempSecurityGroupId string - ksyun.CommonConfig `mapstructure:",squash"` + // The temporary subnet id. + TempSubnetId string + // The temporary security group id. + TempSecurityGroupId string + ksyun.CommonConfig `mapstructure:",squash"` } func (c *KsyunEpcRunConfig) Prepare(ctx *interpolate.Context) []error { diff --git a/builder/kec/image_config.go b/builder/kec/image_config.go index 9612a0b..199887d 100644 --- a/builder/kec/image_config.go +++ b/builder/kec/image_config.go @@ -41,7 +41,8 @@ type KsyunImageConfig struct { // Copy to the regions. KsyunImageCopyRegions []string `mapstructure:"image_copy_regions" required:"false"` - KsyunImageCopyNames []string `mapstructure:"image_copy_names" required:"false"` + // The image name in copied regions + KsyunImageCopyNames []string `mapstructure:"image_copy_names" required:"false"` // Share image to other accounts KsyunImageShareAccounts []string `mapstructure:"image_share_accounts" required:"false"` diff --git a/builder/kec/run_config.go b/builder/kec/run_config.go index b64245d..ddf6a1c 100644 --- a/builder/kec/run_config.go +++ b/builder/kec/run_config.go @@ -24,7 +24,7 @@ type KsyunEbsDataDisk struct { type KsyunKecRunConfig struct { // Instance package type, if the instance package type is not specified when calling, the default value is I1.1A. InstanceType string `mapstructure:"instance_type" required:"true"` - SourceImageId string `mapstructure:"source_image_id" required:"false"` + SourceImageId string `mapstructure:"source_image_id" required:"true"` // Filters used to populate the `source_image_id` field. // // Example Hcl usage: diff --git a/docs-partials/builder/epc/KsyunEpcRunConfig-not-required.mdx b/docs-partials/builder/epc/KsyunEpcRunConfig-not-required.mdx index e3606f3..c86778d 100644 --- a/docs-partials/builder/epc/KsyunEpcRunConfig-not-required.mdx +++ b/docs-partials/builder/epc/KsyunEpcRunConfig-not-required.mdx @@ -1,40 +1,46 @@ -- `raid` (string) - Raid +- `raid` (string) - Data Disk Raid level. Valid options: `Raid1`, `Raid5`, `Raid10`, `Raid50` and `SRaid0`, + the details see the [Raid of epc information](https://docs.ksyun.com/documents/651) -- `network_interface_mode` (string) - Network Interface Mode +- `network_interface_mode` (string) - Network interface mode. Valid options: `bond4`, `single` and `dual`. -- `host_name` (string) - Host Name +- `host_name` (string) - The name of epc host. Default value: `ksc_epc`. -- `computer_name` (string) - Computer Name +- `computer_name` (string) - The system name of this epc computer. - `host_charge_type` (string) - Host Charge Type -- `security_agent` (string) - Security Agent +- `security_agent` (string) - Security component type. Valid options: `classic` and `no`. -- `container_agent` (string) - Container Agent +- `container_agent` (string) - Container engine component type. Valid options: `supported` and `unsupported`, Default `unsupported`. -- `cloud_monitor_agent` (string) - Cloud Monitor Agent +- `cloud_monitor_agent` (string) - The monitor agent. -- `system_file_type` (string) - System File Type +- `system_file_type` (string) - The system disk file type. Valid options: `EXT4` and `XFS`. Default `EXT4`. -- `data_file_type` (string) - Data File Type +- `data_file_type` (string) - The Data disk file type. Valid options: `EXT4` and `XFS`. Default `EXT4`. -- `data_disk_catalogue` (string) - Data Disk Catalogue +- `data_disk_catalogue` (string) - The catalogue of data disk. Valid options: `/DATA/disk` and `/data`. Default `/data`. -- `data_disk_catalogue_suffix` (string) - Data Disk Catalogue Suffix +- `data_disk_catalogue_suffix` (string) - The suffix of data disk catalogue. + `NoSuffix`: creating data disk catalogue without suffix, but it's valid, when there is one data disk. + `NaturalNumber`: creating data disk catalogue with suffix that increment from 1. + `NaturalNumberFromZero`: creating data disk catalogue with suffix that increment from 0. + Valid options: `NoSuffix`, `NaturalNumber` and `NaturalNumberFromZero`. + Default `NaturalNumber` -- `extension_subnet_id` (string) - Extension Subnet Id +- `extension_subnet_id` (string) - The subnet id of secondary network interface -- `extension_subnet_name` (string) - Extension Subnet Name +- `extension_subnet_name` (string) - The subnet name of secondary network interface -- `extension_subnet_cidr_block` (string) - Extension Subnet Cidr Block +- `extension_subnet_cidr_block` (string) - The subnet cidr block of secondary network interface. -- `extension_private_ip_address` (string) - Extension Private Ip Address +- `extension_private_ip_address` (string) - The private ip address under the vpc of secondary network interface. -- `extension_dns1` (string) - Extension DNS 1 +- `extension_dns1` (string) - The address of first dns server. -- `extension_dns2` (string) - Extension DNS 2 +- `extension_dns2` (string) - The address of second dns server. - `extension_security_group_id` (string) - Extension Security Group Id diff --git a/docs-partials/builder/epc/KsyunEpcRunConfig-required.mdx b/docs-partials/builder/epc/KsyunEpcRunConfig-required.mdx index f250e5d..834bf3a 100644 --- a/docs-partials/builder/epc/KsyunEpcRunConfig-required.mdx +++ b/docs-partials/builder/epc/KsyunEpcRunConfig-required.mdx @@ -1,7 +1,8 @@ -- `host_type` (string) - Host Type +- `host_type` (string) - Machine type of epc. + Valid Options: see the [HostType of epc information](https://docs.ksyun.com/documents/651) -- `source_image_id` (string) - Source Image Id +- `source_image_id` (string) - Source image id whose root volume will be copied and provisioned on the currently running instance. diff --git a/docs-partials/builder/epc/KsyunImageConfig-not-required.mdx b/docs-partials/builder/epc/KsyunImageConfig-not-required.mdx new file mode 100644 index 0000000..7d0b192 --- /dev/null +++ b/docs-partials/builder/epc/KsyunImageConfig-not-required.mdx @@ -0,0 +1,8 @@ + + +- `image_name` (string) - The name of the user-defined image, [2, 64] English or Chinese + characters. It must begin with an uppercase/lowercase letter or a + Chinese character, and may contain numbers, `_` or `-`. It cannot begin + with `http://` or `https://`. + + diff --git a/docs-partials/builder/kec/KsyunImageConfig-not-required.mdx b/docs-partials/builder/kec/KsyunImageConfig-not-required.mdx index 72836a0..58ad00d 100644 --- a/docs-partials/builder/kec/KsyunImageConfig-not-required.mdx +++ b/docs-partials/builder/kec/KsyunImageConfig-not-required.mdx @@ -8,7 +8,7 @@ - `image_copy_regions` ([]string) - Copy to the regions. -- `image_copy_names` ([]string) - Ksyun Image Copy Names +- `image_copy_names` ([]string) - The image name in copied regions - `image_share_accounts` ([]string) - Share image to other accounts diff --git a/docs-partials/builder/kec/KsyunKecRunConfig-not-required.mdx b/docs-partials/builder/kec/KsyunKecRunConfig-not-required.mdx index 41624b5..f58124a 100644 --- a/docs-partials/builder/kec/KsyunKecRunConfig-not-required.mdx +++ b/docs-partials/builder/kec/KsyunKecRunConfig-not-required.mdx @@ -1,5 +1,17 @@ +- `source_image_filter` (ksyun.KmiFilterOptions) - Filters used to populate the `source_image_id` field. + + Example Hcl usage: + ```hcl + source_image_filter { + platform = "centos-7.5" + name_regex = "centos-7.5.*" + image_source = "system" // import, copy, share, extend, system. + most_recent = true + } + ``` + - `system_disk_type` (string) - Local_SSD || SSD3.0 || EHDD - `system_disk_size` (int) - System Disk Size diff --git a/docs/builders/kec/kec.mdx b/docs/builders/kec/kec.mdx deleted file mode 100644 index 9f6f34d..0000000 --- a/docs/builders/kec/kec.mdx +++ /dev/null @@ -1,137 +0,0 @@ ---- -description: > -The ksyun-kec Packer builder is able to create Ksyun Images backed by - -instance storage as the root device. - -page_title: Ksyun Instance(KEC) - Builders -nav_title: Instance(KEC) ---- - -# Ksyun Image Builder (kec) - -Type: `ksyun-kec` - -The `ksyun-kec` Packer builder is able to create Ksyun Images backed by -instance storage as the root device. - - -## Configuration Reference - -There are many configuration options available for the builder. In addition to -the items listed here, you will want to look at the general configuration -references for [Image](#image-configuration), -[DiskDevices](#disk-devices-configuration), -[Access](#access-configuration), -[Run](#run-configuration) and -[General](#general-configuration) -configuration references, which are -necessary for this build to succeed and can be found further down the page. - -## Run Configuration - -### Required: - -@include 'builder/kec/KsyunKecRunConfig-required.mdx' - -### Optional: - -@include 'builder/kec/KsyunKecRunConfig-not-required.mdx' - -## Access Configuration - -### Required: - -@include 'builder/AccessConfig-required.mdx' - -## General Configuration - -### Optional: - -@include 'builder/CommonConfig-not-required.mdx' - -## Image Configuration - -### Required: - -@include 'builder/kec/KsyunImageConfig-required.mdx' - -### Optional: - -@include 'builder/kec/KsyunImageConfig-not-required.mdx' - -### Source Image Filter Configuration - -@include 'builder/KmiFilterOptions-not-required.mdx' - -## Basic Example - -Here is a basic example. It is completely valid but excludes the access keys: - -### Example Usage - -```hcl -packer { - required_plugins { - ksyun = { - version = ">=0.1.0" - source = "github.com/kingsoftcloud/ksyun" - } - } -} - -variable ak { - type = string - default = "${env("KSYUN_ACCESS_KEY")}" -} - -variable sk { - type = string - default = "${env("KSYUN_SECRET_KEY")}" -} - -source "ksyun-kec" "test" { - access_key = var.ak - secret_key = var.sk - region = "cn-shanghai-2" - image_name = "packer_test" - source_image_id = "IMG-05f198b3-9df6-4f94-a3e3-dcee4b48c4aa" - instance_type = "N3.1B" - ssh_username = "root" - - # 此参数用于跳过ssh - # communicator = "none" - - # 如需使用ssh,须保证网络能通,如果不在同一个网络环境下就要挂公网ip - associate_public_ip_address = true - - ssh_clear_authorized_keys = true - - # 此参数为true时,data_disks的硬盘不会打快照加入镜像 - image_ignore_data_disks = true - - data_disks { - data_disk_type = "SSD3.0" - data_disk_size = 50 - } - - # 复制镜像到以下region - image_copy_regions = ["cn-beijing-6", "cn-guangzhou-1"] - - # 镜像复制后的名称, 不命名则使用原镜像的名称 - image_copy_names = ["copy-test"] - - # 开启镜像预热 - image_warm_up = true - - # 镜像共享给其他用户 - # image_share_accounts = ["xxxxxxxx", "xxxxxxxx"] -} - -build { - sources = ["source.ksyun-kec.test"] - provisioner "shell" { - inline = ["sleep 10", "df -h"] - } -} -``` \ No newline at end of file diff --git a/docs/datasources/kmi/kmi.mdx b/docs/datasources/kmi/kmi.mdx deleted file mode 100644 index 9913be6..0000000 --- a/docs/datasources/kmi/kmi.mdx +++ /dev/null @@ -1,97 +0,0 @@ ---- -description: | -The Ksyun KMI data source provides information from a KMI that will be fetched based -on the filter options provided in the configuration. - -page_title: Ksyun KMI - Data Source -nav_title: Ksyun KMI ---- - -# Ksyun KMI Data Source - -Type: `ksyun-kmi` - -The Ksyun KMI data source will filter and fetch a Ksyun Images, and output all the Ksyun Machine images information that will -be then available to use in the [Ksyun builders](./). - --> **Note:** Data sources is a feature exclusively available to HCL2 templates. - -Basic example of usage: - -```hcl -data "ksyun-kmi" "foo" { - access_key = "ksyun access key" - secret_key = "ksyun secret key" - region = "cn-shanghai-2" - platform = "centos-7.5" - name_regex = "centos-7.5.*" - image_source = "system" // import, copy, share, extend, system. - most_recent = true -} -``` -This selects the most recent Centos 7.5 Ksyun Images from remote Ksyun. Note that the data source will fail unless -*exactly* one AMI is returned. In the above example, `most_recent` will cause this to succeed by selecting the newest image. - -## Configuration Reference - -### Required: -@include 'builder/AccessConfig-required.mdx' - -### Optional: -@include 'builder/KmiFilterOptions-not-required.mdx' - -## Output Data - -@include 'datasource/kmi/DatasourceOutput.mdx' - -## Basic Example - -Here is a basic example. It is completely valid but excludes the access keys: - -### Example Usage - -```hcl -packer { - required_plugins { - ksyun = { - version = ">=0.1.0" - source = "github.com/kingsoftcloud/ksyun" - } - } -} - -variable ak { - type = string - default = "${env("KSYUN_ACCESS_KEY")}" -} - -variable sk { - type = string - default = "${env("KSYUN_SECRET_KEY")}" -} - -data "ksyun-kmi" "foo" { - access_key = var.ak - secret_key = var.sk - region = "cn-shanghai-2" - platform = "centos-7.5" - name_regex = "centos-7.5.*" - image_source = "system" // import, copy, share, extend, system. - most_recent = true -} - - -source "ksyun-kec" "test" { - access_key = var.ak - secret_key = var.sk - region = "cn-shanghai-2" - image_name = "packer_test" - source_image_id = "IMG-05f198b3-9df6-4f94-a3e3-dcee4b48c4aa" - instance_type = "N3.1B" - ssh_username = "root" -} - -build { - sources = ["source.ksyun-kec.test"] -} -``` \ No newline at end of file From 99b424fabfc2381416d13b8208de7b461638e824 Mon Sep 17 00:00:00 2001 From: "Sk.Lv" Date: Wed, 2 Aug 2023 16:05:20 +0800 Subject: [PATCH 06/11] docs: completed example usage --- .docs/builders/epc/epc.mdx | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/.docs/builders/epc/epc.mdx b/.docs/builders/epc/epc.mdx index eecc377..3a09e96 100644 --- a/.docs/builders/epc/epc.mdx +++ b/.docs/builders/epc/epc.mdx @@ -59,3 +59,33 @@ necessary for this build to succeed and can be found further down the page. Here is a basic example. It is completely valid but excludes the access keys: ### Example Usage + +```json +{ + "variables": { + "access_key": "{{ env `KSYUN_ACCESS_KEY` }}", + "secret_key": "{{ env `KSYUN_SECRET_KEY` }}" + }, + "builders": [{ + "type":"ksyun-epc", + "access_key":"{{user `access_key`}}", + "secret_key":"{{user `secret_key`}}", + "region":"cn-beijing-6", + "source_image_id":"eb8c0428-476e-49af-8ccb-9fad2455a54c", + "host_type":"EC-I-III-II", + "availability_zone":"cn-beijing-6c", + "raid": "Raid1", + "ssh_username":"root", + "ssh_clear_authorized_keys": true, + "associate_public_ip_address": true + }], + "provisioners": [{ + "type": "shell", + "inline": [ + "sleep 30", + "yum install mysql -y" + ] + }] +} + +``` \ No newline at end of file From 805063e5e8ef96dd6ce335b7cab12301baae6201 Mon Sep 17 00:00:00 2001 From: "Sk.Lv" Date: Wed, 2 Aug 2023 16:13:09 +0800 Subject: [PATCH 07/11] docs: completed docs file --- docs/builders/epc/epc.mdx | 218 ++++++++++++++++++++++++++ docs/builders/kec/kec.mdx | 292 +++++++++++++++++++++++++++++++++++ docs/datasources/kmi/kmi.mdx | 136 ++++++++++++++++ 3 files changed, 646 insertions(+) create mode 100644 docs/builders/epc/epc.mdx create mode 100644 docs/builders/kec/kec.mdx create mode 100644 docs/datasources/kmi/kmi.mdx diff --git a/docs/builders/epc/epc.mdx b/docs/builders/epc/epc.mdx new file mode 100644 index 0000000..a81ca44 --- /dev/null +++ b/docs/builders/epc/epc.mdx @@ -0,0 +1,218 @@ +--- +description: > +The ksyun-epc Packer builder is able to create Ksyun Images backed by + +instance storage as the root device. + +page_title: Ksyun EPC - Builders +nav_title: Epc +--- + +# Ksyun Image Builder (epc) + +Type: `ksyun-epc` + +The `ksyun-epc` Packer builder is able to create Ksyun Images backed by +bare metal instance storage as the root device. + + +## Configuration Reference + +There are many configuration options available for the builder. In addition to +the items listed here, you will want to look at the general configuration +references for [Image](#image-configuration), +[Access](#access-configuration), +[Run](#run-configuration) and +[General](#general-configuration) +configuration references, which are +necessary for this build to succeed and can be found further down the page. + +## Run Configuration +### Required: + + + +- `host_type` (string) - Machine type of epc. + Valid Options: see the [HostType of epc information](https://docs.ksyun.com/documents/651) + +- `source_image_id` (string) - Source image id whose root volume will be copied and provisioned on the currently running instance. + + + + +### Optional: + + + +- `raid` (string) - Data Disk Raid level. Valid options: `Raid1`, `Raid5`, `Raid10`, `Raid50` and `SRaid0`, + the details see the [Raid of epc information](https://docs.ksyun.com/documents/651) + +- `network_interface_mode` (string) - Network interface mode. Valid options: `bond4`, `single` and `dual`. + +- `host_name` (string) - The name of epc host. Default value: `ksc_epc`. + +- `computer_name` (string) - The system name of this epc computer. + +- `host_charge_type` (string) - Host Charge Type + +- `security_agent` (string) - Security component type. Valid options: `classic` and `no`. + +- `container_agent` (string) - Container engine component type. Valid options: `supported` and `unsupported`, Default `unsupported`. + +- `cloud_monitor_agent` (string) - The monitor agent. + +- `system_file_type` (string) - The system disk file type. Valid options: `EXT4` and `XFS`. Default `EXT4`. + +- `data_file_type` (string) - The Data disk file type. Valid options: `EXT4` and `XFS`. Default `EXT4`. + +- `data_disk_catalogue` (string) - The catalogue of data disk. Valid options: `/DATA/disk` and `/data`. Default `/data`. + +- `data_disk_catalogue_suffix` (string) - The suffix of data disk catalogue. + `NoSuffix`: creating data disk catalogue without suffix, but it's valid, when there is one data disk. + `NaturalNumber`: creating data disk catalogue with suffix that increment from 1. + `NaturalNumberFromZero`: creating data disk catalogue with suffix that increment from 0. + Valid options: `NoSuffix`, `NaturalNumber` and `NaturalNumberFromZero`. + Default `NaturalNumber` + +- `extension_subnet_id` (string) - The subnet id of secondary network interface + +- `extension_subnet_name` (string) - The subnet name of secondary network interface + +- `extension_subnet_cidr_block` (string) - The subnet cidr block of secondary network interface. + +- `extension_private_ip_address` (string) - The private ip address under the vpc of secondary network interface. + +- `extension_dns1` (string) - The address of first dns server. + +- `extension_dns2` (string) - The address of second dns server. + +- `extension_security_group_id` (string) - Extension Security Group Id + +- `extension_security_group_name` (string) - Extension Security Group Name + + + + +## Access Configuration + +### Required: + + + +- `access_key` (string) - Ksyun access key must be provided unless `profile` is set, but it can + also be sourced from the `KSYUN_ACCESS_KEY` environment variable. + +- `secret_key` (string) - Ksyun secret key must be provided unless `profile` is set, but it can + also be sourced from the `KSYUN_SECRET_KEY` environment variable. + +- `region` (string) - Ksyun region must be provided unless `profile` is set, but it can + also be sourced from the `KSYUN_REGION` environment variable. + + + + +## General Configuration + +### Optional: + + + +- `vpc_id` (string) - VPC ID allocated by the system. + +- `vpc_name` (string) - the default value is packer_vpc + +- `vpc_cidr_block` (string) - 172.16.0.0/16. When not specified, the default value is 172.16.0.0/16. + +- `subnet_id` (string) - The ID of the Subnet to be used. + +- `subnet_name` (string) - the default value is packer_subnet + +- `dns1` (string) - 172.16.0.0/24. When not specified, the default value is 172.16.0.0/24. + +- `dns2` (string) - DNS 2 + +- `subnet_cidr_block` (string) - Subnet Cidr Block + +- `availability_zone` (string) - availability_zone + +- `security_group_id` (string) - ID of the security group to which a newly + created instance belongs. Mutual access is allowed between instances in one + security group. If not specified, the newly created instance will be added + to the default security group. If the default group doesn’t exist, or the + number of instances in it has reached the maximum limit, a new security + group will be created automatically. + +- `security_group_name` (string) - The security group name. The default value + is blank. [2, 128] English or Chinese characters, must begin with an + uppercase/lowercase letter or Chinese character. Can contain numbers, ., + _ or -. It cannot begin with `http://` or `https://`. + the default value is packer_security_group + +- `private_ip_address` (string) - Private IP address, which specifies any valid value within the range of subnet IP address and represents + the primary IP address of the instance. Only one can be selected and bound to the primary network card. + If this parameter is not specified, the system will automatically select one from the valid address pool at random + Valid values: standard IP address format + +- `associate_public_ip_address` (bool) - Associate Public Ip Address + +- `public_ip_charge_type` (string) - PublicIp charge type, which can be + Daily TrafficMonthly DailyPaidByTransfer HourlyInstantSettlement + Default is Daily + +- `public_ip_band_width` (int) - [1-100] + Default is 1 + +- `project_id` (string) - Default is 0 + + + + +## Image Configuration + +### Optional: + + + +- `image_name` (string) - The name of the user-defined image, [2, 64] English or Chinese + characters. It must begin with an uppercase/lowercase letter or a + Chinese character, and may contain numbers, `_` or `-`. It cannot begin + with `http://` or `https://`. + + + + +## Basic Example + +Here is a basic example. It is completely valid but excludes the access keys: + +### Example Usage + +```json +{ + "variables": { + "access_key": "{{ env `KSYUN_ACCESS_KEY` }}", + "secret_key": "{{ env `KSYUN_SECRET_KEY` }}" + }, + "builders": [{ + "type":"ksyun-epc", + "access_key":"{{user `access_key`}}", + "secret_key":"{{user `secret_key`}}", + "region":"cn-beijing-6", + "source_image_id":"eb8c0428-476e-49af-8ccb-9fad2455a54c", + "host_type":"EC-I-III-II", + "availability_zone":"cn-beijing-6c", + "raid": "Raid1", + "ssh_username":"root", + "ssh_clear_authorized_keys": true, + "associate_public_ip_address": true + }], + "provisioners": [{ + "type": "shell", + "inline": [ + "sleep 30", + "yum install mysql -y" + ] + }] +} + +``` \ No newline at end of file diff --git a/docs/builders/kec/kec.mdx b/docs/builders/kec/kec.mdx new file mode 100644 index 0000000..695d729 --- /dev/null +++ b/docs/builders/kec/kec.mdx @@ -0,0 +1,292 @@ +--- +description: > +The ksyun-kec Packer builder is able to create Ksyun Images backed by + +instance storage as the root device. + +page_title: Ksyun Instance(KEC) - Builders +nav_title: Instance(KEC) +--- + +# Ksyun Image Builder (kec) + +Type: `ksyun-kec` + +The `ksyun-kec` Packer builder is able to create Ksyun Images backed by +instance storage as the root device. + + +## Configuration Reference + +There are many configuration options available for the builder. In addition to +the items listed here, you will want to look at the general configuration +references for [Image](#image-configuration), +[DiskDevices](#disk-devices-configuration), +[Access](#access-configuration), +[Run](#run-configuration) and +[General](#general-configuration) +configuration references, which are +necessary for this build to succeed and can be found further down the page. + +## Run Configuration + +### Required: + + + +- `instance_type` (string) - Instance package type, if the instance package type is not specified when calling, the default value is I1.1A. + +- `source_image_id` (string) - Source Image Id + +- `instance_charge_type` (string) - PostPaidByDay or PostPaidByHour + default is PostPaidByDay + + + + +### Optional: + + + +- `source_image_filter` (ksyun.KmiFilterOptions) - Filters used to populate the `source_image_id` field. + + Example Hcl usage: + ```hcl + source_image_filter { + platform = "centos-7.5" + name_regex = "centos-7.5.*" + image_source = "system" // import, copy, share, extend, system. + most_recent = true + } + ``` + +- `system_disk_type` (string) - Local_SSD || SSD3.0 || EHDD + +- `system_disk_size` (int) - System Disk Size + +- `data_disks` ([]KsyunEbsDataDisk) - EbsDataDisk + +- `instance_name` (string) - Display name of the instance, which is a string of 2 to 128 Chinese or + English characters. It must begin with an uppercase/lowercase letter or + a Chinese charac displayed on the Alibaba Cloud console. If this + // parameter is not specified, the default value is InstanceId of the + // instance. It cannot begin with `http://` or `https://`.ter and can contain numerals, `.`, `_`, or `-`. The + instance name is packer_kec_instance + +- `sriov_net_support` (bool) - This parameter needs to satisfy the following two conditions: + IO optimized I1, calculation optimized C1, and IO optimized I2 are more than 8C packages + We use the standard image improved by Jinshan cloud or the user-defined image made by + the instance of starting the Jinshan cloud standard image + default : false + +- `local_volume_snapshot_id` (string) - Local Volume Snapshot Id + +- `data_disk_gb` (int) - The data volume capacity is in GB. The capacity limit changes according to the definition of the instance package + type. If it is not specified when calling, it is the minimum value of the corresponding instance package type. + When the instancetype is a general-purpose host N1, N2, N3 or a local nvme I4, this parameter + does not take effect. + +- `user_data` (string) - The user-defined data provided for instance startup needs to be encoded in Base64 mode, + and the maximum data size supported is 16kb + + + + +## Access Configuration + +### Required: + + + +- `access_key` (string) - Ksyun access key must be provided unless `profile` is set, but it can + also be sourced from the `KSYUN_ACCESS_KEY` environment variable. + +- `secret_key` (string) - Ksyun secret key must be provided unless `profile` is set, but it can + also be sourced from the `KSYUN_SECRET_KEY` environment variable. + +- `region` (string) - Ksyun region must be provided unless `profile` is set, but it can + also be sourced from the `KSYUN_REGION` environment variable. + + + + +## General Configuration + +### Optional: + + + +- `vpc_id` (string) - VPC ID allocated by the system. + +- `vpc_name` (string) - the default value is packer_vpc + +- `vpc_cidr_block` (string) - 172.16.0.0/16. When not specified, the default value is 172.16.0.0/16. + +- `subnet_id` (string) - The ID of the Subnet to be used. + +- `subnet_name` (string) - the default value is packer_subnet + +- `dns1` (string) - 172.16.0.0/24. When not specified, the default value is 172.16.0.0/24. + +- `dns2` (string) - DNS 2 + +- `subnet_cidr_block` (string) - Subnet Cidr Block + +- `availability_zone` (string) - availability_zone + +- `security_group_id` (string) - ID of the security group to which a newly + created instance belongs. Mutual access is allowed between instances in one + security group. If not specified, the newly created instance will be added + to the default security group. If the default group doesn’t exist, or the + number of instances in it has reached the maximum limit, a new security + group will be created automatically. + +- `security_group_name` (string) - The security group name. The default value + is blank. [2, 128] English or Chinese characters, must begin with an + uppercase/lowercase letter or Chinese character. Can contain numbers, ., + _ or -. It cannot begin with `http://` or `https://`. + the default value is packer_security_group + +- `private_ip_address` (string) - Private IP address, which specifies any valid value within the range of subnet IP address and represents + the primary IP address of the instance. Only one can be selected and bound to the primary network card. + If this parameter is not specified, the system will automatically select one from the valid address pool at random + Valid values: standard IP address format + +- `associate_public_ip_address` (bool) - Associate Public Ip Address + +- `public_ip_charge_type` (string) - PublicIp charge type, which can be + Daily TrafficMonthly DailyPaidByTransfer HourlyInstantSettlement + Default is Daily + +- `public_ip_band_width` (int) - [1-100] + Default is 1 + +- `project_id` (string) - Default is 0 + + + + +## Image Configuration + +### Required: + + + +- `image_name` (string) - The name of the user-defined image, [2, 64] English or Chinese + characters. It must begin with an uppercase/lowercase letter or a + Chinese character, and may contain numbers, `_` or `-`. It cannot begin + with `http://` or `https://`. + + + + +### Optional: + + + +- `image_type` (string) - The type of image + LocalImage (ebs) or CommonImage (ks3) + +- `image_ignore_data_disks` (bool) - If this value is true, the image created will not include any snapshot + of data disks. The default value is false. + +- `image_copy_regions` ([]string) - Copy to the regions. + +- `image_copy_names` ([]string) - The image name in copied regions + +- `image_share_accounts` ([]string) - Share image to other accounts + +- `image_warm_up` (bool) - Set the image as warm-up for fast boot + + + + +### Source Image Filter Configuration + + + +- `most_recent` (bool) - Selects the newest created image when true. + This is most useful for selecting a daily distro build. + +- `image_source` (string) - ImageSource Valid values are import, copy, share, extend, system. + +- `name_regex` (string) - NameRegex A regex string to filter resulting images by name. + (Such as: `^CentOS 7.[1-2] 64` means CentOS 7.1 of 64-bit operating system or CentOS 7.2 of 64-bit operating system, + \"^Ubuntu 16.04 64\" means Ubuntu 16.04 of 64-bit operating system). + +- `platform` (string) - Platform type of the image system. + + + + +## Basic Example + +Here is a basic example. It is completely valid but excludes the access keys: + +### Example Usage + +```hcl +packer { + required_plugins { + ksyun = { + version = ">=0.1.0" + source = "github.com/kingsoftcloud/ksyun" + } + } +} + +variable ak { + type = string + default = "${env("KSYUN_ACCESS_KEY")}" +} + +variable sk { + type = string + default = "${env("KSYUN_SECRET_KEY")}" +} + +source "ksyun-kec" "test" { + access_key = var.ak + secret_key = var.sk + region = "cn-shanghai-2" + image_name = "packer_test" + source_image_id = "IMG-05f198b3-9df6-4f94-a3e3-dcee4b48c4aa" + instance_type = "N3.1B" + ssh_username = "root" + + # 此参数用于跳过ssh + # communicator = "none" + + # 如需使用ssh,须保证网络能通,如果不在同一个网络环境下就要挂公网ip + associate_public_ip_address = true + + ssh_clear_authorized_keys = true + + # 此参数为true时,data_disks的硬盘不会打快照加入镜像 + image_ignore_data_disks = true + + data_disks { + data_disk_type = "SSD3.0" + data_disk_size = 50 + } + + # 复制镜像到以下region + image_copy_regions = ["cn-beijing-6", "cn-guangzhou-1"] + + # 镜像复制后的名称, 不命名则使用原镜像的名称 + image_copy_names = ["copy-test"] + + # 开启镜像预热 + image_warm_up = true + + # 镜像共享给其他用户 + # image_share_accounts = ["xxxxxxxx", "xxxxxxxx"] +} + +build { + sources = ["source.ksyun-kec.test"] + provisioner "shell" { + inline = ["sleep 10", "df -h"] + } +} +``` \ No newline at end of file diff --git a/docs/datasources/kmi/kmi.mdx b/docs/datasources/kmi/kmi.mdx new file mode 100644 index 0000000..a22a3a2 --- /dev/null +++ b/docs/datasources/kmi/kmi.mdx @@ -0,0 +1,136 @@ +--- +description: | +The Ksyun KMI data source provides information from a KMI that will be fetched based +on the filter options provided in the configuration. + +page_title: Ksyun KMI - Data Source +nav_title: Ksyun KMI +--- + +# Ksyun KMI Data Source + +Type: `ksyun-kmi` + +The Ksyun KMI data source will filter and fetch a Ksyun Images, and output all the Ksyun Machine images information that will +be then available to use in the [Ksyun builders](./). + +-> **Note:** Data sources is a feature exclusively available to HCL2 templates. + +Basic example of usage: + +```hcl +data "ksyun-kmi" "foo" { + access_key = "ksyun access key" + secret_key = "ksyun secret key" + region = "cn-shanghai-2" + platform = "centos-7.5" + name_regex = "centos-7.5.*" + image_source = "system" // import, copy, share, extend, system. + most_recent = true +} +``` +This selects the most recent Centos 7.5 Ksyun Images from remote Ksyun. Note that the data source will fail unless +*exactly* one AMI is returned. In the above example, `most_recent` will cause this to succeed by selecting the newest image. + +## Configuration Reference + +### Required: + + +- `access_key` (string) - Ksyun access key must be provided unless `profile` is set, but it can + also be sourced from the `KSYUN_ACCESS_KEY` environment variable. + +- `secret_key` (string) - Ksyun secret key must be provided unless `profile` is set, but it can + also be sourced from the `KSYUN_SECRET_KEY` environment variable. + +- `region` (string) - Ksyun region must be provided unless `profile` is set, but it can + also be sourced from the `KSYUN_REGION` environment variable. + + + + +### Optional: + + +- `most_recent` (bool) - Selects the newest created image when true. + This is most useful for selecting a daily distro build. + +- `image_source` (string) - ImageSource Valid values are import, copy, share, extend, system. + +- `name_regex` (string) - NameRegex A regex string to filter resulting images by name. + (Such as: `^CentOS 7.[1-2] 64` means CentOS 7.1 of 64-bit operating system or CentOS 7.2 of 64-bit operating system, + \"^Ubuntu 16.04 64\" means Ubuntu 16.04 of 64-bit operating system). + +- `platform` (string) - Platform type of the image system. + + + + +## Output Data + + + +- `id` (string) - The ID of the image. + +- `name` (string) - The name of the image. + +- `creation_date` (string) - The date of creation of the image. + +- `platform` (string) - Platform + +- `image_source` (string) - Image Source + + + + +## Basic Example + +Here is a basic example. It is completely valid but excludes the access keys: + +### Example Usage + +```hcl +packer { + required_plugins { + ksyun = { + version = ">=0.1.0" + source = "github.com/kingsoftcloud/ksyun" + } + } +} + +variable ak { + type = string + default = "${env("KSYUN_ACCESS_KEY")}" +} + +variable sk { + type = string + default = "${env("KSYUN_SECRET_KEY")}" +} + +data "ksyun-kmi" "foo" { + access_key = var.ak + secret_key = var.sk + region = "cn-shanghai-2" + platform = "centos-7.5" + name_regex = "centos-7.5.*" + image_source = "system" // import, copy, share, extend, system. + most_recent = true +} + + +source "ksyun-kec" "test" { + access_key = var.ak + secret_key = var.sk + region = "cn-shanghai-2" + image_name = "packer_test" + source_image_id = "IMG-05f198b3-9df6-4f94-a3e3-dcee4b48c4aa" + instance_type = "N3.1B" + ssh_username = "root" +} + +build { + sources = ["source.ksyun-kec.test"] +} +``` \ No newline at end of file From 068ce1a5cdc1b42bf3f029962594433d9619effa Mon Sep 17 00:00:00 2001 From: "Sk.Lv" Date: Thu, 3 Aug 2023 15:04:07 +0800 Subject: [PATCH 08/11] docs: packer plugin local testing --- .docs/builders/{epc => }/epc.mdx | 5 ++--- .docs/builders/{kec => }/kec.mdx | 5 ++--- {docs/datasources/kmi => .docs/datasources}/kmi.mdx | 6 +++--- Makefile | 1 + docs/builders/{epc => }/epc.mdx | 5 ++--- docs/builders/{kec => }/kec.mdx | 5 ++--- {.docs/datasources/kmi => docs/datasources}/kmi.mdx | 6 +++--- 7 files changed, 15 insertions(+), 18 deletions(-) rename .docs/builders/{epc => }/epc.mdx (93%) rename .docs/builders/{kec => }/kec.mdx (96%) rename {docs/datasources/kmi => .docs/datasources}/kmi.mdx (96%) rename docs/builders/{epc => }/epc.mdx (98%) rename docs/builders/{kec => }/kec.mdx (98%) rename {.docs/datasources/kmi => docs/datasources}/kmi.mdx (96%) diff --git a/.docs/builders/epc/epc.mdx b/.docs/builders/epc.mdx similarity index 93% rename from .docs/builders/epc/epc.mdx rename to .docs/builders/epc.mdx index 3a09e96..c315689 100644 --- a/.docs/builders/epc/epc.mdx +++ b/.docs/builders/epc.mdx @@ -1,8 +1,7 @@ --- description: > -The ksyun-epc Packer builder is able to create Ksyun Images backed by - -instance storage as the root device. + The ksyun-epc Packer builder is able to create Ksyun Images backed by + bare metal instance storage as the root device. page_title: Ksyun EPC - Builders nav_title: Epc diff --git a/.docs/builders/kec/kec.mdx b/.docs/builders/kec.mdx similarity index 96% rename from .docs/builders/kec/kec.mdx rename to .docs/builders/kec.mdx index 9f6f34d..1e52c79 100644 --- a/.docs/builders/kec/kec.mdx +++ b/.docs/builders/kec.mdx @@ -1,8 +1,7 @@ --- description: > -The ksyun-kec Packer builder is able to create Ksyun Images backed by - -instance storage as the root device. + The ksyun-kec Packer builder is able to create Ksyun Images backed by + instance storage as the root device. page_title: Ksyun Instance(KEC) - Builders nav_title: Instance(KEC) diff --git a/docs/datasources/kmi/kmi.mdx b/.docs/datasources/kmi.mdx similarity index 96% rename from docs/datasources/kmi/kmi.mdx rename to .docs/datasources/kmi.mdx index a22a3a2..16fe1db 100644 --- a/docs/datasources/kmi/kmi.mdx +++ b/.docs/datasources/kmi.mdx @@ -1,7 +1,7 @@ --- -description: | -The Ksyun KMI data source provides information from a KMI that will be fetched based -on the filter options provided in the configuration. +description: > + The Ksyun KMI data source provides information from a KMI that will be fetched based + on the filter options provided in the configuration. page_title: Ksyun KMI - Data Source nav_title: Ksyun KMI diff --git a/Makefile b/Makefile index 2e458f8..8321f68 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,7 @@ install-packer-sdc: ## Install packer sofware development command go install github.com/hashicorp/packer-plugin-sdk/cmd/packer-sdc@${HASHICORP_PACKER_PLUGIN_SDK_VERSION} ci-release-docs: install-packer-sdc + @/bin/sh -c "if [ -d docs ]; then echo \"removed existed docs directory\" && rm -rf docs; fi" @packer-sdc renderdocs -src .docs -partials docs-partials/ -dst docs/ @/bin/sh -c "[ -d docs ] && zip -r docs.zip docs/" diff --git a/docs/builders/epc/epc.mdx b/docs/builders/epc.mdx similarity index 98% rename from docs/builders/epc/epc.mdx rename to docs/builders/epc.mdx index a81ca44..d44571e 100644 --- a/docs/builders/epc/epc.mdx +++ b/docs/builders/epc.mdx @@ -1,8 +1,7 @@ --- description: > -The ksyun-epc Packer builder is able to create Ksyun Images backed by - -instance storage as the root device. + The ksyun-epc Packer builder is able to create Ksyun Images backed by + bare metal instance storage as the root device. page_title: Ksyun EPC - Builders nav_title: Epc diff --git a/docs/builders/kec/kec.mdx b/docs/builders/kec.mdx similarity index 98% rename from docs/builders/kec/kec.mdx rename to docs/builders/kec.mdx index 695d729..1af6a12 100644 --- a/docs/builders/kec/kec.mdx +++ b/docs/builders/kec.mdx @@ -1,8 +1,7 @@ --- description: > -The ksyun-kec Packer builder is able to create Ksyun Images backed by - -instance storage as the root device. + The ksyun-kec Packer builder is able to create Ksyun Images backed by + instance storage as the root device. page_title: Ksyun Instance(KEC) - Builders nav_title: Instance(KEC) diff --git a/.docs/datasources/kmi/kmi.mdx b/docs/datasources/kmi.mdx similarity index 96% rename from .docs/datasources/kmi/kmi.mdx rename to docs/datasources/kmi.mdx index a22a3a2..16fe1db 100644 --- a/.docs/datasources/kmi/kmi.mdx +++ b/docs/datasources/kmi.mdx @@ -1,7 +1,7 @@ --- -description: | -The Ksyun KMI data source provides information from a KMI that will be fetched based -on the filter options provided in the configuration. +description: > + The Ksyun KMI data source provides information from a KMI that will be fetched based + on the filter options provided in the configuration. page_title: Ksyun KMI - Data Source nav_title: Ksyun KMI From 4c0d87db1583481b92bd49a197240980531e2732 Mon Sep 17 00:00:00 2001 From: "Sk.Lv" Date: Thu, 3 Aug 2023 15:16:59 +0800 Subject: [PATCH 09/11] docs: update example usage --- .docs/datasources/kmi.mdx | 2 +- docs/datasources/kmi.mdx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.docs/datasources/kmi.mdx b/.docs/datasources/kmi.mdx index 16fe1db..27dbc1e 100644 --- a/.docs/datasources/kmi.mdx +++ b/.docs/datasources/kmi.mdx @@ -125,7 +125,7 @@ source "ksyun-kec" "test" { secret_key = var.sk region = "cn-shanghai-2" image_name = "packer_test" - source_image_id = "IMG-05f198b3-9df6-4f94-a3e3-dcee4b48c4aa" + source_image_id = data.ksyun-kmi.foo.id instance_type = "N3.1B" ssh_username = "root" } diff --git a/docs/datasources/kmi.mdx b/docs/datasources/kmi.mdx index 16fe1db..27dbc1e 100644 --- a/docs/datasources/kmi.mdx +++ b/docs/datasources/kmi.mdx @@ -125,7 +125,7 @@ source "ksyun-kec" "test" { secret_key = var.sk region = "cn-shanghai-2" image_name = "packer_test" - source_image_id = "IMG-05f198b3-9df6-4f94-a3e3-dcee4b48c4aa" + source_image_id = data.ksyun-kmi.foo.id instance_type = "N3.1B" ssh_username = "root" } From 115f6b9f95a21189c5b9146dcfd22b50d806dd9c Mon Sep 17 00:00:00 2001 From: "Sk.Lv" Date: Mon, 7 Aug 2023 11:20:04 +0800 Subject: [PATCH 10/11] chore: regiter to packer official site --- .docs/builders/kec.mdx | 1 - .docs/datasources/kmi.mdx | 43 ++----------------- builder/common_config.go | 6 ++- builder/kec/builder.hcl2spec.go | 2 +- builder/kec/run_config.go | 17 ++++++-- .../builder/CommonConfig-not-required.mdx | 3 +- .../kec/KsyunKecRunConfig-not-required.mdx | 15 +++++-- docs/builders/epc.mdx | 3 +- docs/builders/kec.mdx | 19 +++++--- docs/datasources/kmi.mdx | 2 + 10 files changed, 54 insertions(+), 57 deletions(-) diff --git a/.docs/builders/kec.mdx b/.docs/builders/kec.mdx index 1e52c79..eaff4d7 100644 --- a/.docs/builders/kec.mdx +++ b/.docs/builders/kec.mdx @@ -20,7 +20,6 @@ instance storage as the root device. There are many configuration options available for the builder. In addition to the items listed here, you will want to look at the general configuration references for [Image](#image-configuration), -[DiskDevices](#disk-devices-configuration), [Access](#access-configuration), [Run](#run-configuration) and [General](#general-configuration) diff --git a/.docs/datasources/kmi.mdx b/.docs/datasources/kmi.mdx index 27dbc1e..4a42401 100644 --- a/.docs/datasources/kmi.mdx +++ b/.docs/datasources/kmi.mdx @@ -35,53 +35,16 @@ This selects the most recent Centos 7.5 Ksyun Images from remote Ksyun. Note tha ## Configuration Reference ### Required: - - -- `access_key` (string) - Ksyun access key must be provided unless `profile` is set, but it can - also be sourced from the `KSYUN_ACCESS_KEY` environment variable. - -- `secret_key` (string) - Ksyun secret key must be provided unless `profile` is set, but it can - also be sourced from the `KSYUN_SECRET_KEY` environment variable. - -- `region` (string) - Ksyun region must be provided unless `profile` is set, but it can - also be sourced from the `KSYUN_REGION` environment variable. - - +@include 'builder/AccessConfig-required.mdx' ### Optional: - - -- `most_recent` (bool) - Selects the newest created image when true. - This is most useful for selecting a daily distro build. - -- `image_source` (string) - ImageSource Valid values are import, copy, share, extend, system. - -- `name_regex` (string) - NameRegex A regex string to filter resulting images by name. - (Such as: `^CentOS 7.[1-2] 64` means CentOS 7.1 of 64-bit operating system or CentOS 7.2 of 64-bit operating system, - \"^Ubuntu 16.04 64\" means Ubuntu 16.04 of 64-bit operating system). - -- `platform` (string) - Platform type of the image system. - - +@include 'builder/KmiFilterOptions-not-required.mdx' ## Output Data - - -- `id` (string) - The ID of the image. - -- `name` (string) - The name of the image. - -- `creation_date` (string) - The date of creation of the image. - -- `platform` (string) - Platform - -- `image_source` (string) - Image Source - - - +@include 'datasource/kmi/DatasourceOutput.mdx' ## Basic Example diff --git a/builder/common_config.go b/builder/common_config.go index b519a88..fa27f2b 100644 --- a/builder/common_config.go +++ b/builder/common_config.go @@ -39,8 +39,10 @@ type CommonConfig struct { // the primary IP address of the instance. Only one can be selected and bound to the primary network card. // If this parameter is not specified, the system will automatically select one from the valid address pool at random // Valid values: standard IP address format - PrivateIpAddress string `mapstructure:"private_ip_address" required:"false"` - AssociatePublicIpAddress bool `mapstructure:"associate_public_ip_address" required:"false"` + PrivateIpAddress string `mapstructure:"private_ip_address" required:"false"` + // Indicating associate whether public ip for creating kec instance + // Default `false` + AssociatePublicIpAddress bool `mapstructure:"associate_public_ip_address" required:"false"` // PublicIp charge type, which can be // Daily TrafficMonthly DailyPaidByTransfer HourlyInstantSettlement // Default is Daily diff --git a/builder/kec/builder.hcl2spec.go b/builder/kec/builder.hcl2spec.go index e451b5a..90e577e 100644 --- a/builder/kec/builder.hcl2spec.go +++ b/builder/kec/builder.hcl2spec.go @@ -32,7 +32,7 @@ type FlatConfig struct { KsyunImageShareAccounts []string `mapstructure:"image_share_accounts" required:"false" cty:"image_share_accounts" hcl:"image_share_accounts"` KsyunImageWarmUp *bool `mapstructure:"image_warm_up" required:"false" cty:"image_warm_up" hcl:"image_warm_up"` InstanceType *string `mapstructure:"instance_type" required:"true" cty:"instance_type" hcl:"instance_type"` - SourceImageId *string `mapstructure:"source_image_id" required:"false" cty:"source_image_id" hcl:"source_image_id"` + SourceImageId *string `mapstructure:"source_image_id" required:"true" cty:"source_image_id" hcl:"source_image_id"` SourceImageFilter *ksyun.FlatKmiFilterOptions `mapstructure:"source_image_filter" required:"false" cty:"source_image_filter" hcl:"source_image_filter"` SystemDiskType *string `mapstructure:"system_disk_type" required:"false" cty:"system_disk_type" hcl:"system_disk_type"` SystemDiskSize *int `mapstructure:"system_disk_size" required:"false" cty:"system_disk_size" hcl:"system_disk_size"` diff --git a/builder/kec/run_config.go b/builder/kec/run_config.go index ddf6a1c..b746994 100644 --- a/builder/kec/run_config.go +++ b/builder/kec/run_config.go @@ -32,17 +32,27 @@ type KsyunKecRunConfig struct { // source_image_filter { // platform = "centos-7.5" // name_regex = "centos-7.5.*" - // image_source = "system" // import, copy, share, extend, system. + // image_source = "system" # import, copy, share, extend, system. // most_recent = true // } // ``` + // `most_recent` will cause this to succeed by selecting the newest image. // SourceImageFilter ksyun.KmiFilterOptions `mapstructure:"source_image_filter" required:"false"` // Local_SSD || SSD3.0 || EHDD SystemDiskType string `mapstructure:"system_disk_type" required:"false"` SystemDiskSize int `mapstructure:"system_disk_size" required:"false"` - // EbsDataDisk + // `data_disks` is able to create Ksyun Kec instance with data disks. + // Example Hcl usage: + // ```hcl + // data_disks { + // data_disk_type = "SSD3.0" + // data_disk_size = 50 + // data_disk_snapshot_id = "data disk snapshot id" # creat disk with a data disk snapshot existed. + // } + // ``` + // KsyunEbsDataDisks []KsyunEbsDataDisk `mapstructure:"data_disks" required:"false"` // PostPaidByDay or PostPaidByHour // default is PostPaidByDay @@ -59,7 +69,8 @@ type KsyunKecRunConfig struct { // We use the standard image improved by Jinshan cloud or the user-defined image made by // the instance of starting the Jinshan cloud standard image // default : false - SriovNetSupport bool `mapstructure:"sriov_net_support" required:"false"` + SriovNetSupport bool `mapstructure:"sriov_net_support" required:"false"` + // Indicating whether needs local volume snapshot with creating kec instance LocalVolumeSnapshotId string `mapstructure:"local_volume_snapshot_id" required:"false"` // The data volume capacity is in GB. The capacity limit changes according to the definition of the instance package // type. If it is not specified when calling, it is the minimum value of the corresponding instance package type. diff --git a/docs-partials/builder/CommonConfig-not-required.mdx b/docs-partials/builder/CommonConfig-not-required.mdx index 4889816..6aedb6f 100644 --- a/docs-partials/builder/CommonConfig-not-required.mdx +++ b/docs-partials/builder/CommonConfig-not-required.mdx @@ -36,7 +36,8 @@ If this parameter is not specified, the system will automatically select one from the valid address pool at random Valid values: standard IP address format -- `associate_public_ip_address` (bool) - Associate Public Ip Address +- `associate_public_ip_address` (bool) - Indicating associate whether public ip for creating kec instance + Default `false` - `public_ip_charge_type` (string) - PublicIp charge type, which can be Daily TrafficMonthly DailyPaidByTransfer HourlyInstantSettlement diff --git a/docs-partials/builder/kec/KsyunKecRunConfig-not-required.mdx b/docs-partials/builder/kec/KsyunKecRunConfig-not-required.mdx index f58124a..bb1045b 100644 --- a/docs-partials/builder/kec/KsyunKecRunConfig-not-required.mdx +++ b/docs-partials/builder/kec/KsyunKecRunConfig-not-required.mdx @@ -7,16 +7,25 @@ source_image_filter { platform = "centos-7.5" name_regex = "centos-7.5.*" - image_source = "system" // import, copy, share, extend, system. + image_source = "system" # import, copy, share, extend, system. most_recent = true } ``` + `most_recent` will cause this to succeed by selecting the newest image. - `system_disk_type` (string) - Local_SSD || SSD3.0 || EHDD - `system_disk_size` (int) - System Disk Size -- `data_disks` ([]KsyunEbsDataDisk) - EbsDataDisk +- `data_disks` ([]KsyunEbsDataDisk) - `data_disks` is able to create Ksyun Kec instance with data disks. + Example Hcl usage: + ```hcl + data_disks { + data_disk_type = "SSD3.0" + data_disk_size = 50 + data_disk_snapshot_id = "data disk snapshot id" # creat disk with a data disk snapshot existed. + } + ``` - `instance_name` (string) - Display name of the instance, which is a string of 2 to 128 Chinese or English characters. It must begin with an uppercase/lowercase letter or @@ -31,7 +40,7 @@ the instance of starting the Jinshan cloud standard image default : false -- `local_volume_snapshot_id` (string) - Local Volume Snapshot Id +- `local_volume_snapshot_id` (string) - Indicating whether needs local volume snapshot with creating kec instance - `data_disk_gb` (int) - The data volume capacity is in GB. The capacity limit changes according to the definition of the instance package type. If it is not specified when calling, it is the minimum value of the corresponding instance package type. diff --git a/docs/builders/epc.mdx b/docs/builders/epc.mdx index d44571e..0c712d1 100644 --- a/docs/builders/epc.mdx +++ b/docs/builders/epc.mdx @@ -152,7 +152,8 @@ necessary for this build to succeed and can be found further down the page. If this parameter is not specified, the system will automatically select one from the valid address pool at random Valid values: standard IP address format -- `associate_public_ip_address` (bool) - Associate Public Ip Address +- `associate_public_ip_address` (bool) - Indicating associate whether public ip for creating kec instance + Default `false` - `public_ip_charge_type` (string) - PublicIp charge type, which can be Daily TrafficMonthly DailyPaidByTransfer HourlyInstantSettlement diff --git a/docs/builders/kec.mdx b/docs/builders/kec.mdx index 1af6a12..222aefb 100644 --- a/docs/builders/kec.mdx +++ b/docs/builders/kec.mdx @@ -20,7 +20,6 @@ instance storage as the root device. There are many configuration options available for the builder. In addition to the items listed here, you will want to look at the general configuration references for [Image](#image-configuration), -[DiskDevices](#disk-devices-configuration), [Access](#access-configuration), [Run](#run-configuration) and [General](#general-configuration) @@ -54,16 +53,25 @@ necessary for this build to succeed and can be found further down the page. source_image_filter { platform = "centos-7.5" name_regex = "centos-7.5.*" - image_source = "system" // import, copy, share, extend, system. + image_source = "system" # import, copy, share, extend, system. most_recent = true } ``` + `most_recent` will cause this to succeed by selecting the newest image. - `system_disk_type` (string) - Local_SSD || SSD3.0 || EHDD - `system_disk_size` (int) - System Disk Size -- `data_disks` ([]KsyunEbsDataDisk) - EbsDataDisk +- `data_disks` ([]KsyunEbsDataDisk) - `data_disks` is able to create Ksyun Kec instance with data disks. + Example Hcl usage: + ```hcl + data_disks { + data_disk_type = "SSD3.0" + data_disk_size = 50 + data_disk_snapshot_id = "data disk snapshot id" # creat disk with a data disk snapshot existed. + } + ``` - `instance_name` (string) - Display name of the instance, which is a string of 2 to 128 Chinese or English characters. It must begin with an uppercase/lowercase letter or @@ -78,7 +86,7 @@ necessary for this build to succeed and can be found further down the page. the instance of starting the Jinshan cloud standard image default : false -- `local_volume_snapshot_id` (string) - Local Volume Snapshot Id +- `local_volume_snapshot_id` (string) - Indicating whether needs local volume snapshot with creating kec instance - `data_disk_gb` (int) - The data volume capacity is in GB. The capacity limit changes according to the definition of the instance package type. If it is not specified when calling, it is the minimum value of the corresponding instance package type. @@ -151,7 +159,8 @@ necessary for this build to succeed and can be found further down the page. If this parameter is not specified, the system will automatically select one from the valid address pool at random Valid values: standard IP address format -- `associate_public_ip_address` (bool) - Associate Public Ip Address +- `associate_public_ip_address` (bool) - Indicating associate whether public ip for creating kec instance + Default `false` - `public_ip_charge_type` (string) - PublicIp charge type, which can be Daily TrafficMonthly DailyPaidByTransfer HourlyInstantSettlement diff --git a/docs/datasources/kmi.mdx b/docs/datasources/kmi.mdx index 27dbc1e..703061e 100644 --- a/docs/datasources/kmi.mdx +++ b/docs/datasources/kmi.mdx @@ -35,6 +35,7 @@ This selects the most recent Centos 7.5 Ksyun Images from remote Ksyun. Note tha ## Configuration Reference ### Required: + - `access_key` (string) - Ksyun access key must be provided unless `profile` is set, but it can @@ -50,6 +51,7 @@ This selects the most recent Centos 7.5 Ksyun Images from remote Ksyun. Note tha ### Optional: + - `most_recent` (bool) - Selects the newest created image when true. From 72d3c26d2455222ed0a4f1612402d07e3eb76859 Mon Sep 17 00:00:00 2001 From: "Sk.Lv" Date: Mon, 7 Aug 2023 14:28:52 +0800 Subject: [PATCH 11/11] chore: completed tags documents --- CHANGELOG.md | 7 + builder/client.go | 10 +- builder/client_config.go | 6 + builder/common_config.go | 15 +- builder/epc/builder.hcl2spec.go | 207 +++++++++--------- builder/kec/builder.go | 4 + builder/kec/builder.hcl2spec.go | 9 + builder/kec/image_config.go | 17 ++ builder/kec/run_config.go | 7 + builder/kec/step_create_kec.go | 12 + builder/step_config_eip.go | 21 +- builder/step_create_tags.go | 47 ++++ builder/tags.go | 80 +++++++ builder/utils.go | 23 +- .../builder/CommonConfig-not-required.mdx | 8 + .../kec/KsyunImageConfig-not-required.mdx | 7 + docs/builders/epc.mdx | 8 + docs/builders/kec.mdx | 15 ++ example/kec.pkr.hcl | 21 +- go.mod | 3 +- 20 files changed, 405 insertions(+), 122 deletions(-) create mode 100644 builder/step_create_tags.go create mode 100644 builder/tags.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 9dff954..e1d8e4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,13 @@ Please refer to [releases](https://github.com/kingsoftcloud/packer-plugin-ksyun/releases) for the latest CHANGELOG information. --- +## 0.3.0 (Aug 3, 2023) + +### FEATURES + +* Support `run_tags`, `run_tag` tags to apply to the instance that is launched to create the image. +* Support`tags`, `tag` tags applied to the destination image. + ## 0.2.0 (Jul 5, 2023) ### FEATURES diff --git a/builder/client.go b/builder/client.go index d5a9273..b2aff23 100644 --- a/builder/client.go +++ b/builder/client.go @@ -2,11 +2,13 @@ package ksyun import ( "fmt" + "time" + "github.com/KscSDK/ksc-sdk-go/service/eip" "github.com/KscSDK/ksc-sdk-go/service/sks" + "github.com/KscSDK/ksc-sdk-go/service/tagv2" "github.com/KscSDK/ksc-sdk-go/service/vpc" "github.com/hashicorp/packer-plugin-sdk/multistep" - "time" ) const ( @@ -29,6 +31,8 @@ type ClientWrapper struct { SksClient *sks.Sks EipClient *eip.Eip VpcClient *vpc.Vpc + + TagsClient *tagv2.Tagv2 } type ProcessRequestResult struct { @@ -47,10 +51,10 @@ var ( StopRetry: false, } - //RequestResourceStop = ProcessRequestResult{ + // RequestResourceStop = ProcessRequestResult{ // Complete: false, // StopRetry: true, - //} + // } ) type WaitResourceParam struct { diff --git a/builder/client_config.go b/builder/client_config.go index c308d54..8ed5eb9 100644 --- a/builder/client_config.go +++ b/builder/client_config.go @@ -5,6 +5,7 @@ import ( "github.com/KscSDK/ksc-sdk-go/ksc/utils" "github.com/KscSDK/ksc-sdk-go/service/eip" "github.com/KscSDK/ksc-sdk-go/service/sks" + "github.com/KscSDK/ksc-sdk-go/service/tagv2" "github.com/KscSDK/ksc-sdk-go/service/vpc" "github.com/hashicorp/packer-plugin-sdk/multistep" ) @@ -32,6 +33,11 @@ func (c *ClientConfig) Client(stateBag *multistep.BasicStateBag) *ClientWrapper &ksc.Config{Region: &c.KsyunRegion}, &utils.UrlInfo{ UseSSL: true, }) + + c.client.TagsClient = tagv2.SdkNew(ksc.NewClient(c.KsyunAccessKey, c.KsyunSecretKey), + &ksc.Config{Region: &c.KsyunRegion}, &utils.UrlInfo{ + UseSSL: true, + }) stateBag.Put("ksyun_client", c.client) return c.client } diff --git a/builder/common_config.go b/builder/common_config.go index fa27f2b..ac604fd 100644 --- a/builder/common_config.go +++ b/builder/common_config.go @@ -3,7 +3,10 @@ package ksyun -import "github.com/hashicorp/packer-plugin-sdk/communicator" +import ( + "github.com/hashicorp/packer-plugin-sdk/communicator" + "github.com/hashicorp/packer-plugin-sdk/template/config" +) type CommonConfig struct { // VPC ID allocated by the system. @@ -52,6 +55,16 @@ type CommonConfig struct { PublicIpBandWidth int `mapstructure:"public_ip_band_width" required:"false"` // Default is 0 ProjectId string `mapstructure:"project_id" required:"false"` + + // Key/value pair 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"` + // Same as [`run_tags`](#run_tags) but defined as a singular repeatable + // block containing a `key` and a `value` field. In HCL2 mode the + // [`dynamic_block`](/packer/docs/templates/hcl_templates/expressions#dynamic-blocks) + // will allow you to create those programatically. + RunTag config.KeyValues `mapstructure:"run_tag" required:"false"` + // Communicator settings Comm communicator.Config `mapstructure:",squash"` } diff --git a/builder/epc/builder.hcl2spec.go b/builder/epc/builder.hcl2spec.go index 78c6ef9..e39ea4e 100644 --- a/builder/epc/builder.hcl2spec.go +++ b/builder/epc/builder.hcl2spec.go @@ -4,113 +4,116 @@ package epc import ( "github.com/hashicorp/hcl/v2/hcldec" + "github.com/hashicorp/packer-plugin-sdk/template/config" "github.com/zclconf/go-cty/cty" ) // FlatConfig is an auto-generated flat version of Config. // Where the contents of a field with a `mapstructure:,squash` tag are bubbled up. type FlatConfig struct { - PackerBuildName *string `mapstructure:"packer_build_name" cty:"packer_build_name" hcl:"packer_build_name"` - PackerBuilderType *string `mapstructure:"packer_builder_type" cty:"packer_builder_type" hcl:"packer_builder_type"` - PackerCoreVersion *string `mapstructure:"packer_core_version" cty:"packer_core_version" hcl:"packer_core_version"` - PackerDebug *bool `mapstructure:"packer_debug" cty:"packer_debug" hcl:"packer_debug"` - PackerForce *bool `mapstructure:"packer_force" cty:"packer_force" hcl:"packer_force"` - PackerOnError *string `mapstructure:"packer_on_error" cty:"packer_on_error" hcl:"packer_on_error"` - PackerUserVars map[string]string `mapstructure:"packer_user_variables" cty:"packer_user_variables" hcl:"packer_user_variables"` - PackerSensitiveVars []string `mapstructure:"packer_sensitive_variables" cty:"packer_sensitive_variables" hcl:"packer_sensitive_variables"` - KsyunAccessKey *string `mapstructure:"access_key" required:"true" cty:"access_key" hcl:"access_key"` - KsyunSecretKey *string `mapstructure:"secret_key" required:"true" cty:"secret_key" hcl:"secret_key"` - KsyunRegion *string `mapstructure:"region" required:"true" cty:"region" hcl:"region"` - HostType *string `mapstructure:"host_type" required:"true" cty:"host_type" hcl:"host_type"` - Raid *string `mapstructure:"raid" required:"false" cty:"raid" hcl:"raid"` - SourceImageId *string `mapstructure:"source_image_id" required:"true" cty:"source_image_id" hcl:"source_image_id"` - NetworkInterfaceMode *string `mapstructure:"network_interface_mode" required:"false" cty:"network_interface_mode" hcl:"network_interface_mode"` - HostName *string `mapstructure:"host_name" required:"false" cty:"host_name" hcl:"host_name"` - ComputerName *string `mapstructure:"computer_name" required:"false" cty:"computer_name" hcl:"computer_name"` - HostChargeType *string `mapstructure:"host_charge_type" required:"false" cty:"host_charge_type" hcl:"host_charge_type"` - SecurityAgent *string `mapstructure:"security_agent" required:"false" cty:"security_agent" hcl:"security_agent"` - ContainerAgent *string `mapstructure:"container_agent" required:"false" cty:"container_agent" hcl:"container_agent"` - CloudMonitorAgent *string `mapstructure:"cloud_monitor_agent" required:"false" cty:"cloud_monitor_agent" hcl:"cloud_monitor_agent"` - SystemFileType *string `mapstructure:"system_file_type" required:"false" cty:"system_file_type" hcl:"system_file_type"` - DataFileType *string `mapstructure:"data_file_type" required:"false" cty:"data_file_type" hcl:"data_file_type"` - DataDiskCatalogue *string `mapstructure:"data_disk_catalogue" required:"false" cty:"data_disk_catalogue" hcl:"data_disk_catalogue"` - DataDiskCatalogueSuffix *string `mapstructure:"data_disk_catalogue_suffix" required:"false" cty:"data_disk_catalogue_suffix" hcl:"data_disk_catalogue_suffix"` - ExtensionSubnetId *string `mapstructure:"extension_subnet_id" required:"false" cty:"extension_subnet_id" hcl:"extension_subnet_id"` - ExtensionSubnetName *string `mapstructure:"extension_subnet_name" required:"false" cty:"extension_subnet_name" hcl:"extension_subnet_name"` - ExtensionSubnetCidrBlock *string `mapstructure:"extension_subnet_cidr_block" required:"false" cty:"extension_subnet_cidr_block" hcl:"extension_subnet_cidr_block"` - ExtensionPrivateIpAddress *string `mapstructure:"extension_private_ip_address" required:"false" cty:"extension_private_ip_address" hcl:"extension_private_ip_address"` - ExtensionDNS1 *string `mapstructure:"extension_dns1" required:"false" cty:"extension_dns1" hcl:"extension_dns1"` - ExtensionDNS2 *string `mapstructure:"extension_dns2" required:"false" cty:"extension_dns2" hcl:"extension_dns2"` - ExtensionSecurityGroupId *string `mapstructure:"extension_security_group_id" required:"false" cty:"extension_security_group_id" hcl:"extension_security_group_id"` - ExtensionSecurityGroupName *string `mapstructure:"extension_security_group_name" required:"false" cty:"extension_security_group_name" hcl:"extension_security_group_name"` - TempSubnetId *string `cty:"temp_subnet_id" hcl:"temp_subnet_id"` - TempSecurityGroupId *string `cty:"temp_security_group_id" hcl:"temp_security_group_id"` - 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"` - VpcCidrBlock *string `mapstructure:"vpc_cidr_block" required:"false" cty:"vpc_cidr_block" hcl:"vpc_cidr_block"` - SubnetId *string `mapstructure:"subnet_id" required:"false" cty:"subnet_id" hcl:"subnet_id"` - SubnetName *string `mapstructure:"subnet_name" required:"false" cty:"subnet_name" hcl:"subnet_name"` - DNS1 *string `mapstructure:"dns1" required:"false" cty:"dns1" hcl:"dns1"` - DNS2 *string `mapstructure:"dns2" required:"false" cty:"dns2" hcl:"dns2"` - SubnetCidrBlock *string `mapstructure:"subnet_cidr_block" required:"false" cty:"subnet_cidr_block" hcl:"subnet_cidr_block"` - AvailabilityZone *string `mapstructure:"availability_zone" required:"false" cty:"availability_zone" hcl:"availability_zone"` - SecurityGroupId *string `mapstructure:"security_group_id" required:"false" cty:"security_group_id" hcl:"security_group_id"` - SecurityGroupName *string `mapstructure:"security_group_name" required:"false" cty:"security_group_name" hcl:"security_group_name"` - PrivateIpAddress *string `mapstructure:"private_ip_address" required:"false" cty:"private_ip_address" hcl:"private_ip_address"` - AssociatePublicIpAddress *bool `mapstructure:"associate_public_ip_address" required:"false" cty:"associate_public_ip_address" hcl:"associate_public_ip_address"` - PublicIpChargeType *string `mapstructure:"public_ip_charge_type" required:"false" cty:"public_ip_charge_type" hcl:"public_ip_charge_type"` - PublicIpBandWidth *int `mapstructure:"public_ip_band_width" required:"false" cty:"public_ip_band_width" hcl:"public_ip_band_width"` - ProjectId *string `mapstructure:"project_id" required:"false" cty:"project_id" hcl:"project_id"` - Type *string `mapstructure:"communicator" cty:"communicator" hcl:"communicator"` - PauseBeforeConnect *string `mapstructure:"pause_before_connecting" cty:"pause_before_connecting" hcl:"pause_before_connecting"` - SSHHost *string `mapstructure:"ssh_host" cty:"ssh_host" hcl:"ssh_host"` - SSHPort *int `mapstructure:"ssh_port" cty:"ssh_port" hcl:"ssh_port"` - SSHUsername *string `mapstructure:"ssh_username" cty:"ssh_username" hcl:"ssh_username"` - SSHPassword *string `mapstructure:"ssh_password" cty:"ssh_password" hcl:"ssh_password"` - SSHKeyPairName *string `mapstructure:"ssh_keypair_name" undocumented:"true" cty:"ssh_keypair_name" hcl:"ssh_keypair_name"` - SSHTemporaryKeyPairName *string `mapstructure:"temporary_key_pair_name" undocumented:"true" cty:"temporary_key_pair_name" hcl:"temporary_key_pair_name"` - SSHTemporaryKeyPairType *string `mapstructure:"temporary_key_pair_type" cty:"temporary_key_pair_type" hcl:"temporary_key_pair_type"` - SSHTemporaryKeyPairBits *int `mapstructure:"temporary_key_pair_bits" cty:"temporary_key_pair_bits" hcl:"temporary_key_pair_bits"` - SSHCiphers []string `mapstructure:"ssh_ciphers" cty:"ssh_ciphers" hcl:"ssh_ciphers"` - SSHClearAuthorizedKeys *bool `mapstructure:"ssh_clear_authorized_keys" cty:"ssh_clear_authorized_keys" hcl:"ssh_clear_authorized_keys"` - SSHKEXAlgos []string `mapstructure:"ssh_key_exchange_algorithms" cty:"ssh_key_exchange_algorithms" hcl:"ssh_key_exchange_algorithms"` - SSHPrivateKeyFile *string `mapstructure:"ssh_private_key_file" undocumented:"true" cty:"ssh_private_key_file" hcl:"ssh_private_key_file"` - SSHCertificateFile *string `mapstructure:"ssh_certificate_file" cty:"ssh_certificate_file" hcl:"ssh_certificate_file"` - SSHPty *bool `mapstructure:"ssh_pty" cty:"ssh_pty" hcl:"ssh_pty"` - SSHTimeout *string `mapstructure:"ssh_timeout" cty:"ssh_timeout" hcl:"ssh_timeout"` - SSHWaitTimeout *string `mapstructure:"ssh_wait_timeout" undocumented:"true" cty:"ssh_wait_timeout" hcl:"ssh_wait_timeout"` - SSHAgentAuth *bool `mapstructure:"ssh_agent_auth" undocumented:"true" cty:"ssh_agent_auth" hcl:"ssh_agent_auth"` - SSHDisableAgentForwarding *bool `mapstructure:"ssh_disable_agent_forwarding" cty:"ssh_disable_agent_forwarding" hcl:"ssh_disable_agent_forwarding"` - SSHHandshakeAttempts *int `mapstructure:"ssh_handshake_attempts" cty:"ssh_handshake_attempts" hcl:"ssh_handshake_attempts"` - SSHBastionHost *string `mapstructure:"ssh_bastion_host" cty:"ssh_bastion_host" hcl:"ssh_bastion_host"` - SSHBastionPort *int `mapstructure:"ssh_bastion_port" cty:"ssh_bastion_port" hcl:"ssh_bastion_port"` - SSHBastionAgentAuth *bool `mapstructure:"ssh_bastion_agent_auth" cty:"ssh_bastion_agent_auth" hcl:"ssh_bastion_agent_auth"` - SSHBastionUsername *string `mapstructure:"ssh_bastion_username" cty:"ssh_bastion_username" hcl:"ssh_bastion_username"` - SSHBastionPassword *string `mapstructure:"ssh_bastion_password" cty:"ssh_bastion_password" hcl:"ssh_bastion_password"` - SSHBastionInteractive *bool `mapstructure:"ssh_bastion_interactive" cty:"ssh_bastion_interactive" hcl:"ssh_bastion_interactive"` - SSHBastionPrivateKeyFile *string `mapstructure:"ssh_bastion_private_key_file" cty:"ssh_bastion_private_key_file" hcl:"ssh_bastion_private_key_file"` - SSHBastionCertificateFile *string `mapstructure:"ssh_bastion_certificate_file" cty:"ssh_bastion_certificate_file" hcl:"ssh_bastion_certificate_file"` - SSHFileTransferMethod *string `mapstructure:"ssh_file_transfer_method" cty:"ssh_file_transfer_method" hcl:"ssh_file_transfer_method"` - SSHProxyHost *string `mapstructure:"ssh_proxy_host" cty:"ssh_proxy_host" hcl:"ssh_proxy_host"` - SSHProxyPort *int `mapstructure:"ssh_proxy_port" cty:"ssh_proxy_port" hcl:"ssh_proxy_port"` - SSHProxyUsername *string `mapstructure:"ssh_proxy_username" cty:"ssh_proxy_username" hcl:"ssh_proxy_username"` - SSHProxyPassword *string `mapstructure:"ssh_proxy_password" cty:"ssh_proxy_password" hcl:"ssh_proxy_password"` - SSHKeepAliveInterval *string `mapstructure:"ssh_keep_alive_interval" cty:"ssh_keep_alive_interval" hcl:"ssh_keep_alive_interval"` - SSHReadWriteTimeout *string `mapstructure:"ssh_read_write_timeout" cty:"ssh_read_write_timeout" hcl:"ssh_read_write_timeout"` - SSHRemoteTunnels []string `mapstructure:"ssh_remote_tunnels" cty:"ssh_remote_tunnels" hcl:"ssh_remote_tunnels"` - SSHLocalTunnels []string `mapstructure:"ssh_local_tunnels" cty:"ssh_local_tunnels" hcl:"ssh_local_tunnels"` - SSHPublicKey []byte `mapstructure:"ssh_public_key" undocumented:"true" cty:"ssh_public_key" hcl:"ssh_public_key"` - SSHPrivateKey []byte `mapstructure:"ssh_private_key" undocumented:"true" cty:"ssh_private_key" hcl:"ssh_private_key"` - WinRMUser *string `mapstructure:"winrm_username" cty:"winrm_username" hcl:"winrm_username"` - WinRMPassword *string `mapstructure:"winrm_password" cty:"winrm_password" hcl:"winrm_password"` - WinRMHost *string `mapstructure:"winrm_host" cty:"winrm_host" hcl:"winrm_host"` - WinRMNoProxy *bool `mapstructure:"winrm_no_proxy" cty:"winrm_no_proxy" hcl:"winrm_no_proxy"` - WinRMPort *int `mapstructure:"winrm_port" cty:"winrm_port" hcl:"winrm_port"` - WinRMTimeout *string `mapstructure:"winrm_timeout" cty:"winrm_timeout" hcl:"winrm_timeout"` - WinRMUseSSL *bool `mapstructure:"winrm_use_ssl" cty:"winrm_use_ssl" hcl:"winrm_use_ssl"` - WinRMInsecure *bool `mapstructure:"winrm_insecure" cty:"winrm_insecure" hcl:"winrm_insecure"` - WinRMUseNTLM *bool `mapstructure:"winrm_use_ntlm" cty:"winrm_use_ntlm" hcl:"winrm_use_ntlm"` - KsyunImageName *string `mapstructure:"image_name" required:"false" cty:"image_name" hcl:"image_name"` + PackerBuildName *string `mapstructure:"packer_build_name" cty:"packer_build_name" hcl:"packer_build_name"` + PackerBuilderType *string `mapstructure:"packer_builder_type" cty:"packer_builder_type" hcl:"packer_builder_type"` + PackerCoreVersion *string `mapstructure:"packer_core_version" cty:"packer_core_version" hcl:"packer_core_version"` + PackerDebug *bool `mapstructure:"packer_debug" cty:"packer_debug" hcl:"packer_debug"` + PackerForce *bool `mapstructure:"packer_force" cty:"packer_force" hcl:"packer_force"` + PackerOnError *string `mapstructure:"packer_on_error" cty:"packer_on_error" hcl:"packer_on_error"` + PackerUserVars map[string]string `mapstructure:"packer_user_variables" cty:"packer_user_variables" hcl:"packer_user_variables"` + PackerSensitiveVars []string `mapstructure:"packer_sensitive_variables" cty:"packer_sensitive_variables" hcl:"packer_sensitive_variables"` + KsyunAccessKey *string `mapstructure:"access_key" required:"true" cty:"access_key" hcl:"access_key"` + KsyunSecretKey *string `mapstructure:"secret_key" required:"true" cty:"secret_key" hcl:"secret_key"` + KsyunRegion *string `mapstructure:"region" required:"true" cty:"region" hcl:"region"` + HostType *string `mapstructure:"host_type" required:"true" cty:"host_type" hcl:"host_type"` + Raid *string `mapstructure:"raid" required:"false" cty:"raid" hcl:"raid"` + SourceImageId *string `mapstructure:"source_image_id" required:"true" cty:"source_image_id" hcl:"source_image_id"` + NetworkInterfaceMode *string `mapstructure:"network_interface_mode" required:"false" cty:"network_interface_mode" hcl:"network_interface_mode"` + HostName *string `mapstructure:"host_name" required:"false" cty:"host_name" hcl:"host_name"` + ComputerName *string `mapstructure:"computer_name" required:"false" cty:"computer_name" hcl:"computer_name"` + HostChargeType *string `mapstructure:"host_charge_type" required:"false" cty:"host_charge_type" hcl:"host_charge_type"` + SecurityAgent *string `mapstructure:"security_agent" required:"false" cty:"security_agent" hcl:"security_agent"` + ContainerAgent *string `mapstructure:"container_agent" required:"false" cty:"container_agent" hcl:"container_agent"` + CloudMonitorAgent *string `mapstructure:"cloud_monitor_agent" required:"false" cty:"cloud_monitor_agent" hcl:"cloud_monitor_agent"` + SystemFileType *string `mapstructure:"system_file_type" required:"false" cty:"system_file_type" hcl:"system_file_type"` + DataFileType *string `mapstructure:"data_file_type" required:"false" cty:"data_file_type" hcl:"data_file_type"` + DataDiskCatalogue *string `mapstructure:"data_disk_catalogue" required:"false" cty:"data_disk_catalogue" hcl:"data_disk_catalogue"` + DataDiskCatalogueSuffix *string `mapstructure:"data_disk_catalogue_suffix" required:"false" cty:"data_disk_catalogue_suffix" hcl:"data_disk_catalogue_suffix"` + ExtensionSubnetId *string `mapstructure:"extension_subnet_id" required:"false" cty:"extension_subnet_id" hcl:"extension_subnet_id"` + ExtensionSubnetName *string `mapstructure:"extension_subnet_name" required:"false" cty:"extension_subnet_name" hcl:"extension_subnet_name"` + ExtensionSubnetCidrBlock *string `mapstructure:"extension_subnet_cidr_block" required:"false" cty:"extension_subnet_cidr_block" hcl:"extension_subnet_cidr_block"` + ExtensionPrivateIpAddress *string `mapstructure:"extension_private_ip_address" required:"false" cty:"extension_private_ip_address" hcl:"extension_private_ip_address"` + ExtensionDNS1 *string `mapstructure:"extension_dns1" required:"false" cty:"extension_dns1" hcl:"extension_dns1"` + ExtensionDNS2 *string `mapstructure:"extension_dns2" required:"false" cty:"extension_dns2" hcl:"extension_dns2"` + ExtensionSecurityGroupId *string `mapstructure:"extension_security_group_id" required:"false" cty:"extension_security_group_id" hcl:"extension_security_group_id"` + ExtensionSecurityGroupName *string `mapstructure:"extension_security_group_name" required:"false" cty:"extension_security_group_name" hcl:"extension_security_group_name"` + TempSubnetId *string `cty:"temp_subnet_id" hcl:"temp_subnet_id"` + TempSecurityGroupId *string `cty:"temp_security_group_id" hcl:"temp_security_group_id"` + 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"` + VpcCidrBlock *string `mapstructure:"vpc_cidr_block" required:"false" cty:"vpc_cidr_block" hcl:"vpc_cidr_block"` + SubnetId *string `mapstructure:"subnet_id" required:"false" cty:"subnet_id" hcl:"subnet_id"` + SubnetName *string `mapstructure:"subnet_name" required:"false" cty:"subnet_name" hcl:"subnet_name"` + DNS1 *string `mapstructure:"dns1" required:"false" cty:"dns1" hcl:"dns1"` + DNS2 *string `mapstructure:"dns2" required:"false" cty:"dns2" hcl:"dns2"` + SubnetCidrBlock *string `mapstructure:"subnet_cidr_block" required:"false" cty:"subnet_cidr_block" hcl:"subnet_cidr_block"` + AvailabilityZone *string `mapstructure:"availability_zone" required:"false" cty:"availability_zone" hcl:"availability_zone"` + SecurityGroupId *string `mapstructure:"security_group_id" required:"false" cty:"security_group_id" hcl:"security_group_id"` + SecurityGroupName *string `mapstructure:"security_group_name" required:"false" cty:"security_group_name" hcl:"security_group_name"` + PrivateIpAddress *string `mapstructure:"private_ip_address" required:"false" cty:"private_ip_address" hcl:"private_ip_address"` + AssociatePublicIpAddress *bool `mapstructure:"associate_public_ip_address" required:"false" cty:"associate_public_ip_address" hcl:"associate_public_ip_address"` + PublicIpChargeType *string `mapstructure:"public_ip_charge_type" required:"false" cty:"public_ip_charge_type" hcl:"public_ip_charge_type"` + PublicIpBandWidth *int `mapstructure:"public_ip_band_width" required:"false" cty:"public_ip_band_width" hcl:"public_ip_band_width"` + ProjectId *string `mapstructure:"project_id" required:"false" cty:"project_id" hcl:"project_id"` + RunTags map[string]string `mapstructure:"run_tags" required:"false" cty:"run_tags" hcl:"run_tags"` + RunTag []config.FlatKeyValue `mapstructure:"run_tag" required:"false" cty:"run_tag" hcl:"run_tag"` + Type *string `mapstructure:"communicator" cty:"communicator" hcl:"communicator"` + PauseBeforeConnect *string `mapstructure:"pause_before_connecting" cty:"pause_before_connecting" hcl:"pause_before_connecting"` + SSHHost *string `mapstructure:"ssh_host" cty:"ssh_host" hcl:"ssh_host"` + SSHPort *int `mapstructure:"ssh_port" cty:"ssh_port" hcl:"ssh_port"` + SSHUsername *string `mapstructure:"ssh_username" cty:"ssh_username" hcl:"ssh_username"` + SSHPassword *string `mapstructure:"ssh_password" cty:"ssh_password" hcl:"ssh_password"` + SSHKeyPairName *string `mapstructure:"ssh_keypair_name" undocumented:"true" cty:"ssh_keypair_name" hcl:"ssh_keypair_name"` + SSHTemporaryKeyPairName *string `mapstructure:"temporary_key_pair_name" undocumented:"true" cty:"temporary_key_pair_name" hcl:"temporary_key_pair_name"` + SSHTemporaryKeyPairType *string `mapstructure:"temporary_key_pair_type" cty:"temporary_key_pair_type" hcl:"temporary_key_pair_type"` + SSHTemporaryKeyPairBits *int `mapstructure:"temporary_key_pair_bits" cty:"temporary_key_pair_bits" hcl:"temporary_key_pair_bits"` + SSHCiphers []string `mapstructure:"ssh_ciphers" cty:"ssh_ciphers" hcl:"ssh_ciphers"` + SSHClearAuthorizedKeys *bool `mapstructure:"ssh_clear_authorized_keys" cty:"ssh_clear_authorized_keys" hcl:"ssh_clear_authorized_keys"` + SSHKEXAlgos []string `mapstructure:"ssh_key_exchange_algorithms" cty:"ssh_key_exchange_algorithms" hcl:"ssh_key_exchange_algorithms"` + SSHPrivateKeyFile *string `mapstructure:"ssh_private_key_file" undocumented:"true" cty:"ssh_private_key_file" hcl:"ssh_private_key_file"` + SSHCertificateFile *string `mapstructure:"ssh_certificate_file" cty:"ssh_certificate_file" hcl:"ssh_certificate_file"` + SSHPty *bool `mapstructure:"ssh_pty" cty:"ssh_pty" hcl:"ssh_pty"` + SSHTimeout *string `mapstructure:"ssh_timeout" cty:"ssh_timeout" hcl:"ssh_timeout"` + SSHWaitTimeout *string `mapstructure:"ssh_wait_timeout" undocumented:"true" cty:"ssh_wait_timeout" hcl:"ssh_wait_timeout"` + SSHAgentAuth *bool `mapstructure:"ssh_agent_auth" undocumented:"true" cty:"ssh_agent_auth" hcl:"ssh_agent_auth"` + SSHDisableAgentForwarding *bool `mapstructure:"ssh_disable_agent_forwarding" cty:"ssh_disable_agent_forwarding" hcl:"ssh_disable_agent_forwarding"` + SSHHandshakeAttempts *int `mapstructure:"ssh_handshake_attempts" cty:"ssh_handshake_attempts" hcl:"ssh_handshake_attempts"` + SSHBastionHost *string `mapstructure:"ssh_bastion_host" cty:"ssh_bastion_host" hcl:"ssh_bastion_host"` + SSHBastionPort *int `mapstructure:"ssh_bastion_port" cty:"ssh_bastion_port" hcl:"ssh_bastion_port"` + SSHBastionAgentAuth *bool `mapstructure:"ssh_bastion_agent_auth" cty:"ssh_bastion_agent_auth" hcl:"ssh_bastion_agent_auth"` + SSHBastionUsername *string `mapstructure:"ssh_bastion_username" cty:"ssh_bastion_username" hcl:"ssh_bastion_username"` + SSHBastionPassword *string `mapstructure:"ssh_bastion_password" cty:"ssh_bastion_password" hcl:"ssh_bastion_password"` + SSHBastionInteractive *bool `mapstructure:"ssh_bastion_interactive" cty:"ssh_bastion_interactive" hcl:"ssh_bastion_interactive"` + SSHBastionPrivateKeyFile *string `mapstructure:"ssh_bastion_private_key_file" cty:"ssh_bastion_private_key_file" hcl:"ssh_bastion_private_key_file"` + SSHBastionCertificateFile *string `mapstructure:"ssh_bastion_certificate_file" cty:"ssh_bastion_certificate_file" hcl:"ssh_bastion_certificate_file"` + SSHFileTransferMethod *string `mapstructure:"ssh_file_transfer_method" cty:"ssh_file_transfer_method" hcl:"ssh_file_transfer_method"` + SSHProxyHost *string `mapstructure:"ssh_proxy_host" cty:"ssh_proxy_host" hcl:"ssh_proxy_host"` + SSHProxyPort *int `mapstructure:"ssh_proxy_port" cty:"ssh_proxy_port" hcl:"ssh_proxy_port"` + SSHProxyUsername *string `mapstructure:"ssh_proxy_username" cty:"ssh_proxy_username" hcl:"ssh_proxy_username"` + SSHProxyPassword *string `mapstructure:"ssh_proxy_password" cty:"ssh_proxy_password" hcl:"ssh_proxy_password"` + SSHKeepAliveInterval *string `mapstructure:"ssh_keep_alive_interval" cty:"ssh_keep_alive_interval" hcl:"ssh_keep_alive_interval"` + SSHReadWriteTimeout *string `mapstructure:"ssh_read_write_timeout" cty:"ssh_read_write_timeout" hcl:"ssh_read_write_timeout"` + SSHRemoteTunnels []string `mapstructure:"ssh_remote_tunnels" cty:"ssh_remote_tunnels" hcl:"ssh_remote_tunnels"` + SSHLocalTunnels []string `mapstructure:"ssh_local_tunnels" cty:"ssh_local_tunnels" hcl:"ssh_local_tunnels"` + SSHPublicKey []byte `mapstructure:"ssh_public_key" undocumented:"true" cty:"ssh_public_key" hcl:"ssh_public_key"` + SSHPrivateKey []byte `mapstructure:"ssh_private_key" undocumented:"true" cty:"ssh_private_key" hcl:"ssh_private_key"` + WinRMUser *string `mapstructure:"winrm_username" cty:"winrm_username" hcl:"winrm_username"` + WinRMPassword *string `mapstructure:"winrm_password" cty:"winrm_password" hcl:"winrm_password"` + WinRMHost *string `mapstructure:"winrm_host" cty:"winrm_host" hcl:"winrm_host"` + WinRMNoProxy *bool `mapstructure:"winrm_no_proxy" cty:"winrm_no_proxy" hcl:"winrm_no_proxy"` + WinRMPort *int `mapstructure:"winrm_port" cty:"winrm_port" hcl:"winrm_port"` + WinRMTimeout *string `mapstructure:"winrm_timeout" cty:"winrm_timeout" hcl:"winrm_timeout"` + WinRMUseSSL *bool `mapstructure:"winrm_use_ssl" cty:"winrm_use_ssl" hcl:"winrm_use_ssl"` + WinRMInsecure *bool `mapstructure:"winrm_insecure" cty:"winrm_insecure" hcl:"winrm_insecure"` + WinRMUseNTLM *bool `mapstructure:"winrm_use_ntlm" cty:"winrm_use_ntlm" hcl:"winrm_use_ntlm"` + KsyunImageName *string `mapstructure:"image_name" required:"false" cty:"image_name" hcl:"image_name"` } // FlatMapstructure returns a new FlatConfig. @@ -176,6 +179,8 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "public_ip_charge_type": &hcldec.AttrSpec{Name: "public_ip_charge_type", Type: cty.String, Required: false}, "public_ip_band_width": &hcldec.AttrSpec{Name: "public_ip_band_width", Type: cty.Number, Required: false}, "project_id": &hcldec.AttrSpec{Name: "project_id", Type: cty.String, Required: false}, + "run_tags": &hcldec.AttrSpec{Name: "run_tags", Type: cty.Map(cty.String), Required: false}, + "run_tag": &hcldec.BlockListSpec{TypeName: "run_tag", Nested: hcldec.ObjectSpec((*config.FlatKeyValue)(nil).HCL2Spec())}, "communicator": &hcldec.AttrSpec{Name: "communicator", Type: cty.String, Required: false}, "pause_before_connecting": &hcldec.AttrSpec{Name: "pause_before_connecting", Type: cty.String, Required: false}, "ssh_host": &hcldec.AttrSpec{Name: "ssh_host", Type: cty.String, Required: false}, diff --git a/builder/kec/builder.go b/builder/kec/builder.go index a055dde..fff1bd0 100644 --- a/builder/kec/builder.go +++ b/builder/kec/builder.go @@ -127,6 +127,10 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook) KsyunRunConfig: &b.config.KsyunKecRunConfig, KsyunImageConfig: &b.config.KsyunImageConfig, }, + &ksyun.StepCreateKsyunTags{ + Tags: b.config.Tags, + ResourceType: ksyun.ResourceTypeImage, + }, } // Run! diff --git a/builder/kec/builder.hcl2spec.go b/builder/kec/builder.hcl2spec.go index 90e577e..e04e8d4 100644 --- a/builder/kec/builder.hcl2spec.go +++ b/builder/kec/builder.hcl2spec.go @@ -4,6 +4,7 @@ package kec import ( "github.com/hashicorp/hcl/v2/hcldec" + "github.com/hashicorp/packer-plugin-sdk/template/config" ksyun "github.com/kingsoftcloud/packer-plugin-ksyun/builder" "github.com/zclconf/go-cty/cty" ) @@ -31,6 +32,8 @@ type FlatConfig struct { KsyunImageCopyNames []string `mapstructure:"image_copy_names" required:"false" cty:"image_copy_names" hcl:"image_copy_names"` KsyunImageShareAccounts []string `mapstructure:"image_share_accounts" required:"false" cty:"image_share_accounts" hcl:"image_share_accounts"` KsyunImageWarmUp *bool `mapstructure:"image_warm_up" required:"false" cty:"image_warm_up" hcl:"image_warm_up"` + Tags map[string]string `mapstructure:"tags" required:"false" cty:"tags" hcl:"tags"` + Tag []config.FlatKeyValue `mapstructure:"tag" required:"false" cty:"tag" hcl:"tag"` InstanceType *string `mapstructure:"instance_type" required:"true" cty:"instance_type" hcl:"instance_type"` SourceImageId *string `mapstructure:"source_image_id" required:"true" cty:"source_image_id" hcl:"source_image_id"` SourceImageFilter *ksyun.FlatKmiFilterOptions `mapstructure:"source_image_filter" required:"false" cty:"source_image_filter" hcl:"source_image_filter"` @@ -59,6 +62,8 @@ type FlatConfig struct { PublicIpChargeType *string `mapstructure:"public_ip_charge_type" required:"false" cty:"public_ip_charge_type" hcl:"public_ip_charge_type"` PublicIpBandWidth *int `mapstructure:"public_ip_band_width" required:"false" cty:"public_ip_band_width" hcl:"public_ip_band_width"` ProjectId *string `mapstructure:"project_id" required:"false" cty:"project_id" hcl:"project_id"` + RunTags map[string]string `mapstructure:"run_tags" required:"false" cty:"run_tags" hcl:"run_tags"` + RunTag []config.FlatKeyValue `mapstructure:"run_tag" required:"false" cty:"run_tag" hcl:"run_tag"` Type *string `mapstructure:"communicator" cty:"communicator" hcl:"communicator"` PauseBeforeConnect *string `mapstructure:"pause_before_connecting" cty:"pause_before_connecting" hcl:"pause_before_connecting"` SSHHost *string `mapstructure:"ssh_host" cty:"ssh_host" hcl:"ssh_host"` @@ -142,6 +147,8 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "image_copy_names": &hcldec.AttrSpec{Name: "image_copy_names", Type: cty.List(cty.String), Required: false}, "image_share_accounts": &hcldec.AttrSpec{Name: "image_share_accounts", Type: cty.List(cty.String), Required: false}, "image_warm_up": &hcldec.AttrSpec{Name: "image_warm_up", Type: cty.Bool, Required: false}, + "tags": &hcldec.AttrSpec{Name: "tags", Type: cty.Map(cty.String), Required: false}, + "tag": &hcldec.BlockListSpec{TypeName: "tag", Nested: hcldec.ObjectSpec((*config.FlatKeyValue)(nil).HCL2Spec())}, "instance_type": &hcldec.AttrSpec{Name: "instance_type", Type: cty.String, Required: false}, "source_image_id": &hcldec.AttrSpec{Name: "source_image_id", Type: cty.String, Required: false}, "source_image_filter": &hcldec.BlockSpec{TypeName: "source_image_filter", Nested: hcldec.ObjectSpec((*ksyun.FlatKmiFilterOptions)(nil).HCL2Spec())}, @@ -170,6 +177,8 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "public_ip_charge_type": &hcldec.AttrSpec{Name: "public_ip_charge_type", Type: cty.String, Required: false}, "public_ip_band_width": &hcldec.AttrSpec{Name: "public_ip_band_width", Type: cty.Number, Required: false}, "project_id": &hcldec.AttrSpec{Name: "project_id", Type: cty.String, Required: false}, + "run_tags": &hcldec.AttrSpec{Name: "run_tags", Type: cty.Map(cty.String), Required: false}, + "run_tag": &hcldec.BlockListSpec{TypeName: "run_tag", Nested: hcldec.ObjectSpec((*config.FlatKeyValue)(nil).HCL2Spec())}, "communicator": &hcldec.AttrSpec{Name: "communicator", Type: cty.String, Required: false}, "pause_before_connecting": &hcldec.AttrSpec{Name: "pause_before_connecting", Type: cty.String, Required: false}, "ssh_host": &hcldec.AttrSpec{Name: "ssh_host", Type: cty.String, Required: false}, diff --git a/builder/kec/image_config.go b/builder/kec/image_config.go index 199887d..83e9ec4 100644 --- a/builder/kec/image_config.go +++ b/builder/kec/image_config.go @@ -6,6 +6,7 @@ import ( "fmt" "regexp" + "github.com/hashicorp/packer-plugin-sdk/template/config" "github.com/hashicorp/packer-plugin-sdk/template/interpolate" ) @@ -49,6 +50,15 @@ type KsyunImageConfig struct { // Set the image as warm-up for fast boot KsyunImageWarmUp bool `mapstructure:"image_warm_up" required:"false"` + + // Key/value pair tags applied to the destination image. + Tags map[string]string `mapstructure:"tags" required:"false"` + + // Same as [`tags`](#tags) but defined as a singular repeatable + // block containing a `key` and a `value` field. In HCL2 mode the + // [`dynamic_block`](/packer/docs/templates/hcl_templates/expressions#dynamic-blocks) + // will allow you to create those programatically. + Tag config.KeyValues `mapstructure:"tag" required:"false"` } func (c *KsyunImageConfig) Prepare(ctx *interpolate.Context) []error { @@ -62,5 +72,12 @@ func (c *KsyunImageConfig) Prepare(ctx *interpolate.Context) []error { if !match { errs = append(errs, fmt.Errorf("image_name can't matched")) } + + if c.Tags == nil { + c.Tags = make(map[string]string) + } + + // Copy singular tag maps + errs = append(errs, c.Tag.CopyOn(&c.Tags)...) return errs } diff --git a/builder/kec/run_config.go b/builder/kec/run_config.go index b746994..f2b8cf9 100644 --- a/builder/kec/run_config.go +++ b/builder/kec/run_config.go @@ -106,5 +106,12 @@ func (c *KsyunKecRunConfig) Prepare(ctx *interpolate.Context) []error { errs = append(errs, errors.New("A ksyun_instance_type must be specified")) } + if c.RunTags == nil { + c.RunTags = make(map[string]string) + } + + // Copy singular tag maps + errs = append(errs, c.RunTag.CopyOn(&c.RunTags)...) + return errs } diff --git a/builder/kec/step_create_kec.go b/builder/kec/step_create_kec.go index 7fac2fb..e06f3bc 100644 --- a/builder/kec/step_create_kec.go +++ b/builder/kec/step_create_kec.go @@ -138,6 +138,18 @@ func (s *stepCreateKsyunKec) Run(ctx context.Context, stateBag multistep.StateBa return ksyun.Halt(stateBag, createErr, fmt.Sprintf("Error Wait new kec instance id %s status active", instanceId)) } stateBag.Put("InstanceId", instanceId) + + // processing tag on kec + if len(s.KsyunRunConfig.RunTags) > 0 { + ui.Say("Pinning tags on Kec instance") + ksyunTags := ksyun.TagMap(s.KsyunRunConfig.RunTags).KsyunTags() + ksyunTags.Report(ui) + + err := ksyunTags.Pinning(ksyun.ResourceTypeKec, instanceId, client.TagsClient) + if err != nil { + return ksyun.Halt(stateBag, err, "Error pinning tags to instance") + } + } } return multistep.ActionContinue } diff --git a/builder/step_config_eip.go b/builder/step_config_eip.go index 925cb6d..7ab9511 100644 --- a/builder/step_config_eip.go +++ b/builder/step_config_eip.go @@ -3,9 +3,10 @@ package ksyun import ( "context" "fmt" + "strconv" + "github.com/hashicorp/packer-plugin-sdk/multistep" packersdk "github.com/hashicorp/packer-plugin-sdk/packer" - "strconv" ) type StepConfigKsyunPublicIp struct { @@ -40,7 +41,7 @@ func (s *StepConfigKsyunPublicIp) Run(ctx context.Context, stateBag multistep.St } if checkChargeType { ui.Say("Allocating eip...") - //create eip + // create eip createEip := make(map[string]interface{}) createEip["BandWidth"] = strconv.Itoa(s.CommonConfig.PublicIpBandWidth) createEip["ChargeType"] = s.CommonConfig.PublicIpChargeType @@ -55,7 +56,7 @@ func (s *StepConfigKsyunPublicIp) Run(ctx context.Context, stateBag multistep.St s.eipId = allocationId stateBag.Put("publicIp", publicIp) ui.Say("Associating eip to instance") - //create_security_group_rule + // create_security_group_rule authorizeSecurityGroupEntry := make(map[string]interface{}) authorizeSecurityGroupEntry["securityGroupId"] = s.CommonConfig.SecurityGroupId authorizeSecurityGroupEntry["CidrBlock"] = "0.0.0.0/0" @@ -67,7 +68,7 @@ func (s *StepConfigKsyunPublicIp) Run(ctx context.Context, stateBag multistep.St if errRule != nil { return Halt(stateBag, errRule, "Error creating eip SecurityGroupRule") } - //associate eip + // associate eip associateAddress := make(map[string]interface{}) associateAddress["AllocationId"] = allocationId associateAddress["InstanceType"] = "Ipfwd" @@ -76,6 +77,18 @@ func (s *StepConfigKsyunPublicIp) Run(ctx context.Context, stateBag multistep.St if err != nil { return Halt(stateBag, err, "Error associate eip to instance") } + + // processing tag on eip + if len(s.CommonConfig.RunTags) > 0 { + ui.Say("Pinning tags on Eip") + ksyunTags := TagMap(s.CommonConfig.RunTags).KsyunTags() + ksyunTags.Report(ui) + + err = ksyunTags.Pinning(ResourceTypeEip, allocationId, client.TagsClient) + if err != nil { + return Halt(stateBag, err, "Error pinning tags to eip") + } + } } } else { diff --git a/builder/step_create_tags.go b/builder/step_create_tags.go new file mode 100644 index 0000000..fbaf38e --- /dev/null +++ b/builder/step_create_tags.go @@ -0,0 +1,47 @@ +package ksyun + +import ( + "context" + + "github.com/hashicorp/packer-plugin-sdk/multistep" + packersdk "github.com/hashicorp/packer-plugin-sdk/packer" +) + +type StepCreateKsyunTags struct { + Tags map[string]string + + // tag resource type Values: instance, epc-host, epc-image, image, eip + ResourceType string +} + +func (s *StepCreateKsyunTags) Run(ctx context.Context, stateBag multistep.StateBag) multistep.StepAction { + ui := stateBag.Get("ui").(packersdk.Ui) + client := stateBag.Get("ksyun_client").(*ClientWrapper) + conn := client.TagsClient + targetImageId := stateBag.Get("TargetImageId").(string) + + if len(s.Tags) == 0 { + return multistep.ActionContinue + } + + ksyunTags := TagMap(s.Tags).KsyunTags() + ksyunTags.Report(ui) + + if !StringInSlice(s.ResourceType, ResourceTypeList, false) { + s.ResourceType = ResourceTypeImage + } + processTagsParams, err := ksyunTags.GetTagsParams(s.ResourceType, targetImageId) + if err != nil { + return Halt(stateBag, err, "Error processing tag") + } + _, err = conn.ReplaceResourcesTags(&processTagsParams) + if err != nil { + return Halt(stateBag, err, "Error bounding tag") + } + + return multistep.ActionContinue +} + +func (s *StepCreateKsyunTags) Cleanup(stateBag multistep.StateBag) { + // No cleanup... +} diff --git a/builder/tags.go b/builder/tags.go new file mode 100644 index 0000000..d2efb74 --- /dev/null +++ b/builder/tags.go @@ -0,0 +1,80 @@ +package ksyun + +import ( + "fmt" + "strconv" + + "github.com/KscSDK/ksc-sdk-go/service/tagv2" + packersdk "github.com/hashicorp/packer-plugin-sdk/packer" +) + +const ( + ResourceTypeKec = "instance" + ResourceTypeEip = "eip" + ResourceTypeImage = "image" + ResourceTypeBareHost = "epc-host" + ResourceTypeBareImage = "epc-image" +) + +var ResourceTypeList = []string{ResourceTypeImage, ResourceTypeKec, ResourceTypeEip} + +type TagMap map[string]string + +type Tag struct { + Id int `mapstructure:"Id"` + Key string `mapstructure:"Key"` + Value string `mapstructure:"Value"` + CreateTime string `mapstructure:"CreateTime"` + CanDelete int `mapstructure:"CanDelete"` + IsBillTag int `mapstructure:"IsBillTag"` +} + +type Tags []*Tag + +func (t Tags) Report(ui packersdk.Ui) { + for _, tag := range t { + ui.Message(fmt.Sprintf("Adding tag: \"%s\": \"%s\"", + tag.Key, tag.Value)) + } +} + +func (t TagMap) KsyunTags() Tags { + var tags = Tags{} + for k, v := range t { + tags = append(tags, &Tag{Key: k, Value: v}) + } + return tags +} + +func (t Tags) GetTagsParams(rsType, rsUuid string) (map[string]interface{}, error) { + if !StringInSlice(rsType, ResourceTypeList, false) { + return nil, fmt.Errorf("resource type is not empty, specify it") + } + if !IsUuid(rsUuid) { + return nil, fmt.Errorf("resouce uuid is invalid") + } + m := make(map[string]interface{}) + for i, tag := range t { + m["Tag_"+strconv.Itoa(i+1)+"_Key"] = tag.Key + m["Tag_"+strconv.Itoa(i+1)+"_Value"] = tag.Value + } + m["ResourceType"] = rsType + rpTagMap := map[string]interface{}{ + "ResourceUuids": rsUuid, + } + m["ReplaceTags"] = []interface{}{rpTagMap} + return m, nil +} + +func (t Tags) Pinning(rsType, rsUuid string, client *tagv2.Tagv2) error { + tagsParams, err := t.GetTagsParams(rsType, rsUuid) + if err != nil { + return err + } + + _, err = client.ReplaceResourcesTags(&tagsParams) + if err != nil { + return err + } + return nil +} diff --git a/builder/utils.go b/builder/utils.go index 17771a6..80f380a 100644 --- a/builder/utils.go +++ b/builder/utils.go @@ -2,12 +2,14 @@ package ksyun import ( "fmt" - "github.com/hashicorp/packer-plugin-sdk/communicator" - "github.com/hashicorp/packer-plugin-sdk/multistep" - packersdk "github.com/hashicorp/packer-plugin-sdk/packer" "reflect" "strconv" "strings" + + "github.com/hashicorp/go-uuid" + "github.com/hashicorp/packer-plugin-sdk/communicator" + "github.com/hashicorp/packer-plugin-sdk/multistep" + packersdk "github.com/hashicorp/packer-plugin-sdk/packer" ) type AfterStepRun func() @@ -34,10 +36,10 @@ func Halt(stateBag multistep.StateBag, err error, prefix string) multistep.StepA func GetSdkValue(stateBag multistep.StateBag, keyPattern string, obj interface{}) interface{} { keys := strings.Split(keyPattern, ".") root := obj - //log.Println(obj, 23) - //log.Println("GetSdkValue keyPattern:", keyPattern) + // log.Println(obj, 23) + // log.Println("GetSdkValue keyPattern:", keyPattern) for index, k := range keys { - //log.Println("GetSdkValue key:", k) + // log.Println("GetSdkValue key:", k) if reflect.ValueOf(root).Kind() == reflect.Map { root = root.(map[string]interface{})[k] if root == nil { @@ -84,7 +86,7 @@ func GetCidrIpMask(maskLen int) string { // ^uint32(0)二进制为32个比特1,通过向左位移,得到CIDR掩码的二进制 cidrMask := ^uint32(0) << uint(32-maskLen) fmt.Println(fmt.Sprintf("%b \n", cidrMask)) - //计算CIDR掩码的四个片段,将想要得到的片段移动到内存最低8位后,将其强转为8位整型,从而得到 + // 计算CIDR掩码的四个片段,将想要得到的片段移动到内存最低8位后,将其强转为8位整型,从而得到 cidrMaskSeg1 := uint8(cidrMask >> 24) cidrMaskSeg2 := uint8(cidrMask >> 16) cidrMaskSeg3 := uint8(cidrMask >> 8) @@ -127,3 +129,10 @@ func StringInSlice(v string, valid []string, ignoreCase bool) bool { } return false } + +func IsUuid(v string) bool { + if _, err := uuid.ParseUUID(v); err != nil { + return false + } + return true +} diff --git a/docs-partials/builder/CommonConfig-not-required.mdx b/docs-partials/builder/CommonConfig-not-required.mdx index 6aedb6f..c059d4d 100644 --- a/docs-partials/builder/CommonConfig-not-required.mdx +++ b/docs-partials/builder/CommonConfig-not-required.mdx @@ -48,4 +48,12 @@ - `project_id` (string) - Default is 0 +- `run_tags` (map[string]string) - Key/value pair tags to apply to the instance that is launched to create the image. + These tags are not applied to the resulting image. + +- `run_tag` ([]{key string, value string}) - Same as [`run_tags`](#run_tags) but defined as a singular repeatable + block containing a `key` and a `value` field. In HCL2 mode the + [`dynamic_block`](/packer/docs/templates/hcl_templates/expressions#dynamic-blocks) + will allow you to create those programatically. + diff --git a/docs-partials/builder/kec/KsyunImageConfig-not-required.mdx b/docs-partials/builder/kec/KsyunImageConfig-not-required.mdx index 58ad00d..97aee12 100644 --- a/docs-partials/builder/kec/KsyunImageConfig-not-required.mdx +++ b/docs-partials/builder/kec/KsyunImageConfig-not-required.mdx @@ -14,4 +14,11 @@ - `image_warm_up` (bool) - Set the image as warm-up for fast boot +- `tags` (map[string]string) - Key/value pair tags applied to the destination image. + +- `tag` ([]{key string, value string}) - Same as [`tags`](#tags) but defined as a singular repeatable + block containing a `key` and a `value` field. In HCL2 mode the + [`dynamic_block`](/packer/docs/templates/hcl_templates/expressions#dynamic-blocks) + will allow you to create those programatically. + diff --git a/docs/builders/epc.mdx b/docs/builders/epc.mdx index 0c712d1..9886bc9 100644 --- a/docs/builders/epc.mdx +++ b/docs/builders/epc.mdx @@ -164,6 +164,14 @@ necessary for this build to succeed and can be found further down the page. - `project_id` (string) - Default is 0 +- `run_tags` (map[string]string) - Key/value pair tags to apply to the instance that is launched to create the image. + These tags are not applied to the resulting image. + +- `run_tag` ([]{key string, value string}) - Same as [`run_tags`](#run_tags) but defined as a singular repeatable + block containing a `key` and a `value` field. In HCL2 mode the + [`dynamic_block`](/packer/docs/templates/hcl_templates/expressions#dynamic-blocks) + will allow you to create those programatically. + diff --git a/docs/builders/kec.mdx b/docs/builders/kec.mdx index 222aefb..b4956fe 100644 --- a/docs/builders/kec.mdx +++ b/docs/builders/kec.mdx @@ -171,6 +171,14 @@ necessary for this build to succeed and can be found further down the page. - `project_id` (string) - Default is 0 +- `run_tags` (map[string]string) - Key/value pair tags to apply to the instance that is launched to create the image. + These tags are not applied to the resulting image. + +- `run_tag` ([]{key string, value string}) - Same as [`run_tags`](#run_tags) but defined as a singular repeatable + block containing a `key` and a `value` field. In HCL2 mode the + [`dynamic_block`](/packer/docs/templates/hcl_templates/expressions#dynamic-blocks) + will allow you to create those programatically. + @@ -206,6 +214,13 @@ necessary for this build to succeed and can be found further down the page. - `image_warm_up` (bool) - Set the image as warm-up for fast boot +- `tags` (map[string]string) - Key/value pair tags applied to the destination image. + +- `tag` ([]{key string, value string}) - Same as [`tags`](#tags) but defined as a singular repeatable + block containing a `key` and a `value` field. In HCL2 mode the + [`dynamic_block`](/packer/docs/templates/hcl_templates/expressions#dynamic-blocks) + will allow you to create those programatically. + diff --git a/example/kec.pkr.hcl b/example/kec.pkr.hcl index 47eced8..5a3d9d8 100644 --- a/example/kec.pkr.hcl +++ b/example/kec.pkr.hcl @@ -1,7 +1,7 @@ packer { required_plugins { ksyun = { - version = ">=0.2.0" + version = ">=0.3.0" source = "github.com/kingsoftcloud/ksyun" } } @@ -21,7 +21,7 @@ source "ksyun-kec" "test" { access_key = var.ak secret_key = var.sk region = "cn-shanghai-2" - image_name = "packer_test" + image_name = "packer_tags" // 如果 source_image_id = "", 那么将会使用 source_image_filter 来过滤出 source_image_id // 同样满足直接指定source_image_id @@ -62,11 +62,22 @@ source "ksyun-kec" "test" { # 如果 source_image_id != "", 将会以source_image_id作为查询条件,并以source_image_filter进行过滤 # 若source_image_id所属镜像不满足source_image_filter条件则无法以该source_image_id进行镜像创建 source_image_filter { - platform = "centos-7.5" - name_regex = "centos-7.5.*" - image_source = "system" // import, copy, share, extend, system. + platform = "ubuntu-22.04" +# name_regex = "centos-7.5.*" + #image_source = "extend" // import, copy, share, extend, system. most_recent = true } + + # 应用于创建镜像过程中使用的资源的标签,这些标签并不应用到最终的镜像 + run_tags = { + packer_tags="run_tags" + } + + # 应用到最终创建的镜像的标签 + tags = { + packer_tags="destination_image" + } + } build { diff --git a/go.mod b/go.mod index 83af841..99969c1 100644 --- a/go.mod +++ b/go.mod @@ -4,8 +4,10 @@ go 1.19 require ( github.com/KscSDK/ksc-sdk-go v0.2.3 + github.com/hashicorp/go-uuid v1.0.2 github.com/hashicorp/hcl/v2 v2.13.0 github.com/hashicorp/packer-plugin-sdk v0.4.0 + github.com/mitchellh/mapstructure v1.4.1 github.com/zclconf/go-cty v1.10.0 ) @@ -67,7 +69,6 @@ require ( github.com/mitchellh/go-testing-interface v1.14.1 // indirect github.com/mitchellh/go-wordwrap v1.0.1 // indirect github.com/mitchellh/iochan v1.0.0 // indirect - github.com/mitchellh/mapstructure v1.4.1 // indirect github.com/mitchellh/reflectwalk v1.0.0 // indirect github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect github.com/packer-community/winrmcp v0.0.0-20180921211025-c76d91c1e7db // indirect