Packer
Kingsoft Cloud
@kingsoftcloud
The Kingsoft Cloud plugin can be used with HashiCorp Packer to create custom images on Ksyun.
- Community
Updated 10 months ago
- GitHub(opens in new tab)
Ksyun KMI
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:
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 unlessprofile
is set, but it can also be sourced from theKSYUN_ACCESS_KEY
environment variable.secret_key
(string) - Ksyun secret key must be provided unlessprofile
is set, but it can also be sourced from theKSYUN_SECRET_KEY
environment variable.region
(string) - Ksyun region must be provided unlessprofile
is set, but it can also be sourced from theKSYUN_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) - Platformimage_source
(string) - Image Source
Basic Example
Here is a basic example. It is completely valid but excludes the access keys:
Example Usage
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 = data.ksyun-kmi.foo.id
instance_type = "N3.1B"
ssh_username = "root"
}
build {
sources = ["source.ksyun-kec.test"]
}