@Test public void packageGoalWithNoFatZipPackagesOnlyTfRootContentsInTheTargetDir() throws TerraformException, IOException { Path zipFilePath = Paths.get(TerraformPackage.targetDir) .resolve(String.format("%1$s-%2$s.zip", project.getArtifactId(), project.getVersion())); this.properties.put(TerraformPackageParams.tfVarFiles.toString(), "variables/dev1.tfvars,variables/dev2.tfvars"); String response = this.terraformPackage.execute(properties); Assert.assertEquals(response, String.format("Created zip file '%1$s'", zipFilePath.toString())); Assert.assertEquals(4, this.targetTfRootModule.toFile().listFiles().length); Assert.assertEquals("dev1.auto.tfvars,dev2.auto.tfvars,main.tf", Files.walk(this.targetTfRootModule, 1) .filter(path -> !path.toFile().isDirectory()) .map(path -> path.getFileName().toString()) .sorted() .collect(Collectors.joining(","))); try (IterableZipInputStream zipStream = new IterableZipInputStream(new FileInputStream(zipFilePath.toFile()))) { int count = 0; Set<String> zipEntryNames = new HashSet<>(); for (ZipEntry entry : zipStream) { count++; zipEntryNames.add(entry.getName()); } Assert.assertEquals(6, count); Assert.assertTrue(zipEntryNames.contains("main.tf")); Assert.assertTrue(zipEntryNames.contains("dev1.auto.tfvars")); Assert.assertTrue(zipEntryNames.contains("dev2.auto.tfvars")); } }
@Override public String execute(Properties properties) throws TerraformException { try { Path targetPath = Paths.get(targetDir); Path targetTfRootPath = targetPath.resolve(targetTfRootDir); String tfModulesDir = properties.getProperty(TerraformPackageParams.tfModulesDir.toString()); String tfRootDir = properties.getProperty(TerraformPackageParams.tfRootDir.toString()); String tfVarFiles = properties.getProperty(TerraformPackageParams.tfVarFiles.toString()); Object isFatTarObj = properties.getOrDefault(TerraformPackageParams.fatTar.toString(), false); boolean isFatTar = isFatTarObj instanceof Boolean ? (Boolean)isFatTarObj : Boolean.valueOf(isFatTarObj.toString()); Path tfModulesPath = !StringUtils.isEmpty(tfModulesDir) ? Paths.get(tfModulesDir) : TerraformUtils.getDefaultTfModulesDir(); logger.debug(String.format("tfModulesPath is %1$s", tfModulesPath.toAbsolutePath().toString())); File tfSourceFile = Paths.get("src", "main", "tf").toFile(); Path tfRootPath = !StringUtils.isEmpty(tfRootDir) ? TerraformUtils.getTerraformRootModuleDir(tfRootDir) : (tfSourceFile.exists() && tfSourceFile.isDirectory() && tfSourceFile.listFiles().length > 1 ? tfSourceFile.toPath() : TerraformUtils.getDefaultTerraformRootModuleDir()); logger.debug(String.format("tfRootPath is %1$s", tfRootPath.toAbsolutePath().toString())); List<Path> tfVarFilePaths = StringUtils.isEmpty(tfVarFiles) ? new ArrayList<>() : Arrays.stream(tfVarFiles.split(",")) .map(x -> tfRootPath.resolve(x.trim())) .collect(Collectors.toList()); logger.debug(String.format("tfVarFiles is %1$s", tfVarFilePaths)); if (targetTfRootPath.toFile().exists()) FileUtils.forceDelete(targetTfRootPath.toFile()); FileUtils.forceMkdir(targetTfRootPath.toFile()); List<Path> tfRootDirFiles = Files.walk(tfRootPath, 1) .filter(path -> !path.equals(tfRootPath)) .collect(Collectors.toList()); for (Path file : tfRootDirFiles.stream().filter(f -> !excludedFiles.contains(f.getFileName().toString())).collect(Collectors.toList())) { if (file.toFile().isDirectory()) { FileUtils.copyDirectory(file.toFile(), targetTfRootPath.resolve(file.getFileName().toString()).toFile(), new FileFilter() { @Override public boolean accept(File pathname) { return excludedFiles.stream().noneMatch(excludedFile -> pathname.getName().endsWith(excludedFile)); } }); } else { Files.copy(file, targetTfRootPath.resolve(file.getFileName().toString())); } } for (Path tfVarFilePath : tfVarFilePaths) { Files.copy(tfVarFilePath, targetTfRootPath.resolve(tfVarFilePath.getFileName().toString().replaceAll(".tfvars", "").concat(".auto.tfvars"))); } if (isFatTar) { updateDependenciesInTfRoot(targetTfRootPath, tfModulesPath, tfRootPath); if (tfModulesPath.toFile().exists() && tfModulesPath.toFile().isDirectory()) { FileUtils.copyDirectory(tfModulesPath.toFile(), targetTfRootPath.resolve(tfModulesPath.getFileName().toString()).toFile()); } return String.format("Created fatTar gzipped tar file '%1$s'", createGZippedTar(targetPath, targetTfRootPath)); } return String.format("Created zip file '%1$s'", createZip(targetPath, targetTfRootPath)); } catch (IOException e) { throw new TerraformException(e.getMessage(), e); } }
TerraformPackage implements TerraformOperation<String> { @Override public String execute(Properties properties) throws TerraformException { try { Path targetPath = Paths.get(targetDir); Path targetTfRootPath = targetPath.resolve(targetTfRootDir); String tfModulesDir = properties.getProperty(TerraformPackageParams.tfModulesDir.toString()); String tfRootDir = properties.getProperty(TerraformPackageParams.tfRootDir.toString()); String tfVarFiles = properties.getProperty(TerraformPackageParams.tfVarFiles.toString()); Object isFatTarObj = properties.getOrDefault(TerraformPackageParams.fatTar.toString(), false); boolean isFatTar = isFatTarObj instanceof Boolean ? (Boolean)isFatTarObj : Boolean.valueOf(isFatTarObj.toString()); Path tfModulesPath = !StringUtils.isEmpty(tfModulesDir) ? Paths.get(tfModulesDir) : TerraformUtils.getDefaultTfModulesDir(); logger.debug(String.format("tfModulesPath is %1$s", tfModulesPath.toAbsolutePath().toString())); File tfSourceFile = Paths.get("src", "main", "tf").toFile(); Path tfRootPath = !StringUtils.isEmpty(tfRootDir) ? TerraformUtils.getTerraformRootModuleDir(tfRootDir) : (tfSourceFile.exists() && tfSourceFile.isDirectory() && tfSourceFile.listFiles().length > 1 ? tfSourceFile.toPath() : TerraformUtils.getDefaultTerraformRootModuleDir()); logger.debug(String.format("tfRootPath is %1$s", tfRootPath.toAbsolutePath().toString())); List<Path> tfVarFilePaths = StringUtils.isEmpty(tfVarFiles) ? new ArrayList<>() : Arrays.stream(tfVarFiles.split(",")) .map(x -> tfRootPath.resolve(x.trim())) .collect(Collectors.toList()); logger.debug(String.format("tfVarFiles is %1$s", tfVarFilePaths)); if (targetTfRootPath.toFile().exists()) FileUtils.forceDelete(targetTfRootPath.toFile()); FileUtils.forceMkdir(targetTfRootPath.toFile()); List<Path> tfRootDirFiles = Files.walk(tfRootPath, 1) .filter(path -> !path.equals(tfRootPath)) .collect(Collectors.toList()); for (Path file : tfRootDirFiles.stream().filter(f -> !excludedFiles.contains(f.getFileName().toString())).collect(Collectors.toList())) { if (file.toFile().isDirectory()) { FileUtils.copyDirectory(file.toFile(), targetTfRootPath.resolve(file.getFileName().toString()).toFile(), new FileFilter() { @Override public boolean accept(File pathname) { return excludedFiles.stream().noneMatch(excludedFile -> pathname.getName().endsWith(excludedFile)); } }); } else { Files.copy(file, targetTfRootPath.resolve(file.getFileName().toString())); } } for (Path tfVarFilePath : tfVarFilePaths) { Files.copy(tfVarFilePath, targetTfRootPath.resolve(tfVarFilePath.getFileName().toString().replaceAll(".tfvars", "").concat(".auto.tfvars"))); } if (isFatTar) { updateDependenciesInTfRoot(targetTfRootPath, tfModulesPath, tfRootPath); if (tfModulesPath.toFile().exists() && tfModulesPath.toFile().isDirectory()) { FileUtils.copyDirectory(tfModulesPath.toFile(), targetTfRootPath.resolve(tfModulesPath.getFileName().toString()).toFile()); } return String.format("Created fatTar gzipped tar file '%1$s'", createGZippedTar(targetPath, targetTfRootPath)); } return String.format("Created zip file '%1$s'", createZip(targetPath, targetTfRootPath)); } catch (IOException e) { throw new TerraformException(e.getMessage(), e); } } }
TerraformPackage implements TerraformOperation<String> { @Override public String execute(Properties properties) throws TerraformException { try { Path targetPath = Paths.get(targetDir); Path targetTfRootPath = targetPath.resolve(targetTfRootDir); String tfModulesDir = properties.getProperty(TerraformPackageParams.tfModulesDir.toString()); String tfRootDir = properties.getProperty(TerraformPackageParams.tfRootDir.toString()); String tfVarFiles = properties.getProperty(TerraformPackageParams.tfVarFiles.toString()); Object isFatTarObj = properties.getOrDefault(TerraformPackageParams.fatTar.toString(), false); boolean isFatTar = isFatTarObj instanceof Boolean ? (Boolean)isFatTarObj : Boolean.valueOf(isFatTarObj.toString()); Path tfModulesPath = !StringUtils.isEmpty(tfModulesDir) ? Paths.get(tfModulesDir) : TerraformUtils.getDefaultTfModulesDir(); logger.debug(String.format("tfModulesPath is %1$s", tfModulesPath.toAbsolutePath().toString())); File tfSourceFile = Paths.get("src", "main", "tf").toFile(); Path tfRootPath = !StringUtils.isEmpty(tfRootDir) ? TerraformUtils.getTerraformRootModuleDir(tfRootDir) : (tfSourceFile.exists() && tfSourceFile.isDirectory() && tfSourceFile.listFiles().length > 1 ? tfSourceFile.toPath() : TerraformUtils.getDefaultTerraformRootModuleDir()); logger.debug(String.format("tfRootPath is %1$s", tfRootPath.toAbsolutePath().toString())); List<Path> tfVarFilePaths = StringUtils.isEmpty(tfVarFiles) ? new ArrayList<>() : Arrays.stream(tfVarFiles.split(",")) .map(x -> tfRootPath.resolve(x.trim())) .collect(Collectors.toList()); logger.debug(String.format("tfVarFiles is %1$s", tfVarFilePaths)); if (targetTfRootPath.toFile().exists()) FileUtils.forceDelete(targetTfRootPath.toFile()); FileUtils.forceMkdir(targetTfRootPath.toFile()); List<Path> tfRootDirFiles = Files.walk(tfRootPath, 1) .filter(path -> !path.equals(tfRootPath)) .collect(Collectors.toList()); for (Path file : tfRootDirFiles.stream().filter(f -> !excludedFiles.contains(f.getFileName().toString())).collect(Collectors.toList())) { if (file.toFile().isDirectory()) { FileUtils.copyDirectory(file.toFile(), targetTfRootPath.resolve(file.getFileName().toString()).toFile(), new FileFilter() { @Override public boolean accept(File pathname) { return excludedFiles.stream().noneMatch(excludedFile -> pathname.getName().endsWith(excludedFile)); } }); } else { Files.copy(file, targetTfRootPath.resolve(file.getFileName().toString())); } } for (Path tfVarFilePath : tfVarFilePaths) { Files.copy(tfVarFilePath, targetTfRootPath.resolve(tfVarFilePath.getFileName().toString().replaceAll(".tfvars", "").concat(".auto.tfvars"))); } if (isFatTar) { updateDependenciesInTfRoot(targetTfRootPath, tfModulesPath, tfRootPath); if (tfModulesPath.toFile().exists() && tfModulesPath.toFile().isDirectory()) { FileUtils.copyDirectory(tfModulesPath.toFile(), targetTfRootPath.resolve(tfModulesPath.getFileName().toString()).toFile()); } return String.format("Created fatTar gzipped tar file '%1$s'", createGZippedTar(targetPath, targetTfRootPath)); } return String.format("Created zip file '%1$s'", createZip(targetPath, targetTfRootPath)); } catch (IOException e) { throw new TerraformException(e.getMessage(), e); } } TerraformPackage(MavenProject project, Logger logger);  TerraformPackage(MavenProject project, Log log);  TerraformPackage(MavenProject project); }
TerraformPackage implements TerraformOperation<String> { @Override public String execute(Properties properties) throws TerraformException { try { Path targetPath = Paths.get(targetDir); Path targetTfRootPath = targetPath.resolve(targetTfRootDir); String tfModulesDir = properties.getProperty(TerraformPackageParams.tfModulesDir.toString()); String tfRootDir = properties.getProperty(TerraformPackageParams.tfRootDir.toString()); String tfVarFiles = properties.getProperty(TerraformPackageParams.tfVarFiles.toString()); Object isFatTarObj = properties.getOrDefault(TerraformPackageParams.fatTar.toString(), false); boolean isFatTar = isFatTarObj instanceof Boolean ? (Boolean)isFatTarObj : Boolean.valueOf(isFatTarObj.toString()); Path tfModulesPath = !StringUtils.isEmpty(tfModulesDir) ? Paths.get(tfModulesDir) : TerraformUtils.getDefaultTfModulesDir(); logger.debug(String.format("tfModulesPath is %1$s", tfModulesPath.toAbsolutePath().toString())); File tfSourceFile = Paths.get("src", "main", "tf").toFile(); Path tfRootPath = !StringUtils.isEmpty(tfRootDir) ? TerraformUtils.getTerraformRootModuleDir(tfRootDir) : (tfSourceFile.exists() && tfSourceFile.isDirectory() && tfSourceFile.listFiles().length > 1 ? tfSourceFile.toPath() : TerraformUtils.getDefaultTerraformRootModuleDir()); logger.debug(String.format("tfRootPath is %1$s", tfRootPath.toAbsolutePath().toString())); List<Path> tfVarFilePaths = StringUtils.isEmpty(tfVarFiles) ? new ArrayList<>() : Arrays.stream(tfVarFiles.split(",")) .map(x -> tfRootPath.resolve(x.trim())) .collect(Collectors.toList()); logger.debug(String.format("tfVarFiles is %1$s", tfVarFilePaths)); if (targetTfRootPath.toFile().exists()) FileUtils.forceDelete(targetTfRootPath.toFile()); FileUtils.forceMkdir(targetTfRootPath.toFile()); List<Path> tfRootDirFiles = Files.walk(tfRootPath, 1) .filter(path -> !path.equals(tfRootPath)) .collect(Collectors.toList()); for (Path file : tfRootDirFiles.stream().filter(f -> !excludedFiles.contains(f.getFileName().toString())).collect(Collectors.toList())) { if (file.toFile().isDirectory()) { FileUtils.copyDirectory(file.toFile(), targetTfRootPath.resolve(file.getFileName().toString()).toFile(), new FileFilter() { @Override public boolean accept(File pathname) { return excludedFiles.stream().noneMatch(excludedFile -> pathname.getName().endsWith(excludedFile)); } }); } else { Files.copy(file, targetTfRootPath.resolve(file.getFileName().toString())); } } for (Path tfVarFilePath : tfVarFilePaths) { Files.copy(tfVarFilePath, targetTfRootPath.resolve(tfVarFilePath.getFileName().toString().replaceAll(".tfvars", "").concat(".auto.tfvars"))); } if (isFatTar) { updateDependenciesInTfRoot(targetTfRootPath, tfModulesPath, tfRootPath); if (tfModulesPath.toFile().exists() && tfModulesPath.toFile().isDirectory()) { FileUtils.copyDirectory(tfModulesPath.toFile(), targetTfRootPath.resolve(tfModulesPath.getFileName().toString()).toFile()); } return String.format("Created fatTar gzipped tar file '%1$s'", createGZippedTar(targetPath, targetTfRootPath)); } return String.format("Created zip file '%1$s'", createZip(targetPath, targetTfRootPath)); } catch (IOException e) { throw new TerraformException(e.getMessage(), e); } } TerraformPackage(MavenProject project, Logger logger);  TerraformPackage(MavenProject project, Log log);  TerraformPackage(MavenProject project); @Override String execute(Properties properties); }
TerraformPackage implements TerraformOperation<String> { @Override public String execute(Properties properties) throws TerraformException { try { Path targetPath = Paths.get(targetDir); Path targetTfRootPath = targetPath.resolve(targetTfRootDir); String tfModulesDir = properties.getProperty(TerraformPackageParams.tfModulesDir.toString()); String tfRootDir = properties.getProperty(TerraformPackageParams.tfRootDir.toString()); String tfVarFiles = properties.getProperty(TerraformPackageParams.tfVarFiles.toString()); Object isFatTarObj = properties.getOrDefault(TerraformPackageParams.fatTar.toString(), false); boolean isFatTar = isFatTarObj instanceof Boolean ? (Boolean)isFatTarObj : Boolean.valueOf(isFatTarObj.toString()); Path tfModulesPath = !StringUtils.isEmpty(tfModulesDir) ? Paths.get(tfModulesDir) : TerraformUtils.getDefaultTfModulesDir(); logger.debug(String.format("tfModulesPath is %1$s", tfModulesPath.toAbsolutePath().toString())); File tfSourceFile = Paths.get("src", "main", "tf").toFile(); Path tfRootPath = !StringUtils.isEmpty(tfRootDir) ? TerraformUtils.getTerraformRootModuleDir(tfRootDir) : (tfSourceFile.exists() && tfSourceFile.isDirectory() && tfSourceFile.listFiles().length > 1 ? tfSourceFile.toPath() : TerraformUtils.getDefaultTerraformRootModuleDir()); logger.debug(String.format("tfRootPath is %1$s", tfRootPath.toAbsolutePath().toString())); List<Path> tfVarFilePaths = StringUtils.isEmpty(tfVarFiles) ? new ArrayList<>() : Arrays.stream(tfVarFiles.split(",")) .map(x -> tfRootPath.resolve(x.trim())) .collect(Collectors.toList()); logger.debug(String.format("tfVarFiles is %1$s", tfVarFilePaths)); if (targetTfRootPath.toFile().exists()) FileUtils.forceDelete(targetTfRootPath.toFile()); FileUtils.forceMkdir(targetTfRootPath.toFile()); List<Path> tfRootDirFiles = Files.walk(tfRootPath, 1) .filter(path -> !path.equals(tfRootPath)) .collect(Collectors.toList()); for (Path file : tfRootDirFiles.stream().filter(f -> !excludedFiles.contains(f.getFileName().toString())).collect(Collectors.toList())) { if (file.toFile().isDirectory()) { FileUtils.copyDirectory(file.toFile(), targetTfRootPath.resolve(file.getFileName().toString()).toFile(), new FileFilter() { @Override public boolean accept(File pathname) { return excludedFiles.stream().noneMatch(excludedFile -> pathname.getName().endsWith(excludedFile)); } }); } else { Files.copy(file, targetTfRootPath.resolve(file.getFileName().toString())); } } for (Path tfVarFilePath : tfVarFilePaths) { Files.copy(tfVarFilePath, targetTfRootPath.resolve(tfVarFilePath.getFileName().toString().replaceAll(".tfvars", "").concat(".auto.tfvars"))); } if (isFatTar) { updateDependenciesInTfRoot(targetTfRootPath, tfModulesPath, tfRootPath); if (tfModulesPath.toFile().exists() && tfModulesPath.toFile().isDirectory()) { FileUtils.copyDirectory(tfModulesPath.toFile(), targetTfRootPath.resolve(tfModulesPath.getFileName().toString()).toFile()); } return String.format("Created fatTar gzipped tar file '%1$s'", createGZippedTar(targetPath, targetTfRootPath)); } return String.format("Created zip file '%1$s'", createZip(targetPath, targetTfRootPath)); } catch (IOException e) { throw new TerraformException(e.getMessage(), e); } } TerraformPackage(MavenProject project, Logger logger);  TerraformPackage(MavenProject project, Log log);  TerraformPackage(MavenProject project); @Override String execute(Properties properties);  }