packer subcommands (console,inspect,validate) should support HCL format

Created on 23 Dec 2019  ·  12Comments  ·  Source: hashicorp/packer

Feature Description

Starting from Packer 1.5.0, we could use HCL templates in place of JSON templates but it looks like packer validate doesn't yet support HCL format.

Use Case(s)

test.pkr.hcl

source "docker" "example" {
       image = "centos:7"
       commit = "true"
}

build {
    sources = [
        "source.docker.example"
    ]

    provisioner "ansible" {
        playbook_file = "site.yml"
    }

}
$ packer validate test.pkr.hcl 
Failed to parse template: Error parsing JSON: invalid character 's' looking for beginning of value
At line 1, column 1 (offset 1):
    1: s
      ^
enhancement hcl2 track-internal

Most helpful comment

Hi!

If possible please also make packer validate arguments consistent with packer build.

For instance now we can trigger a build with:

packer build <DIRECTORY>

But if we try to validate our code with packer validate <DIRECTORY> we get the error Failed to parse template: read <DIRECTORY>: is a directory

I'm using Packer 1.5.4.

Best regards and thanks! (HCL support rocks, finally we can leave JSON behind :))

All 12 comments

It seems to be the case for console and inspect too. I'm updating subject of issue.

From my point of view, having a support of validate is a must have when you want to migrate your template from JSON to HCL.

Hello @nqb, thanks for opening 🙂 !

8423 only covered packer build, and we want to allow using HCL files for all of those commands, this is definitely something we want to do.

Hi!

If possible please also make packer validate arguments consistent with packer build.

For instance now we can trigger a build with:

packer build <DIRECTORY>

But if we try to validate our code with packer validate <DIRECTORY> we get the error Failed to parse template: read <DIRECTORY>: is a directory

I'm using Packer 1.5.4.

Best regards and thanks! (HCL support rocks, finally we can leave JSON behind :))

Hi @azr, I've just been revisting packer since the HCL support was added. Very keen to be able to validate and inspect my configs.

Are there any indications as to time, or issues tracking these features? I couldn't find any myself.

@NickLarsenNZ super nice :D. The short answer is we want to work on this but we don't know when this will be done.

We don't have a public schedule to share; but this is in our priority list and I think it's the next major thing I want to work on. Now please note that due to the current circumstances we _could_ postpone working on hard features because it can be harder than usual to focus and everything. 🙂

I just ran into this in Packer 1.5.5. What would it take to get this assigned to a milestone?

As a workaround for validate, I rename the packer files to .tf extension and then use the formatter from Terraform, terraform fmt.
Not elegant but works.

+1 for validate specifically

@julian-alarcon that was a good suggestion. I did the same, but used STDIN so I wouldn't need to rename files: cat file.pkr.hcl | terraform fmt - or add -check and look at the exit-code.

Ah, we still miss the inspect command, should I make another issue and rename this one ?

Let's use this one since it already has the context

I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

znerd picture znerd  ·  3Comments

shashanksinha89 picture shashanksinha89  ·  3Comments

s4mur4i picture s4mur4i  ·  3Comments

frezbo picture frezbo  ·  3Comments

mushon4 picture mushon4  ·  3Comments