Skip to content

Commit 9b8e5c2

Browse files
authored
feat(provisionersdk): add support for .tf.json templates (#7744)
1 parent 9dbbe82 commit 9b8e5c2

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

provisionersdk/archive.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@ const (
1515
TemplateArchiveLimit = 1 << 20
1616
)
1717

18-
func dirHasExt(dir string, ext string) (bool, error) {
18+
func dirHasExt(dir string, exts ...string) (bool, error) {
1919
dirEnts, err := os.ReadDir(dir)
2020
if err != nil {
2121
return false, err
2222
}
2323

2424
for _, fi := range dirEnts {
25-
if strings.HasSuffix(fi.Name(), ext) {
26-
return true, nil
25+
for _, ext := range exts {
26+
if strings.HasSuffix(fi.Name(), ext) {
27+
return true, nil
28+
}
2729
}
2830
}
2931

@@ -35,8 +37,8 @@ func Tar(w io.Writer, directory string, limit int64) error {
3537
tarWriter := tar.NewWriter(w)
3638
totalSize := int64(0)
3739

38-
const tfExt = ".tf"
39-
hasTf, err := dirHasExt(directory, tfExt)
40+
tfExts := []string{".tf", ".tf.json"}
41+
hasTf, err := dirHasExt(directory, tfExts...)
4042
if err != nil {
4143
return err
4244
}
@@ -50,7 +52,7 @@ func Tar(w io.Writer, directory string, limit int64) error {
5052
// useless.
5153
return xerrors.Errorf(
5254
"%s is not a valid template since it has no %s files",
53-
absPath, tfExt,
55+
absPath, tfExts,
5456
)
5557
}
5658

provisionersdk/archive_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ func TestTar(t *testing.T) {
3333
err = provisionersdk.Tar(io.Discard, dir, 1024)
3434
require.NoError(t, err)
3535
})
36+
t.Run("ValidJSON", func(t *testing.T) {
37+
t.Parallel()
38+
dir := t.TempDir()
39+
file, err := os.CreateTemp(dir, "*.tf.json")
40+
require.NoError(t, err)
41+
_ = file.Close()
42+
err = provisionersdk.Tar(io.Discard, dir, 1024)
43+
require.NoError(t, err)
44+
})
3645
t.Run("HiddenFiles", func(t *testing.T) {
3746
t.Parallel()
3847
dir := t.TempDir()

0 commit comments

Comments
 (0)