Skip to content
This repository has been archived by the owner on Aug 23, 2022. It is now read-only.
/ pre-commit-packer Public archive

pre-commit hooks for HashiCorp Packer

License

Notifications You must be signed in to change notification settings

ksatirli/pre-commit-packer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pre-commit-packer

Packer-specific hooks for use with pre-commit.

Table of Contents

Requirements

  • pre-commit version 1.15.0 or newer

Dependencies

  • packer for hooks that are prefixed with packer-
  • docker for hooks that are prefixed with docker-

Usage

The hooks in this repository can be used by adding the following stub to your .pre-commit-config.yaml file:

---
  -
    repo: https://github.com/operatehappy/pre-commit-packer
    rev: 1.0.0
    hooks:
      - id: packer-validate
        files: packer*.json

      - id: packer-fix
        files: packer*.json

      - id: packer-validate-and-fix
        files: packer*.json

List of Hooks

  • packer-validate wraps the validate command to parse Packer template(s) and check template configuration against any used builders, provisioners, and processors.

  • packer-fix wraps the fix command and attempts to fix (known) backwards incompatibilities in Packer template(s).

  • packer-validate-and-fix wraps the fix command and additionally validates the fixed Packer template(s).

Configuring Hooks

All hooks accept the following configuration options:

  • files accepts a string (wildcards are supported) to define which file(s) the hook should target
  • args accepts an array with one or more valid command-specific CLI arguments

The files configuration option defaults to packer.json

The args configuration option is most useful with the packer-validate action as it allows for passing additional arguments such as a path to a variables file (-var-file=packer.vars.json). The upstream documentation for the validate command provides an overview of all available options.

Using Docker

The hooks provided by pre-commit-packer support invocation through a containerized version of the Packer Docker Image.

This invocation defaults to the light tag, but is otherwise functionally identical to a direct invocation via the packer binary.

The Docker-specific hooks are prefixed with docker-:

  • packer-validate becomes docker-packer-validate
  • packer-fix becomes docker-packer-fix
  • packer-validate-and-fix becomes docker-packer-validate-and-fix

Notes

  • In the code example, the 1.0.0 version of pre-commit-packer has been selected. The Releases tab provides an overview of all available versions.

Author Information

This repository is maintained by the contributors listed on GitHub

Development of this module was sponsored by Operate Happy.

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.