Merge pull request #9431 from hashicorp/azr-docs-add-hcl2-basic-examples

add hcl2 basic examples under tabs
This commit is contained in:
Megan Marsh 2020-06-16 09:43:19 -07:00 committed by GitHub
commit 84b71c221c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 510 additions and 4 deletions

View File

@ -49,6 +49,9 @@ builder.
Here is a basic example for Alicloud.
<Tabs>
<Tab heading="JSON">
```json
{
"variables": {
@ -79,6 +82,45 @@ Here is a basic example for Alicloud.
}
```
</Tab>
<Tab heading="HCL2">
```hcl
variable "access_key" {
type = string
}
variable "secret_key" {
type = string
}
source "alicloud-ecs" "basic-example" {
access_key = var.access_key
secret_key = var.secret_key
region = "cn-beijing"
image_name = "packer_test2"
source_image = "centos_7_04_64_20G_alibase_201701015.vhd"
ssh_username = "root"
instance_type = "ecs.n1.tiny"
io_optimized = true
internet_charge_type = "PayByTraffic"
image_force_delete = true
}
build {
sources = ["sources.alicloud-ecs.basic-example"]
provisioner "shell" {
inline = [
"sleep 30", "yum install redis.x86_64 -y",
]
}
}
```
</Tab>
</Tabs>
~> Note: Images can become deprecated after a while; run
`aliyun ecs DescribeImages` to find one that exists.

View File

@ -110,6 +110,9 @@ Block devices can be nested in the
Here is a basic example. It is completely valid except for the access keys:
<Tabs>
<Tab heading="JSON">
```json
{
"type": "amazon-chroot",
@ -120,6 +123,34 @@ Here is a basic example. It is completely valid except for the access keys:
}
```
</Tab>
<Tab heading="HCL2">
```hcl
variable "aws_access_key" {
type = string
}
variable "aws_secret_key" {
type = string
}
source "amazon-chroot" "basic-example" {
access_key = var.aws_access_key
secret_key = var.aws_secret_key
source_ami = "ami-e81d5881"
}
build {
source "sources.amazon-chroot.basic-example" {
ami_name = "packer-amazon-chroot {{timestamp}}"
}
}
```
</Tab>
</Tabs>
## Chroot Mounts
The `chroot_mounts` configuration can be used to mount specific devices within

View File

@ -107,6 +107,9 @@ Here is a basic example. You will need to provide access keys, and may need to
change the AMI IDs according to what images exist at the time the template is
run:
<Tabs>
<Tab heading="JSON">
```json
{
"variables": {
@ -128,6 +131,37 @@ run:
}
```
</Tab>
<Tab heading="HCL2">
```hcl
variable "aws_access_key" {
type = string
}
variable "aws_secret_key" {
type = string
}
source "amazon-ebs" "basic-example" {
access_key = var.aws_access_key
secret_key = var.aws_secret_key
region = "us-east-1"
source_ami = "ami-fce3c696"
instance_type = "t2.micro"
ssh_username = "ubuntu"
}
build {
source "sources.amazon-ebs.basic-example" {
ami_name = "packer_AWS {{timestamp}}"
}
}
```
</Tab>
</Tabs>
-> **Note:** Packer can also read the access key and secret access key from
environmental variables. See the configuration reference in the section above
for more information on what environmental variables Packer will look for.

View File

@ -102,6 +102,10 @@ Block devices can be nested in the
## Basic Example
<Tabs>
<Tab heading="JSON">
```json
{
"type": "amazon-ebssurrogate",
@ -129,6 +133,46 @@ Block devices can be nested in the
}
```
</Tab>
<Tab heading="HCL2">
```hcl
source "amazon-ebssurrogate" "basic-example" {
region = "us-east-1"
ssh_username = "ubuntu"
instance_type = "t2.medium"
source_ami = "ami-40d28157"
ami_name = "packer-test-adrien"
ami_virtualization_type = "paravirtual"
launch_block_device_mappings {
volume_type = "gp2"
device_name = "/dev/xvdf"
delete_on_termination = false
volume_size = 10
}
ami_root_device {
source_device_name = "/dev/xvdf"
device_name = "/dev/xvda"
delete_on_termination = true
volume_size = 16
volume_type = "gp2"
}
}
build {
sources = ["sources.amazon-ebssurrogate.basic-example"]
provisioner "shell" {
inline = ["..."]
}
}
```
</Tab>
</Tabs>
-> **Note:** Packer can also read the access key and secret access key from
environmental variables. See the configuration reference in the section above
for more information on what environmental variables Packer will look for.

