Merge pull request #9760 from hashicorp/pipeline_with_hcl_docs

add hcl docs to pipeline build docs
This commit is contained in:
Megan Marsh 2020-08-13 07:19:14 -07:00 committed by GitHub
commit 29b08e54bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 98 additions and 2 deletions

View File

@ -30,6 +30,9 @@ this example can be applied to other builders as well.
Here is an extremely basic virtualbox-iso template:
<Tabs>
<Tab heading="JSON">
```json
{
"builders": [
@ -67,8 +70,7 @@ Here is an extremely basic virtualbox-iso template:
"type": "shell",
"inline": ["echo initial provisioning"]
}
]
},
],
"post-processors": [
{
"type": "manifest",
@ -78,6 +80,43 @@ Here is an extremely basic virtualbox-iso template:
}
```
</Tab>
<Tab heading="HCL2">
```hcl
source "virtualbox-iso" "step_1" {
boot_command = ["<esc><wait>", "<esc><wait>", "<enter><wait>",
"/install/vmlinuz<wait>", " initrd=/install/initrd.gz",
" auto-install/enable=true", " debconf/priority=critical",
" preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ubuntu_preseed.cfg<wait>",
" -- <wait>", "<enter><wait>"]
disk_size = "40960"
guest_os_type = "Ubuntu_64"
http_directory = "./http"
iso_checksum = "sha256:946a6077af6f5f95a51f82fdc44051c7aa19f9cfc5f737954845a6050543d7c2"
iso_url = "http://old-releases.ubuntu.com/releases/14.04.1/ubuntu-14.04-server-amd64.iso"
shutdown_command = "echo 'vagrant' | sudo -S shutdown -P now"
ssh_password = "vagrant"
ssh_port = 22
ssh_username = "vagrant"
vm_name = "vbox-example"
}
build {
sources = ["source.virtualbox-iso.step_1"]
provisioner "shell" {
inline = ["echo initial provisioning"]
}
post-processor "manifest" {
output = "stage-1-manifest.json"
}
}
```
</Tab>
</Tabs>
In order to build using this template, create a directory named "http" in your
current working directory. Copy the minimal example from our
[preseed guide](https://www.packer.io/guides/automatic-operating-system-installs/preseed_ubuntu#examples)
@ -101,6 +140,9 @@ That output filename generated in the first stage can be used as the
[source_path](https://www.packer.io/docs/builders/virtualbox/ovf#source_path)
for the virtualbox-ovf builder.
<Tabs>
<Tab heading="JSON">
```json
{
"builders": [
@ -125,6 +167,32 @@ for the virtualbox-ovf builder.
}
```
</Tab>
<Tab heading="HCL2">
```hcl
source "virtualbox-ovf" "step_2" {
shutdown_command = "echo 'vagrant' | sudo -S shutdown -P now"
source_path = "output-virtualbox-iso/vbox-example.ovf"
ssh_password = "vagrant"
ssh_port = 22
ssh_username = "vagrant"
vm_name = "virtualbox-example-ovf"
}
build {
sources = ["source.virtualbox-ovf.step_2"]
provisioner "shell" {
inline = ["echo secondary provisioning"]
}
}
```
</Tab>
</Tabs>
## More efficiencies
You may find that you want to run time-consuming import post-processors like
@ -137,6 +205,9 @@ the behavior you want. The below example shows a "vagrant" post-processor
being used with a null builder, and manually sets the artifact from our
stage-2 ovf build:
<Tabs>
<Tab heading="JSON">
```json
{
"builders": [
@ -163,6 +234,31 @@ stage-2 ovf build:
}
```
</Tab>
<Tab heading="HCL2">
```hcl
source "null" "step_3" {
communicator = "none"
}
build {
sources = ["source.null.step_3"]
post-processors {
post-processor "artifice" {
files = ["output-virtualbox-ovf/virtualbox-example-ovf.ovf", "output-virtualbox-ovf/virtualbox-example-ovf-disk001.vmdk"]
}
post-processor "vagrant" {
provider_override = "virtualbox"
}
}
}
```
</Tab>
</Tabs>
By using the null builder instead of just running an ovf builder, we can spare ourselves all of the time Packer would normally spend launching and destroying VMs.
## Putting it all together