14 Commits

Author SHA1 Message Date
Wilken Rivera
1bb154de5a Add support for reading configs
This is the first step in attempting to read a Packer configuration file
via the packer init command. At the present moment it will try to read
one or more configuration templates from a given directory or path. Once
parsed it will error if parsing fails or exist successfully if it is
able to parse the file.

Looking at how the code is structured there will need to be changes made
to the following places:

- When no configuration file is found Packer will display an error. That
error should be bubbled up a bit so that the caller command can
determine if it should be displayed or not. For packer init no
configuration is not an error. Maybe it should be?

- After a configuration has been parsed there needs to be a single way
to determine a list of plugins associated with the configuration. HCL
and JSON configs have fields for this data but some is exported and some
is unexported. Adapting the packerHandler interface may be an option
here. More investigation needed.
2020-09-16 14:46:16 -04:00
Wilken Rivera
8069ae4f43 Add flagset to init command 2020-09-15 10:19:56 -04: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