Skip to content

Commit

Permalink
docs: harmonise code order for examples
Browse files Browse the repository at this point in the history
In the docs for the components of the plugin, some examples are ordered
with HCL first and JSON second, and some others invert this order.

Since HCL is now preferred, and for harmonisation puposes, we reorder
those examples to have HCL first, and JSON second.
  • Loading branch information
lbajolet-hashicorp committed Aug 29, 2023
1 parent 84b1642 commit 53bbe07
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 95 deletions.
81 changes: 40 additions & 41 deletions .web-docs/components/builder/qemu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,33 @@ necessary to run the virtual machine on KVM.
Here is a basic example. This example is functional so long as you fixup paths
to files, URLS for ISOs and checksums.

**HCL2**

```hcl
source "qemu" "example" {
iso_url = "http://mirror.raystedman.net/centos/6/isos/x86_64/CentOS-6.9-x86_64-minimal.iso"
iso_checksum = "md5:af4a1640c0c6f348c6c41f1ea9e192a2"
output_directory = "output_centos_tdhtest"
shutdown_command = "echo 'packer' | sudo -S shutdown -P now"
disk_size = "5000M"
format = "qcow2"
accelerator = "kvm"
http_directory = "path/to/httpdir"
ssh_username = "root"
ssh_password = "s0m3password"
ssh_timeout = "20m"
vm_name = "tdhtest"
net_device = "virtio-net"
disk_interface = "virtio"
boot_wait = "10s"
boot_command = ["<tab> text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/centos6-ks.cfg<enter><wait>"]
}
build {
sources = ["source.qemu.example"]
}
```

**JSON**

```json
Expand Down Expand Up @@ -45,34 +72,6 @@ to files, URLS for ISOs and checksums.
}
```

**HCL2**

```hcl
source "qemu" "example" {
iso_url = "http://mirror.raystedman.net/centos/6/isos/x86_64/CentOS-6.9-x86_64-minimal.iso"
iso_checksum = "md5:af4a1640c0c6f348c6c41f1ea9e192a2"
output_directory = "output_centos_tdhtest"
shutdown_command = "echo 'packer' | sudo -S shutdown -P now"
disk_size = "5000M"
format = "qcow2"
accelerator = "kvm"
http_directory = "path/to/httpdir"
ssh_username = "root"
ssh_password = "s0m3password"
ssh_timeout = "20m"
vm_name = "tdhtest"
net_device = "virtio-net"
disk_interface = "virtio"
boot_wait = "10s"
boot_command = ["<tab> text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/centos6-ks.cfg<enter><wait>"]
}
build {
sources = ["source.qemu.example"]
}
```


This is an example only, and will time out waiting for SSH because we have not
provided a kickstart file. You must add a valid kickstart file to the
"http_directory" and then provide the file in the "boot_command" in order for
Expand Down Expand Up @@ -284,9 +283,9 @@ necessary for this build to succeed and can be found further down the page.

The following shows a sample usage:

