hashicorp / hashicorp/packer

manifest post-processor: add option to add/truncate manifest file dissociated from packer -force flag

Open
#12,337 0 comments 1 reaction 0 assignees View on GitHub
enhancement post-processor/manifest
Dominant language
Go
Stars
15.8k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

#### Community Note

* Please vote on this issue by adding a 👍 [reaction](https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/) to the original issue to help the community and maintainers prioritize this request
* Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
* If you are interested in working on this issue or have submitted a pull request, please leave a comment

#### Description

Add ability to configure "write mode" of manifest file (append or truncate) independently from using packer `-force` flag.

#### Use Case(s)

Need to use `-force` flag with some builders (which could have a different meaning) but need to keep tracks of all builds in same manifest file.

A good example is `vsphere-clone` builder which use `-force` flag to destroy existing artifacts (VM or template in this case) before building a new one (with same name):
```
...
==> Some builds didn't complete successfully and had errors:
--> vsphere-clone: vm-XYZ already exists, you can use -force flag to destroy it:

==> Builds finished but no artifacts were created.
```
If I need to destroy existing artifacts in vSphere but looking to keep tracks of subsequent builds in a manifest file, there is no simple solution based on packer template. Possible workarounds involve destroying exiting VM or template before running builder, or using individual manifest files (then merging them with a script using `jq` utility for example) which is not obvious.

A possible solution would be to implement an optional `overwrite` configuration parameter as boolean to define manifest behaviour as used in [vSphere post processor](https://developer.hashicorp.com/packer/plugins/post-processors/vsphere/vsphere#overwrite).

#### Potential References

As defined in (documentation)[https://developer.hashicorp.com/packer/docs/post-processors/manifest], decision to add or truncate subsequent builds in manifest file is only driven by -force flag:

> If packer is run with the -force flag the manifest file will be truncated automatically during each packer run. Otherwise, subsequent builds will be added to the file. You can use the timestamps to see which is the latest artifact.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.