Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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": {
Expand Down Expand Up @@ -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 <AK> and <SK> with your user details.
```sh
export KSYUN_ACCESS_KEY=<AK>
export KSYUN_SECRET_KEY=<SK>
```
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
Expand Down
23 changes: 23 additions & 0 deletions example/ksyun.pkr.hcl
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
22 changes: 22 additions & 0 deletions example/ksyun_epc.pkr.hcl
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
8 changes: 8 additions & 0 deletions example/require.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
packer {
required_plugins {
ksyun = {
version = "= 0.0.10"
source = "github.com/kingsoftcloud/ksyun"
}
}
}
9 changes: 9 additions & 0 deletions example/variable.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
variable "access_key" {
type = string
default = env("KSYUN_ACCESS_KEY")
}

variable "secret_key" {
type = string
default = env("KSYUN_SECRET_KEY")
}