In JSON:
```json
"qemuargs": [
In HCL2:
```hcl
qemuargs = [
[ "-m", "1024M" ],
[ "--no-acpi", "" ],
[
Expand All @@ -299,9 +298,9 @@ necessary for this build to succeed and can be found further down the page.
]
```

In HCL2:
```hcl
qemuargs = [
In JSON:
```json
"qemuargs": [
[ "-m", "1024M" ],
[ "--no-acpi", "" ],
[
Expand Down Expand Up @@ -338,20 +337,20 @@ necessary for this build to succeed and can be found further down the page.
You can also use the `SSHHostPort` template variable to produce a packer
template that can be invoked by `make` in parallel:

In JSON:
```json
"qemuargs": [
In HCL2:
```hcl
qemuargs = [
[ "-netdev", "user,hostfwd=tcp::{{ .SSHHostPort }}-:22,id=forward"],
[ "-device", "virtio-net,netdev=forward,id=net0"]
]
```
In HCL2:
```hcl
qemuargs = [
In JSON:
```json
"qemuargs": [
[ "-netdev", "user,hostfwd=tcp::{{ .SSHHostPort }}-:22,id=forward"],
[ "-device", "virtio-net,netdev=forward,id=net0"]
]
```

`make -j 3 my-awesome-packer-templates` spawns 3 packer processes, each
of which will bind to their own SSH port as determined by each process.
Expand Down
26 changes: 13 additions & 13 deletions builder/qemu/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,9 @@ type Config struct {
//
// The following shows a sample usage:
//
// In JSON:
// ```json
// "qemuargs": [
// In HCL2:
// ```hcl
// qemuargs = [
// [ "-m", "1024M" ],
// [ "--no-acpi", "" ],
// [
Expand All @@ -417,9 +417,9 @@ type Config struct {
// ]
// ```
//
// In HCL2:
// ```hcl
// qemuargs = [
// In JSON:
// ```json
// "qemuargs": [
// [ "-m", "1024M" ],
// [ "--no-acpi", "" ],
// [
Expand Down Expand Up @@ -456,20 +456,20 @@ type Config struct {
// You can also use the `SSHHostPort` template variable to produce a packer
// template that can be invoked by `make` in parallel:
//
// In JSON:
// ```json
// "qemuargs": [
// In HCL2:
// ```hcl
// qemuargs = [
// [ "-netdev", "user,hostfwd=tcp::{{ .SSHHostPort }}-:22,id=forward"],
// [ "-device", "virtio-net,netdev=forward,id=net0"]
// ]
// ```
//
// In HCL2:
// ```hcl
// qemuargs = [
// In JSON:
// ```json
// "qemuargs": [
// [ "-netdev", "user,hostfwd=tcp::{{ .SSHHostPort }}-:22,id=forward"],
// [ "-device", "virtio-net,netdev=forward,id=net0"]
// ]
// ```
//
// `make -j 3 my-awesome-packer-templates` spawns 3 packer processes, each
// of which will bind to their own SSH port as determined by each process.
Expand Down
26 changes: 13 additions & 13 deletions docs-partials/builder/qemu/Config-not-required.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@

The following shows a sample usage:

In JSON:
```json
"qemuargs": [
In HCL2:
```hcl
qemuargs = [
[ "-m", "1024M" ],
[ "--no-acpi", "" ],
[
Expand All @@ -198,9 +198,9 @@
]
```

In HCL2:
```hcl
qemuargs = [
In JSON:
```json
"qemuargs": [
[ "-m", "1024M" ],
[ "--no-acpi", "" ],
[
Expand Down Expand Up @@ -237,20 +237,20 @@
You can also use the `SSHHostPort` template variable to produce a packer
template that can be invoked by `make` in parallel:

In JSON:
```json
"qemuargs": [
In HCL2:
```hcl
qemuargs = [
[ "-netdev", "user,hostfwd=tcp::{{ .SSHHostPort }}-:22,id=forward"],
[ "-device", "virtio-net,netdev=forward,id=net0"]
]
```

In HCL2:
```hcl
qemuargs = [
In JSON:
```json
"qemuargs": [
[ "-netdev", "user,hostfwd=tcp::{{ .SSHHostPort }}-:22,id=forward"],
[ "-device", "virtio-net,netdev=forward,id=net0"]
]
```

`make -j 3 my-awesome-packer-templates` spawns 3 packer processes, each
of which will bind to their own SSH port as determined by each process.
Expand Down
55 changes: 27 additions & 28 deletions docs/builders/qemu.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,33 @@ necessary to run the virtual machine on KVM.
Here is a basic example. This example is functional so long as you fixup paths
to files, URLS for ISOs and checksums.

**HCL2**

```hcl
source "qemu" "example" {
iso_url = "http://mirror.raystedman.net/centos/6/isos/x86_64/CentOS-6.9-x86_64-minimal.iso"
iso_checksum = "md5:af4a1640c0c6f348c6c41f1ea9e192a2"
output_directory = "output_centos_tdhtest"
shutdown_command = "echo 'packer' | sudo -S shutdown -P now"
disk_size = "5000M"
format = "qcow2"
accelerator = "kvm"
http_directory = "path/to/httpdir"
ssh_username = "root"
ssh_password = "s0m3password"
ssh_timeout = "20m"
vm_name = "tdhtest"
net_device = "virtio-net"
disk_interface = "virtio"
boot_wait = "10s"
boot_command = ["<tab> text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/centos6-ks.cfg<enter><wait>"]
}
build {
sources = ["source.qemu.example"]
}
```

**JSON**

```json
Expand Down Expand Up @@ -56,34 +83,6 @@ to files, URLS for ISOs and checksums.
}
```

**HCL2**

```hcl
source "qemu" "example" {
iso_url = "http://mirror.raystedman.net/centos/6/isos/x86_64/CentOS-6.9-x86_64-minimal.iso"
iso_checksum = "md5:af4a1640c0c6f348c6c41f1ea9e192a2"
output_directory = "output_centos_tdhtest"
shutdown_command = "echo 'packer' | sudo -S shutdown -P now"
disk_size = "5000M"
format = "qcow2"
accelerator = "kvm"
http_directory = "path/to/httpdir"
ssh_username = "root"
ssh_password = "s0m3password"
ssh_timeout = "20m"
vm_name = "tdhtest"
net_device = "virtio-net"
disk_interface = "virtio"
boot_wait = "10s"
boot_command = ["<tab> text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/centos6-ks.cfg<enter><wait>"]
}
build {
sources = ["source.qemu.example"]
}
```


This is an example only, and will time out waiting for SSH because we have not
provided a kickstart file. You must add a valid kickstart file to the
"http_directory" and then provide the file in the "boot_command" in order for
Expand Down

0 comments on commit 53bbe07

Please sign in to comment.