cisagov / cisagov/pre-commit-packer
Make pushd in packer_validate hook optional
- Dominant language
- Shell
- Stars
- 21
- Forks
- 16
- PR merge metrics
- No merged PRs in 30d
Description
# π Summary #
Since https://github.com/cisagov/pre-commit-packer/pull/47, the current working directory is changed to the location of each HCL template.
This breaks setups where HCL templates are in subdirectories and relatively include ansible playbooks, e.g.:
```
.
βββ Makefile
βββ ansible
β βββ ansible.cfg
β βββ group_vars
β β βββ all.yml
β βββ playbook.yml
β βββ requirements.yml
βββ packer
β βββ main.pkr.hcl
βββ renovate.json
βββ requirements.txt
```
With `packer/main.pkr.hcl` containing:
```hcl
build {
provisioner "ansible" {
playbook_file = "./ansible/playbook.yml"
}
}
```
And `.pre-commit-config.yaml`:
```
repos:
- repo: https://github.com/cisagov/pre-commit-packer
rev: v0.3.0
hooks:
- id: packer_validate
- id: packer_fmt
```
As I understand the motivation behind the change, e.g. for monorepos containing multiple independent packer templates, it would be awesome to make this configurable.
## To reproduce ##
Steps to reproduce the behavior:
1. Create the above setup
1. Then run `pre-commit run --all-files packer_validate`
## Expected behavior ##
Hook should pass, just like a normal invocation:
```sh
# packer validate packer/main.pkr.hcl
The configuration is valid.
```
## Any helpful log output or screenshots ##
Paste the results here:
```console
# pre-commit run --all-files packer_validate
Packer Validate..........................................................Failed
- hook id: packer_validate
- exit code: 1
Error: Failed preparing provisioner-block "ansible" ""
on main.pkr.hcl line 84:
(source code not available)
1 error(s) occurred:
* playbook_file: ./ansible/playbook.yml is invalid: stat ./ansible/playbook.yml:
no such file or directory
Failed path: packer
================================
```
Contributor guide
Assessment
This issue has not been assessed yet.