diff --git a/terraform-client/src/main/java/org/terrakube/terraform/ProcessLauncher.java b/terraform-client/src/main/java/org/terrakube/terraform/ProcessLauncher.java index a7da548..aacf11d 100644 --- a/terraform-client/src/main/java/org/terrakube/terraform/ProcessLauncher.java +++ b/terraform-client/src/main/java/org/terrakube/terraform/ProcessLauncher.java @@ -39,6 +39,11 @@ void setDirectory(File directory) { assert this.process == null; this.builder.directory(directory); } + + void setRedirectErrorStream(boolean redirectErrorStream) { + assert this.process == null; + this.builder.redirectErrorStream(redirectErrorStream); + } void appendCommands(String... commands) { Stream filteredCommands = Arrays.stream(commands).filter(c -> c != null && c.length() > 0); diff --git a/terraform-client/src/main/java/org/terrakube/terraform/TerraformClient.java b/terraform-client/src/main/java/org/terrakube/terraform/TerraformClient.java index 73c3574..9d14e2b 100644 --- a/terraform-client/src/main/java/org/terrakube/terraform/TerraformClient.java +++ b/terraform-client/src/main/java/org/terrakube/terraform/TerraformClient.java @@ -41,6 +41,7 @@ public class TerraformClient implements AutoCloseable { private boolean inheritIO; private boolean showColor; private boolean jsonOutput; + private boolean redirectErrorStream; private String terraformVersion; private String backendConfig; private String terraformReleasesUrl; @@ -68,7 +69,7 @@ public CompletableFuture version() throws IOException { return launcher.launch().thenApply((c) -> c == 0 ? version.toString() : null); } - public CompletableFuture show(@NonNull TerraformProcessData terraformProcessData, @NonNull Consumer outputListener, @NonNull Consumer errorListener) throws IOException { + public CompletableFuture show(@NonNull TerraformProcessData terraformProcessData, @NonNull Consumer outputListener, Consumer errorListener) throws IOException { checkVarFileParam(terraformProcessData); checkTerraformVariablesParam(terraformProcessData); return this.run( @@ -83,7 +84,7 @@ public CompletableFuture show() throws IOException { return this.run(TerraformCommand.show); } - public CompletableFuture showPlan(@NonNull TerraformProcessData terraformProcessData, @NonNull Consumer outputListener, @NonNull Consumer errorListener) throws IOException { + public CompletableFuture showPlan(@NonNull TerraformProcessData terraformProcessData, @NonNull Consumer outputListener, Consumer errorListener) throws IOException { checkVarFileParam(terraformProcessData); checkTerraformVariablesParam(terraformProcessData); return this.run( @@ -98,7 +99,7 @@ public CompletableFuture showPlan() throws IOException { return this.run(TerraformCommand.showPlan); } - public CompletableFuture init(TerraformProcessData terraformProcessData, @NonNull Consumer outputListener, @NonNull Consumer errorListener) throws IOException { + public CompletableFuture init(TerraformProcessData terraformProcessData, @NonNull Consumer outputListener, Consumer errorListener) throws IOException { checkVarFileParam(terraformProcessData); checkTerraformVariablesParam(terraformProcessData); return this.run( @@ -113,7 +114,7 @@ public CompletableFuture init() throws IOException { return this.run(TerraformCommand.init); } - public CompletableFuture plan(TerraformProcessData terraformProcessData, @NonNull Consumer outputListener, @NonNull Consumer errorListener) throws IOException { + public CompletableFuture plan(TerraformProcessData terraformProcessData, @NonNull Consumer outputListener, Consumer errorListener) throws IOException { return this.run( terraformProcessData, outputListener, @@ -121,7 +122,7 @@ public CompletableFuture plan(TerraformProcessData terraformProcessData TerraformCommand.plan); } - public CompletableFuture planDetailExitCode(TerraformProcessData terraformProcessData, @NonNull Consumer outputListener, @NonNull Consumer errorListener) throws IOException { + public CompletableFuture planDetailExitCode(TerraformProcessData terraformProcessData, @NonNull Consumer outputListener, Consumer errorListener) throws IOException { terraformProcessData.setDetailExitCode(true); return this.getTerraformLauncher( terraformProcessData, @@ -129,7 +130,7 @@ public CompletableFuture planDetailExitCode(TerraformProcessData terraf errorListener, TerraformCommand.plan).launch(); } - public CompletableFuture statePull(TerraformProcessData terraformProcessData, @NonNull Consumer outputListener, @NonNull Consumer errorListener) throws IOException { + public CompletableFuture statePull(TerraformProcessData terraformProcessData, @NonNull Consumer outputListener, Consumer errorListener) throws IOException { return this.run( terraformProcessData, outputListener, @@ -137,7 +138,7 @@ public CompletableFuture statePull(TerraformProcessData terraformProces TerraformCommand.statePull); } - public CompletableFuture planDestroy(TerraformProcessData terraformProcessData, @NonNull Consumer outputListener, @NonNull Consumer errorListener) throws IOException { + public CompletableFuture planDestroy(TerraformProcessData terraformProcessData, @NonNull Consumer outputListener, Consumer errorListener) throws IOException { return this.run( terraformProcessData, outputListener, @@ -145,7 +146,7 @@ public CompletableFuture planDestroy(TerraformProcessData terraformProc TerraformCommand.planDestroy); } - public CompletableFuture planDestroyDetailExitCode(TerraformProcessData terraformProcessData, @NonNull Consumer outputListener, @NonNull Consumer errorListener) throws IOException { + public CompletableFuture planDestroyDetailExitCode(TerraformProcessData terraformProcessData, @NonNull Consumer outputListener, Consumer errorListener) throws IOException { terraformProcessData.setDetailExitCode(true); return this.getTerraformLauncher( terraformProcessData, @@ -158,7 +159,7 @@ public CompletableFuture plan() throws IOException { return this.run(TerraformCommand.plan); } - public CompletableFuture apply(TerraformProcessData terraformProcessData, @NonNull Consumer outputListener, @NonNull Consumer errorListener) throws IOException { + public CompletableFuture apply(TerraformProcessData terraformProcessData, @NonNull Consumer outputListener, Consumer errorListener) throws IOException { return this.run( terraformProcessData, outputListener, @@ -171,7 +172,7 @@ public CompletableFuture apply() throws IOException { return this.run(TerraformCommand.apply); } - public CompletableFuture destroy(TerraformProcessData terraformProcessData, @NonNull Consumer outputListener, @NonNull Consumer errorListener) throws IOException { + public CompletableFuture destroy(TerraformProcessData terraformProcessData, @NonNull Consumer outputListener, Consumer errorListener) throws IOException { checkBackendConfigFile(terraformProcessData); return this.run( terraformProcessData, @@ -185,7 +186,7 @@ public CompletableFuture destroy() throws IOException { return this.run(TerraformCommand.destroy); } - public CompletableFuture output(TerraformProcessData terraformProcessData, @NonNull Consumer outputListener, @NonNull Consumer errorListener) throws IOException { + public CompletableFuture output(TerraformProcessData terraformProcessData, @NonNull Consumer outputListener, Consumer errorListener) throws IOException { checkBackendConfigFile(terraformProcessData); checkVarFileParam(terraformProcessData); checkTerraformVariablesParam(terraformProcessData); @@ -405,6 +406,7 @@ private ProcessLauncher getTerraformLauncher(TerraformProcessData terraformProce launcher.setOutputListener(outputListener); launcher.setErrorListener(errorListener); + launcher.setRedirectErrorStream(this.redirectErrorStream); return launcher; }