update components docs

This commit is contained in:
sylviamoss 2021-02-16 14:31:05 +01:00
parent 715fe51517
commit 6e195f92e8
6 changed files with 144 additions and 117 deletions

View File

@ -116,7 +116,7 @@ Usage:
$ export AWS_ACCESS_KEY_ID="anaccesskey"
$ export AWS_SECRET_ACCESS_KEY="asecretkey"
$ export AWS_DEFAULT_REGION="us-west-2"
$ packer build packer.json
$ packer build template.pkr.hcl
### Shared Credentials file

View File

@ -155,7 +155,7 @@ This builder requires privileged actions, such as mounting disks, running
permissions, for example:
```shell-session
$ sudo -E packer build example.json
$ sudo -E packer build example.pkr.json
```
### Using a VM with a Managed Identity
@ -164,6 +164,30 @@ On a VM with a system-assigned managed identity that has the contributor role
on its own resource group, the following config can be used to create an
updated Debian image:
<Tabs>
<Tab heading="HCL2">
```hcl
source "azure-chroot" "example" {
image_resource_id = "/subscriptions/{{vm `subscription_id`}}/resourceGroups/{{vm `resource_group`}}/providers/Microsoft.Compute/images/MyDebianOSImage-{{timestamp}}"
source = "credativ:Debian:9:latest"
}
build {
sources = ["source.azure-chroot.example"]
provisioner "shell" {
inline = ["apt-get update", "apt-get upgrade -y"]
inline_shebang = "/bin/sh -x"
}
}
```
</Tab>
<Tab heading="JSON">
```json
{
"builders": [
@ -184,6 +208,9 @@ updated Debian image:
}
```
</Tab>
</Tabs>
### Using a Service Principal
Here is an example that creates a Debian image with updated packages. Specify
@ -195,40 +222,6 @@ Set the `ARM_IMAGE_RESOURCEGROUP_ID` variable to an existing resource group in t
subscription where the resulting image will be created.
<Tabs>
<Tab heading="JSON">
```json
{
"variables": {
"client_id": "{{env `ARM_CLIENT_ID`}}",
"client_secret": "{{env `ARM_CLIENT_SECRET`}}",
"subscription_id": "{{env `ARM_SUBSCRIPTION_ID`}}",
"resource_group": "{{env `ARM_IMAGE_RESOURCEGROUP_ID`}}"
},
"builders": [
{
"type": "azure-chroot",
"client_id": "{{user `client_id`}}",
"client_secret": "{{user `client_secret`}}",
"subscription_id": "{{user `subscription_id`}}",
"image_resource_id": "/subscriptions/{{user `subscription_id`}}/resourceGroups/{{user `resource_group`}}/providers/Microsoft.Compute/images/MyDebianOSImage-{{timestamp}}",
"source": "credativ:Debian:9:latest"
}
],
"provisioners": [
{
"inline": ["apt-get update", "apt-get upgrade -y"],
"inline_shebang": "/bin/sh -x",
"type": "shell"
}
]
}
```
</Tab>
<Tab heading="HCL2">
```hcl
@ -265,5 +258,39 @@ build {
}
```
</Tab>
<Tab heading="JSON">
```json
{
"variables": {
"client_id": "{{env `ARM_CLIENT_ID`}}",
"client_secret": "{{env `ARM_CLIENT_SECRET`}}",
"subscription_id": "{{env `ARM_SUBSCRIPTION_ID`}}",
"resource_group": "{{env `ARM_IMAGE_RESOURCEGROUP_ID`}}"
},
"builders": [
{
"type": "azure-chroot",
"client_id": "{{user `client_id`}}",
"client_secret": "{{user `client_secret`}}",
"subscription_id": "{{user `subscription_id`}}",
"image_resource_id": "/subscriptions/{{user `subscription_id`}}/resourceGroups/{{user `resource_group`}}/providers/Microsoft.Compute/images/MyDebianOSImage-{{timestamp}}",
"source": "credativ:Debian:9:latest"
}
],
"provisioners": [
{
"inline": ["apt-get update", "apt-get upgrade -y"],
"inline_shebang": "/bin/sh -x",
"type": "shell"
}
]
}
```
</Tab>
</Tabs>

View File

@ -75,7 +75,7 @@ Usage:
$ export OUTSCALE_ACCESSKEYID="anaccesskey"
$ export OUTSCALE_SECRETKEYID="asecretkey"
$ export OUTSCALE_REGION="eu-west-2"
$ packer build packer.json
$ packer build template.pkr.hcl
### x509 Certificate Authentication

View File

