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.
This commit is contained in:
Martin Atkins 2017-04-25 10:20:21 -07:00
parent eda2550074
commit eaac9fbca3

View File

@ -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
}