/packer-templates

Packer Templates for commonly used Providers

Primary LanguageHCLApache License 2.0Apache-2.0

Packer Templates: HashiCorp Products

Packer Templates for HashiCorp products for multiple (Cloud) Platforms

Table of Contents

Requirements

  • Packer 1.7.8 or newer
  • Terraform 1.1.3 or newer
  • Ansible 2.12.1 or newer
  • direnv 2.30.3 or newer

Ansible is used for system-level operations (e.g.: installing and removing packages).

Terraform is used as a helper, only. It is possible (though not advised) to manually create the resources needed.

Direnv is used as a helper to programmatically load environment variables.

Usage

This repository contains Packer templates for multiple providers.

The primary way of interacting with this repository is make via the included Makefile.

This allows for a consistent execution of the underlying workflows.

The currently supported options are:

PACKER TEMPLATES

help               Displays this help text
env-info           Prints Version Information
build              Builds an Image with Packer
init               Installs and upgrades Packer Plugins
lint               Formats and validates Packer Template
terraform-plan     Plans prerequisite resources with Terraform
terraform-apply    Creates prerequisite resources with Terraform
terraform-destroy  Destroys prerequisite resources with Terraform
terraform-init     Initializes Terraform

Helpers

The Makefile includes several unsupported helper targets that may be useful when developing in this repository.

target description
_clean (Forcefully) Removes the generated directory
_gen Opens the generated directory (macOS only)
_install_ansible_reqs Fetch and Install Ansible Galaxy Collections and Roles
_lint_ansible Lints Ansible Playbooks using ansible-lint
_lint_yaml Lints YAML files using yamllint
_lint Executes _lint_yaml, followed by _lint_ansible
_ssh Executes vagrant ssh
_up Executes vagrant up
_vb Opens "VirtualBox.app" (macOS only)

Unsupported targets are prefixed by an underscore (_).

Workflow

The workflow for (most) targets is as follows:

  • log in to provider's CLI interface
  • create prerequisite resources
    • initialize Terraform (using make terraform-init target=target)
    • create Terraform-managed resources (using make terraform-apply target=target)
  • create image(s)
    • initialize Packer (using make init target=target)
    • build Packer-managed image(s) (using make build target=target)
  • optionally: delete prerequisite resources
    • delete Terraform-managed resources (using make terraform-destroy target=target)

Usage differs slightly for each provider and is therefore broken out into separate sections.

See the packer/ (and terraform/) sub-directories for more information.

All workflows can be executed manually, though this is not advisable. See the Makefile for more information.

Build Options

The following generic build options are available:

debug

Disables parallelization and enables debug mode. See here for more information.

enable-envconsul

Enables transparent support for envconsul. See here for more information.

enable-inspec

Enable the InSpec Provisioner and image validation against included baselines. See here for more information.

except

Run all builds, provisioners and post-processors except those with the given comma-separated names. See here for more information.

force

Forces a builder to run when artifacts from a previous build prevent a build from running. See here for more information.

machine-readable

Enable a fully machine-readable output setting, allowing you to use Packer in automated environments. See here for more information.

only

Only run the builds with the given comma-separated names. See here for more information.

on-error

Selects what to do when the build fails during provisioning. See here for more information.

parallel-builds

Limit the number of builds to run in parallel. See here for more information.

timestamp-ui

Enable prefixing of each ui output with an RFC3339 timestamp. See here for more information.

var-file

Set template variables from a file. See here for more information.

Additional Build Options may be available, depending on the target.

Supported Providers

This repository supports the following providers:

target local documentation Packer Builder Terraform Provider
aws packer/aws/README.md amazon-ebs n/a
azure packer/azure/README.md azure-arm azurerm
google packer/google/README.md googlecompute google
vagrant packer/vagrant/README.md vagrant n/a

Notes

This repository takes input and inspiration from a handful of community projects.

The authors would like to thank the following parties for their inspiration and contributions:

envconsul

To dynamically retrieve environment variables such as provider authentication credentials and region information, envconsul may be used.

Envconsul expects configuration to be available at ./envconsul.hcl and is configured with sane defaults.

To provide connection information and credentials to (HCP) Consul and (HCP) Vault, direnv may be used. See ./.envrc.sample for a sample configuration.

Author Information

This repository is maintained by the contributors listed on GitHub.

License

Licensed under the Apache License, Version 2.0 (the "License").

You may obtain a copy of the License at apache.org/licenses/LICENSE-2.0.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" basis, without WARRANTIES or conditions of any kind, either express or implied.

See the License for the specific language governing permissions and limitations under the License.

Inputs

No inputs.

Outputs

No outputs.