diff --git a/README.md b/README.md index 54270a2..dd60536 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ packer { ## Usage for Kec Here is a sample template, which you can also find in the `example/` directory +### JSON Template ```json { "variables": { @@ -71,9 +72,45 @@ Here is a sample template, which you can also find in the `example/` directory ] }] } +``` +### HCL Template + +```hcl +variable "access_key" { + type = string + default = env("KSYUN_ACCESS_KEY") +} + +variable "secret_key" { + type = string + default = env("KSYUN_SECRET_KEY") +} + +source "ksyun-kec" "example" { + access_key = var.access_key + secret_key = var.secret_key + region = "cn-shanghai-2" + image_name = "packer_test" + source_image_id = "IMG-dd1f8324-1f27-46e0-ad6b-b41d8c8ff025" + instance_type = "N3.1B" + ssh_username = "root" + associate_public_ip_address = true +} +build { + provisioner "shell" { + inline = [ + "sleep 30", + "yum install mysql -y" + ] + } +} + ``` ## Usage for Bare Metal Here is a sample template, which you can also find in the `example/` directory + +### JSON Template + ```json { "variables": { @@ -103,12 +140,61 @@ Here is a sample template, which you can also find in the `example/` directory } ``` + +### HCL Template + +```hcl +variable "access_key" { + type = string + default = env("KSYUN_ACCESS_KEY") +} + +variable "secret_key" { + type = string + default = env("KSYUN_SECRET_KEY") +} +source "ksyun-kec" "example" { + access_key = var.access_key + secret_key = var.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 +} +build { + provisioner "shell" { + inline = [ + "sleep 30", + "yum install mysql -y" + ] + } +} + +``` + Enter the API user credentials in your terminal with the following commands. Replace the and with your user details. ```sh export KSYUN_ACCESS_KEY= export KSYUN_SECRET_KEY= ``` Then run Packer using the example template with the command underneath. + +### HTL Template + +``` +# install packer plugin +packer init . +# use for kec +packer build -only="ksyun.*" . +# use for bare metal +packer build -only="ksyun_epc.*" . +``` + +### JSON Template ``` # use for kec packer build example/ksyun.json diff --git a/example/ksyun.pkr.hcl b/example/ksyun.pkr.hcl new file mode 100644 index 0000000..20e91a4 --- /dev/null +++ b/example/ksyun.pkr.hcl @@ -0,0 +1,23 @@ +source "ksyun-kec" "example" { + access_key = var.access_key + secret_key = var.secret_key + region = "cn-beijing-6" + availability_zone = "cn-beijing-6a" + instance_charge_type = "HourlyInstantSettlement" + image_name = "packer_test" + source_image_id = "IMG-dd1f8324-1f27-46e0-ad6b-b41d8c8ff025" + instance_type = "C4.2B" + ssh_username = "root" + associate_public_ip_address = true + public_ip_charge_type = "DailyPaidByTransfer" +} +build { + name = "ksyun" + sources = ["source.ksyun-kec.example"] + provisioner "shell" { + inline = [ + "sleep 30", + "yum install mysql -y" + ] + } +} diff --git a/example/ksyun_epc.pkr.hcl b/example/ksyun_epc.pkr.hcl new file mode 100644 index 0000000..5e1b7af --- /dev/null +++ b/example/ksyun_epc.pkr.hcl @@ -0,0 +1,22 @@ +source "ksyun-kec" "example_epc" { + access_key = var.access_key + secret_key = var.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 +} +build { + name = "ksyun_epc" + sources = ["source.ksyun-kec.example_epc"] + provisioner "shell" { + inline = [ + "sleep 30", + "yum install mysql -y" + ] + } +} diff --git a/example/require.pkr.hcl b/example/require.pkr.hcl new file mode 100644 index 0000000..6837921 --- /dev/null +++ b/example/require.pkr.hcl @@ -0,0 +1,8 @@ +packer { + required_plugins { + ksyun = { + version = "= 0.0.10" + source = "github.com/kingsoftcloud/ksyun" + } + } +} diff --git a/example/variable.pkr.hcl b/example/variable.pkr.hcl new file mode 100644 index 0000000..fa7d683 --- /dev/null +++ b/example/variable.pkr.hcl @@ -0,0 +1,9 @@ +variable "access_key" { + type = string + default = env("KSYUN_ACCESS_KEY") +} + +variable "secret_key" { + type = string + default = env("KSYUN_SECRET_KEY") +}