View File

@ -106,11 +106,12 @@ Block devices can be nested in the
## Basic Example
<Tabs>
<Tab heading="JSON">
```json
{
"type": "amazon-ebsvolume",
"secret_key": "YOUR SECRET KEY HERE",
"access_key": "YOUR KEY HERE",
"region": "us-east-1",
"ssh_username": "ubuntu",
"instance_type": "t2.medium",
@ -150,6 +151,58 @@ Block devices can be nested in the
}
```
</Tab>
<Tab heading="HCL2">
```hcl
source "amazon-ebsvolume" "basic-example" {
region = "us-east-1"
ssh_username = "ubuntu"
instance_type = "t2.medium"
source_ami = "ami-40d28157"
ebs_volumes {
volume_type = "gp2"
device_name = "/dev/xvdf"
delete_on_termination = false
tags = {
zpool = "data"
Name = "Data1"
}
volume_size = 10
}
ebs_volumes {
volume_type = "gp2"
device_name = "/dev/xvdg"
tags = {
zpool = "data"
Name = "Data2"
}
delete_on_termination = false
volume_size = 10
}
ebs_volumes {
volume_size = 10
tags = {
zpool = "data"
Name = "Data3"
}
delete_on_termination = false
device_name = "/dev/xvdh"
volume_type = "gp2"
}
}
build {
sources = ["sources.amazon-ebsvolume.basic-example"]
}
```
</Tab>
</Tabs>
-> **Note:** Packer can also read the access key and secret access key from
environmental variables. See the configuration reference in the section above
for more information on what environmental variables Packer will look for.

View File

@ -121,6 +121,9 @@ Block devices can be nested in the
Here is a basic example. It is completely valid except for the access keys:
<Tabs>
<Tab heading="JSON">
```json
{
"type": "amazon-instance",
@ -141,6 +144,33 @@ Here is a basic example. It is completely valid except for the access keys:
}
```
</Tab>
<Tab heading="HCL2">
```hcl
source "amazon-instance" "basic-example" {
region = "us-east-1"
source_ami = "ami-d9d6a6b0"
instance_type = "m1.small"
ssh_username = "ubuntu"
account_id = "0123-4567-0890"
s3_bucket = "packer-images"
x509_cert_path = "x509.cert"
x509_key_path = "x509.key"
x509_upload_path = "/tmp"
}
build {
source "sources.amazon-instance.basic-example" {
ami_name = "packer-quick-start {{timestamp}}"
}
}
```
</Tab>
</Tabs>
-> **Note:** Packer can also read the access key and secret access key from
environmental variables. See the configuration reference in the section above
for more information on what environmental variables Packer will look for.

View File

@ -165,6 +165,9 @@ Providing `temp_resource_group_name` or `location` in combination with
Here is a basic example for Azure.
<Tabs>
<Tab heading="JSON">
```json
{
"type": "azure-arm",
@ -193,6 +196,42 @@ Here is a basic example for Azure.
}
```
</Tab>
<Tab heading="HCL2">
```hcl
source "azure-arm" "basic-example" {
client_id = "fe354398-d7sf-4dc9-87fd-c432cd8a7e09"
client_secret = "keepitsecret&#*$"
resource_group_name = "packerdemo"
storage_account = "virtualmachines"
subscription_id = "44cae533-4247-4093-42cf-897ded6e7823"
tenant_id = "de39842a-caba-497e-a798-7896aea43218"
capture_container_name = "images"
capture_name_prefix = "packer"
os_type = "Linux"
image_publisher = "Canonical"
image_offer = "UbuntuServer"
image_sku = "14.04.4-LTS"
azure_tags = {
dept = "engineering"
}
location = "West US"
vm_size = "Standard_A2"
}
build {
sources = ["sources.azure-arm.basic-example"]
}
```
</Tab>
</Tabs>
## Deprovision
Azure VMs should be deprovisioned at the end of every build. For Windows this

View File

