Merge pull request #9254 from ad-m/hyperone-builder-hcl

HCL compliance for HyperOne builder
This commit is contained in:
Megan Marsh 2020-05-20 13:15:21 -07:00 committed by GitHub
commit b3ece95f27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 106 additions and 1 deletions

View File

@ -0,0 +1,32 @@
variable "token" {
type = string
}
variable "project" {
type = string
}
source "hyperone" "new-syntax" {
token = var.token
project = var.project
source_image = "debian"
disk_size = 10
vm_type = "a1.nano"
image_name = "packerbats-hcl-{{timestamp}}"
image_tags = {
key="value"
}
}
build {
sources = [
"source.hyperone.new-syntax"
]
provisioner "shell" {
inline = [
"apt-get update",
"apt-get upgrade -y"
]
}
}

View File

@ -18,7 +18,7 @@ USER_VARS="${USER_VARS} -var token=${HYPERONE_TOKEN}"
USER_VARS="${USER_VARS} -var project=${HYPERONE_PROJECT}"
hyperone_has_image() {
h1 image list --project-select=${HYPERONE_PROJECT} --query "[?tag.${2}=='${3}']" --output=tsv | grep $1 | wc -l
h1 image list --project-select=${HYPERONE_PROJECT} --query "[?tag.${2}=='${3}']" --output=tsv | grep $1 -c
}
teardown() {
@ -34,6 +34,13 @@ teardown() {
[ "$(hyperone_has_image "packerbats-minimal" "key" "value")" -eq 1 ]
}
@test "hyperone: build new-syntax.pkr.hcl" {
run packer build ${USER_VARS} $FIXTURE_ROOT/new-syntax.pkr.hcl
[ "$status" -eq 0 ]
[ "$(hyperone_has_image "packerbats-hcl" "key" "value")" -eq 1 ]
}
@test "hyperone: build chroot.json" {
run packer build ${USER_VARS} $FIXTURE_ROOT/chroot.json
[ "$status" -eq 0 ]

View File

@ -0,0 +1,29 @@
variable "token" {
type = string
}
variable "project" {
type = string
}
source "hyperone" "new-syntax" {
token = var.token
project = var.project
source_image = "debian"
disk_size = 10
vm_type = "a1.nano"
image_name = "packerbats-hcl-{{timestamp}}"
image_tags = {
key="value"
}
}
build {
sources = [
"source.hyperone.new-syntax"
]
provisioner "shell" {
inline = ["sleep 5"]
}
}

View File

@ -243,3 +243,40 @@ token.
]
}
```
## HCL Example
```hcl
variable "token" {
type = string
}
variable "project" {
type = string
}
source "hyperone" "new-syntax" {
token = var.token
project = var.project
source_image = "debian"
disk_size = 10
vm_type = "a1.nano"
image_name = "packerbats-hcl-{{timestamp}}"
image_tags = {
key="value"
}
}
build {
sources = [
"source.hyperone.new-syntax"
]
provisioner "shell" {
inline = [
"apt-get update",
"apt-get upgrade -y"
]
}
}
```