@ -19,7 +19,7 @@ outputted.
Example usage:
```shell-session
$ packer validate my-template.json
$ packer validate my-template.pkr.hcl
Template validation failed. Errors are shown below.
Errors validating build 'vmware'. 1 error(s) occurred:

View File

@ -49,6 +49,18 @@ compressed raw disk image artifact for us to work with, and that the GCS bucket
has been created.
<Tabs>
<Tab heading="HCL">
```hcl
post-processor "googlecompute-import"{
account_file = "account.json"
bucket = "my-bucket"
project_id = "my-project"
image_name = "my-gce-image"
}
```
</Tab>
<Tab heading="JSON">
```json
@ -61,19 +73,6 @@ has been created.
}
```
</Tab>
<Tab heading="HCL">
```hcl
post-processor "googlecompute-import"{
account_file = "account.json"
bucket = "my-bucket"
project_id = "my-project"
image_name = "my-gce-image"
}
```
</Tab>
</Tabs>
@ -82,72 +81,10 @@ post-processor "googlecompute-import"{
Here is a complete example for building a Fedora 31 server GCE image. For this
example Packer was run from a Debian Linux host with KVM installed.
$ packer build -var serial=$(tty) build.json
$ packer build -var serial=$(tty) build.pkr.hcl
<Tabs>
<Tab heading="JSON">
```json
{
"variables": {
"account_file": "account.json",
"bucket": "my-bucket",
"project": "my-project",
"serial": ""
},
"builders": [
{
"type": "qemu",
"accelerator": "kvm",
"boot_command": [
"<tab> console=ttyS0,115200n8 inst.text inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/fedora-31-ks.cfg rd.live.check=0<enter><wait>"
],
"disk_size": "15000",
"format": "raw",
"iso_checksum": "sha256:225ebc160e40bb43c5de28bad9680e3a78a9db40c9e3f4f42f3ee3f10f95dbeb",
"iso_url": "https://download-ib01.fedoraproject.org/pub/fedora/linux/releases/31/Server/x86_64/iso/Fedora-Server-dvd-x86_64-31-1.9.iso",
"headless": "true",
"http_directory": "http",
"http_port_max": "10089",
"http_port_min": "10082",
"output_directory": "output",
"shutdown_timeout": "30m",
"shutdown_command": "echo 'vagrant'|sudo -S shutdown -P now",
"ssh_username": "vagrant",
"ssh_password": "vagrant",
"vm_name": "disk.raw",
"qemu_binary": "/usr/bin/kvm",
"qemuargs": [
["-m", "1024"],
["-cpu", "host"],
["-chardev", "tty,id=pts,path={{user `serial`}}"],
["-device", "isa-serial,chardev=pts"],
["-device", "virtio-net,netdev=user.0"]
]
}
],
"post-processors": [
[
{
"type": "compress",
"output": "output/disk.raw.tar.gz"
},
{
"type": "googlecompute-import",
"project_id": "{{user `project`}}",
"account_file": "{{user `account_file`}}",
"bucket": "{{user `bucket`}}",
"image_name": "fedora31-server-packertest",
"image_description": "Fedora 31 Server",
"image_family": "fedora31-server"
}
]
]
}
```
</Tab>
<Tab heading="HCL">
<Tab heading="HCL2">
```hcl
variables {
@ -205,5 +142,67 @@ build {
}
```
</Tab>
<Tab heading="JSON">
```json
{
"variables": {
"account_file": "account.json",
"bucket": "my-bucket",
"project": "my-project",
"serial": ""
},
"builders": [
{
"type": "qemu",
"accelerator": "kvm",
"boot_command": [
"<tab> console=ttyS0,115200n8 inst.text inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/fedora-31-ks.cfg rd.live.check=0<enter><wait>"
],
"disk_size": "15000",
"format": "raw",
"iso_checksum": "sha256:225ebc160e40bb43c5de28bad9680e3a78a9db40c9e3f4f42f3ee3f10f95dbeb",
"iso_url": "https://download-ib01.fedoraproject.org/pub/fedora/linux/releases/31/Server/x86_64/iso/Fedora-Server-dvd-x86_64-31-1.9.iso",
"headless": "true",
"http_directory": "http",
"http_port_max": "10089",
"http_port_min": "10082",
"output_directory": "output",
"shutdown_timeout": "30m",
"shutdown_command": "echo 'vagrant'|sudo -S shutdown -P now",
"ssh_username": "vagrant",
"ssh_password": "vagrant",
"vm_name": "disk.raw",
"qemu_binary": "/usr/bin/kvm",
"qemuargs": [
["-m", "1024"],
["-cpu", "host"],
["-chardev", "tty,id=pts,path={{user `serial`}}"],
["-device", "isa-serial,chardev=pts"],
["-device", "virtio-net,netdev=user.0"]
]
}
],
"post-processors": [
[
{
"type": "compress",
"output": "output/disk.raw.tar.gz"
},
{
"type": "googlecompute-import",
"project_id": "{{user `project`}}",
"account_file": "{{user `account_file`}}",
"bucket": "{{user `bucket`}}",
"image_name": "fedora31-server-packertest",
"image_description": "Fedora 31 Server",
"image_family": "fedora31-server"
}
]
]
}
```
</Tab>
</Tabs>

View File

@ -11,9 +11,10 @@ description: |-
-> **Note:** Packer supports HCL2 from version 1.6.0, the Hashicorp Configuration
Language allows to comment directly in template files. Consider upgrading your
json template to hcl2 using the `packer hcl2_upgrade` command.
JSON template to HCL2 using the `packer hcl2_upgrade` command.
One of the biggest complaints we get about packer is that json doesn't use comments. We're in the process of moving to HCL2, the same config language used by Terraform, which does allow comments. But in the meantime, you can add detailed comments beyond the root-level underscore-prefixed field supported by Packer, and remove them using jq.
One of the biggest complaints we get about Packer is that JSON doesn't use comments.
For Packer JSON templates, you can add detailed comments beyond the root-level underscore-prefixed field supported by Packer, and remove them using jq.
Let's say we have a file named `commented_template.json`