@ -194,6 +194,9 @@ to update your VM.
Set the `ARM_IMAGE_RESOURCEGROUP_ID` variable to an existing resource group in the
subscription where the resulting image will be created.
<Tabs>
<Tab heading="JSON">
```json
{
"variables": {
@ -224,3 +227,43 @@ subscription where the resulting image will be created.
]
}
```
</Tab>
<Tab heading="HCL2">
```hcl
variable "client_id" {
type = string
}
variable "client_secret" {
type = string
}
variable "subscription_id" {
type = string
}
variable "resource_group" {
type = string
}
source "azure-chroot" "basic-example" {
client_id = var.client_id
client_secret = var.client_secret
subscription_id = var.subscription_id
image_resource_id = "/subscriptions/${var.subscription_id}/resourceGroups/${var.resource_group}/providers/Microsoft.Compute/images/MyDebianOSImage-{{timestamp}}"
source = "credativ:Debian:9:latest"
}
build {
sources = ["sources.azure-chroot.basic-example"]
provisioner "shell" {
inline = ["apt-get update", "apt-get upgrade -y"]
inline_shebang = "/bin/sh -x"
}
}
```
</Tab>
</Tabs>

View File

@ -21,6 +21,9 @@ wait times.
Below is a fully functioning example. It create a file at `target` with the
specified `content`.
<Tabs>
<Tab heading="JSON">
```json
{
"type": "file",
@ -29,6 +32,24 @@ specified `content`.
}
```
</Tab>
<Tab heading="HCL2">
```hcl
source "file" "basic-example" {
content = "Lorem ipsum dolor sit amet"
target = "dummy_artifact"
}
build {
sources = ["sources.file.basic-example"]
}
```
</Tab>
</Tabs>
## Configuration Reference
Configuration options are organized below into two categories: required and

View File

@ -119,6 +119,9 @@ repackage an existing GCE image. The account_file is obtained in the previous
section. If it parses as JSON it is assumed to be the file itself, otherwise,
it is assumed to be the path to the file containing the JSON.
<Tabs>
<Tab heading="JSON">
```json
{
"builders": [
@ -134,6 +137,26 @@ it is assumed to be the path to the file containing the JSON.
}
```
</Tab>
<Tab heading="HCL2">
```hcl
source "googlecompute" "basic-example" {
account_file = "account.json"
project_id = "my project"
source_image = "debian-7-wheezy-v20150127"
ssh_username = "packer"
zone = "us-central1-a"
}
build {
sources = ["sources.googlecompute.basic-example"]
}
```
</Tab>
</Tabs>
### Windows Example
Before you can provision using the winrm communicator, you need to allow

View File

@ -23,6 +23,9 @@ artifact.
Below is a fully functioning example. It doesn't do anything useful, since no
provisioners are defined, but it will connect to the specified host via ssh.
<Tabs>
<Tab heading="JSON">
```json
{
"type": "null",
@ -32,6 +35,25 @@ provisioners are defined, but it will connect to the specified host via ssh.
}
```
</Tab>
<Tab heading="HCL2">
```hcl
source "null" "basic-example" {
ssh_host = "127.0.0.1"
ssh_username = "foo"
ssh_password = "bar"
}
build {
sources = ["sources.null.basic-example"]
}
```
</Tab>
</Tabs>
## Configuration Reference
The null builder has no configuration parameters other than the

View File

@ -28,6 +28,9 @@ Here is a basic example. This example is not functional. It will start the OS
installer but then fail because we don't provide the preseed file for Ubuntu to
self-install. Still, the example serves to show the basic configuration:
<Tabs>
<Tab heading="JSON">
```json
{
"type": "virtualbox-iso",
@ -41,6 +44,29 @@ self-install. Still, the example serves to show the basic configuration:
}
```
</Tab>
<Tab heading="HCL2">
```hcl
source "virtualbox-iso" "basic-example" {
guest_os_type = "Ubuntu_64"
iso_url = "http://releases.ubuntu.com/12.04/ubuntu-12.04.5-server-amd64.iso"
iso_checksum = "769474248a3897f4865817446f9a4a53"
iso_checksum_type = "md5"
ssh_username = "packer"
ssh_password = "packer"
shutdown_command = "echo 'packer' | sudo -S shutdown -P now"
}
build {
sources = ["sources.virtualbox-iso.basic-example"]
}
```
</Tab>
</Tabs>
It is important to add a `shutdown_command`. By default Packer halts the virtual
machine and the file system may not be sync'd. Thus, changes made in a
provisioner might not be saved.

