in pkg/modulewriter/modulewriter.go [284:334]
func copyGroupSources(gPath string, g config.Group) error {
var copyEmbedded = false
for iMod := range g.Modules {
mod := &g.Modules[iMod]
deplSource, err := DeploymentSource(*mod)
if err != nil {
return err
}
if mod.Kind == config.TerraformKind {
// some terraform modules do not require copying
if sourcereader.IsEmbeddedPath(mod.Source) {
copyEmbedded = true
continue // all embedded terraform modules fill be copied at once
}
if sourcereader.IsRemotePath(mod.Source) {
continue // will be downloaded by terraform
}
}
/* Copy source files */
var src, dst string
if sourcereader.IsRemotePath(mod.Source) && mod.Kind == config.PackerKind {
src, _ = getter.SourceDirSubdir(mod.Source)
dst = filepath.Join(gPath, string(mod.ID))
} else {
src = mod.Source
dst = filepath.Join(gPath, deplSource)
}
if _, err := os.Stat(dst); err == nil {
continue
}
reader := sourcereader.Factory(src)
if err := reader.GetModule(src, dst); err != nil {
return fmt.Errorf("failed to get module from %s to %s: %w", src, dst, err)
}
// remove .git directory if one exists; we do not want submodule
// git history in deployment directory
if err := os.RemoveAll(filepath.Join(dst, ".git")); err != nil {
return err
}
}
if copyEmbedded {
if err := copyEmbeddedModules(gPath); err != nil {
return fmt.Errorf("failed to copy embedded modules: %w", err)
}
}
return nil
}