Commit Graph

14 Commits

Author SHA1 Message Date
Megan Marsh 6a1a22151c move the various flag packages from helper to command, since command is the only package that uses them. 2020-11-16 14:23:35 -08:00
Wilken Rivera acabc1c1aa
Add packer fmt command (#10225)
* Add packer fmt command

This change adds a new command that allows users to format one or more
HCL2 Packer configuration template files.

Related to: #9174

* command/fmt: Add check flag

Packer's fmt command now supports a check flag that will output the name
of any file that would be changed by the HCL2 formatting engine. The
check flag is mutually exclusive with the write flag and will only check
if formatting is needed.

The update write flag will now overwrite the source files with the newly
formatted HCL2 source unless the `-write=false` or `-check` is passed at
the command line.

* Returns a diagnostic error if Format is unable to show a diff - equivalent to `terraform fmt`
* Updates testing to run against #Format and not the private methods of the HCL2Formatter; fixes ShowDiff test failure on Windows
* Updates comments for exported functions

* Add docs for fmt command
2020-11-11 11:49:39 -05:00
Adrien Delorme 5ba134ac5b
JSON to HCL2 (minimal best-effort) transpiler (#9659)
hcl2_upgrade transforms a JSON build-file in a HCL2 build-file.
This starts a validated Packer core and from that core we generate an HCL 'block' per plugin/configuration. So for a builder, a provisioner, a post-processor or a variable. The contents of each block is just transformed as is and basically all fields are HCL2-ified.
A generated field can be valid in JSON but invalid on HCL2; for example JSON templating (in mapstructure) allows to set arrays of strings - like `x = ["a", "b"]` - with single strings - like `x="a"` -, HCL does not allow this.
Since JSON does not make the distinction between variables and locals, everything will be a variable. So variables that use other variables will not work.
hcl2_upgrade tries to transform go templating interpolation calls to HCL2 calls when possible, leaving the go templating calls like they are in case it cannot.

Work:
* transpiler
* tests
* update hcl v2 library so that output looks great.
* update docs
2020-08-25 10:51:43 +02:00
Adrien Delorme 51d02f8c2d hcl2: inspect command 2020-06-23 11:58:57 +02:00
Moss 4f26534072 add on-error flag option to run cleanup provisioner 2020-06-16 15:34:00 +02:00
Adrien Delorme bac9c74447
packer console for HCL2 (#9359) 2020-06-05 17:23:54 +02:00
Adrien Delorme 7ca0a80a86 remove Ui from command.MetaArgs 2020-05-12 12:14:30 +02:00
Adrien Delorme 77297e49e9 Update cli.go 2020-05-12 12:07:02 +02:00
Adrien Delorme efcc6af06c fix tests 2020-05-08 17:46:33 +02:00
Adrien Delorme a93a45e4d3 more fixes to refactor 2020-05-08 17:15:00 +02:00
Adrien Delorme 42a05e1e80 more refactoring 2020-05-08 16:41:47 +02:00
Adrien Delorme 2f63e4e79d refactor term interrupts & have RunContext take a conf struct now 2020-05-08 12:05:14 +02:00
Adrien Delorme 5290beb23e Update cli.go 2020-05-08 11:59:10 +02:00
Adrien Delorme a5ab87ca44 add scaffolding for the new packer command layout 2020-05-07 17:52:49 +02:00