Packer HCL2配置文件支持



Inhttps://packer.io/guides/hcl/from-json-v1/,上面写着

注意:从1.5.0版本开始,Packer可以读取HCL2文件。

我的打包器是packer_1.5.5_linux_amd64.zip,它被认为能够读取HCL2文件。然而,当我尝试时,我得到了

$ packer build -only=docker hcl-example
Failed to parse template: Error parsing JSON: invalid character '#' looking for beginning of value
At line 1, column 1 (offset 1):
1: #
^
==> Builds finished but no artifacts were created.
$ packer build -h 
Usage: packer build [options] TEMPLATE
Will execute multiple builds in parallel as defined in the template.
The various artifacts created by the template will be outputted.
Options:
-color=false                  Disable color output. (Default: color)
-debug                        Debug mode enabled for builds.
-except=foo,bar,baz           Run all builds and post-procesors other than these.
-only=foo,bar,baz             Build only the specified builds.
-force                        Force a build to continue if artifacts exist, deletes existing artifacts.
-machine-readable             Produce machine-readable output.
-on-error=[cleanup|abort|ask] If the build fails do: clean up (default), abort, or ask.
-parallel=false               Disable parallelization. (Default: true)
-parallel-builds=1            Number of builds to run in parallel. 0 means no limit (Default: 0)
-timestamp-ui                 Enable prefixing of each ui output with an RFC3339 timestamp.
-var 'key=value'              Variable for templates, can be used multiple times.
-var-file=path                JSON file containing user variables. [ Note that even in HCL mode this expects file to contain JSON, a fix is comming soon ]

并且我没有看到从上面切换到HCL2模式的任何切换。

我在这里缺少什么?

$ packer version
Packer v1.5.5
$ cat hcl-example
# the source block is what was defined in the builders section and represents a
# reusable way to start a machine. You build your images from that source.source
"amazon-ebs" "example" {
ami_name = "packer-test"
region = "us-east-1"
instance_type = "t2.micro"
}

[更新:]

为了解决Matt的评论/担忧,我将hcl示例的内容更改为https://packer.io/guides/hcl/from-json-v1/、和

mv hcl-example hcl-example.hcl
$ packer validate hcl-example.hcl
Failed to parse template: Error parsing JSON: invalid character '#' looking for beginning of value
At line 1, column 1 (offset 1):
1: #
^

.pkr.hcl扩展名命名它解决了这个问题。

最新更新