From eaac9fbca3aebd1d1f23ff2b70089739872b166a Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Tue, 25 Apr 2017 10:20:21 -0700 Subject: [PATCH] provider/template: template_dir explicitly create dest dir Previously we were letting it get implicitly created as part of making the structure for copying in each file, but that isn't sufficient if the source directory is empty. By explicitly creating the directory first we ensure that it will complete successfully even in the case of an empty directory. --- builtin/providers/template/resource_template_dir.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/builtin/providers/template/resource_template_dir.go b/builtin/providers/template/resource_template_dir.go index 9154d2a89e..63a2f18dc9 100644 --- a/builtin/providers/template/resource_template_dir.go +++ b/builtin/providers/template/resource_template_dir.go @@ -87,11 +87,20 @@ func resourceTemplateDirCreate(d *schema.ResourceData, meta interface{}) error { return err } + // Create the destination directory and any other intermediate directories + // leading to it. + if _, err := os.Stat(destinationDir); err != nil { + if err := os.MkdirAll(destinationDir, 0777); err != nil { + return err + } + } + // Recursively crawl the input files/directories and generate the output ones. err := filepath.Walk(sourceDir, func(p string, f os.FileInfo, err error) error { if err != nil { return err } + if f.IsDir() { return nil }