View File

@ -40,6 +40,9 @@ build.
Here is a basic example. This example is functional if you have an OVF matching
the settings here.
<Tabs>
<Tab heading="JSON">
```json
{
"type": "virtualbox-ovf",
@ -50,6 +53,25 @@ the settings here.
}
```
</Tab>
<Tab heading="HCL2">
```hcl
source "virtualbox-ovf" "basic-example" {
source_path = "source.ovf"
ssh_username = "packer"
ssh_password = "packer"
shutdown_command = "echo 'packer' | sudo -S shutdown -P now"
}
build {
sources = ["sources.virtualbox-ovf.basic-example"]
}
```
</Tab>
</Tabs>
It is important to add a `shutdown_command`. By default Packer halts the virtual
machine and the file system may not be sync'd. Thus, changes made in a
provisioner might not be saved.

View File

@ -29,6 +29,9 @@ from the applied provisioners.
Here is a basic example. which serves to show the basic configuration:
<Tabs>
<Tab heading="JSON">
```json
{
"type": "virtualbox-vm",
@ -49,6 +52,35 @@ Here is a basic example. which serves to show the basic configuration:
}
```
</Tab>
<Tab heading="HCL2">
```hcl
source "virtualbox-vm" "basic-example" {
communicator = "winrm"
headless = "{{user `headless`}}"
winrm_username = "vagrant"
winrm_password = "vagrant"
winrm_timeout = "2h"
shutdown_command = "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\""
guest_additions_mode = "disable"
output_directory = "./builds-vm"
vm_name = "target-vm"
attach_snapshot = "Snapshot"
target_snapshot = "Target-Snapshot"
force_delete_snapshot = true
keep_registered = false
skip_export = false
}
build {
sources = ["sources.virtualbox-vm.basic-example"]
}
```
</Tab>
</Tabs>
It is important to add a `shutdown_command`. By default Packer halts the virtual
machine and the file system may not be sync'd. Thus, changes made in a
provisioner might not be saved.

View File

@ -37,18 +37,40 @@ Here is a basic example. This example is not functional. It will start the OS
installer but then fail because we don't provide the preseed file for Ubuntu to
self-install. Still, the example serves to show the basic configuration:
<Tabs>
<Tab heading="JSON">
```json
{
"type": "vmware-iso",
"iso_url": "http://old-releases.ubuntu.com/releases/precise/ubuntu-12.04.2-server-amd64.iso",
"iso_checksum": "af5f788aee1b32c4b2634734309cc9e9",
"iso_checksum_type": "md5",
"iso_checksum": "md5:af5f788aee1b32c4b2634734309cc9e9",
"ssh_username": "packer",
"ssh_password": "packer",
"shutdown_command": "shutdown -P now"
}
```
</Tab>
<Tab heading="HCL2">
```hcl
source "vmware-iso" "basic-example" {
iso_url = "http://old-releases.ubuntu.com/releases/precise/ubuntu-12.04.2-server-amd64.iso"
iso_checksum = "md5:af5f788aee1b32c4b2634734309cc9e9"
ssh_username = "packer"
ssh_password = "packer"
shutdown_command = "shutdown -P now"
}
build {
sources = ["sources.vmware-iso.basic-example"]
}
```
</Tab>
</Tabs>
## VMware-ISO Builder Configuration Reference
There are many configuration options available for the builder. In addition to

View File

@ -34,6 +34,9 @@ VMware virtual machine.
Here is an example. This example is fully functional as long as the source path
points to a real VMX file with the proper settings:
<Tabs>
<Tab heading="JSON">
```json
{
"type": "vmware-vmx",
@ -44,6 +47,25 @@ points to a real VMX file with the proper settings:
}
```
</Tab>
<Tab heading="HCL2">
```hcl
source "vmware-vmx" "basic-example" {
source_path = "/path/to/a/vm.vmx"
ssh_username = "root"
ssh_password = "root"
shutdown_command = "shutdown -P now"
}
build {
sources = ["sources.vmware-vmx.basic-example"]
}
```
</Tab>
</Tabs>
## Configuration Reference
There are many configuration options available for the VMware builder. They are