From ee55ebda449f7c0b81f813adb30286764636e2c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9fix=20Estrada?= Date: Mon, 4 Sep 2023 11:48:52 +0200 Subject: [PATCH] feat(packer): support for template directories --- modules/packer/packer.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/modules/packer/packer.go b/modules/packer/packer.go index 8f11b4c4a..db6e44504 100644 --- a/modules/packer/packer.go +++ b/modules/packer/packer.go @@ -214,10 +214,18 @@ func packerInit(t testing.TestingT, options *Options) error { return nil } - extension := filepath.Ext(options.Template) - if extension != ".hcl" { - options.Logger.Logf(t, "Skipping 'packer init' because it is only supported for HCL2 templates") - return nil + f, err := os.Stat(options.Template) + if err != nil { + return err + } + + // Only check for extensions when template is a file. If it's a directory, assume it's HCL2 + if !f.IsDir() { + extension := filepath.Ext(options.Template) + if extension != ".hcl" { + options.Logger.Logf(t, "Skipping 'packer init' because it is only supported for HCL2 templates") + return nil + } } cmd := shell.Command{