0

https://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"
}

[更新:]

为了解决马特的评论/担忧,我已将 hcl-example 的内容更改为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: #
      ^
4

1 回答 1

1

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

于 2020-04-05T00:23:09.470 回答