Skip to content

Commit

Permalink
Merge pull request #16 from AzBuilder/fix-input-param
Browse files Browse the repository at this point in the history
Adding input=false flag
  • Loading branch information
alfespa17 authored Mar 26, 2022
2 parents 5776e4e + 5a8f82f commit 80a4943
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<revision>0.5.1</revision>
<revision>0.6.0</revision>
<sonar.organization>azbuilder</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<maven.deploy.skip>true</maven.deploy.skip>
Expand Down
4 changes: 2 additions & 2 deletions terraform-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.8</version>
<version>2.5.10</version>
</parent>

<groupId>org.azbuilder.terraform</groupId>
Expand All @@ -19,7 +19,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<revision>0.5.1</revision>
<revision>0.6.0</revision>
<maven.deploy.skip>false</maven.deploy.skip>
<okhttp.version>4.9.1</okhttp.version>
<commons-io.version>2.8.0</commons-io.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class TerraformClient implements AutoCloseable {
private static final String TERRAFORM_PARAM_BACKEND = "-backend-config=";
private static final String TERRAFORM_PARAM_OUTPUT_PLAN = "-out=terraformLibrary.tfPlan";
private static final String TERRAFORM_PARAM_OUTPUT_PLAN_FILE = "terraformLibrary.tfPlan";
private static final String TERRAFORM_PARAM_DISABLE_USER_INPUT = "-input=false";

private final ExecutorService executor = Executors.newWorkStealingPool();
private final TerraformDownloader terraformDownloader = new TerraformDownloader();
Expand Down Expand Up @@ -141,12 +142,12 @@ public CompletableFuture<Boolean> apply() throws IOException {
return this.run(TerraformCommand.apply);
}

public CompletableFuture<Boolean> destroy(@NonNull String terraformVersion, @NonNull File workingDirectory, String terraformBackendConfigFileName, @NonNull Map<String, String> terraformEnvironmentVariables, @NonNull Consumer<String> outputListener, @NonNull Consumer<String> errorListener) throws IOException {
public CompletableFuture<Boolean> destroy(@NonNull String terraformVersion, @NonNull File workingDirectory, String terraformBackendConfigFileName, @NonNull Map<String, String> terraformVariables, @NonNull Map<String, String> terraformEnvironmentVariables, @NonNull Consumer<String> outputListener, @NonNull Consumer<String> errorListener) throws IOException {
return this.run(
terraformVersion,
workingDirectory,
terraformBackendConfigFileName,
new HashMap<>(),
terraformVariables,
terraformEnvironmentVariables,
outputListener,
errorListener,
Expand Down Expand Up @@ -246,30 +247,42 @@ private ProcessLauncher getTerraformLauncher(String terraformVersion, File worki
if (terraformBackendConfigFileName != null) {
launcher.appendCommands(TERRAFORM_PARAM_BACKEND.concat(terraformBackendConfigFileName));
}
launcher.appendCommands(TERRAFORM_PARAM_DISABLE_USER_INPUT);
break;
case plan:
for (Map.Entry<String, String> entry : terraformVariables.entrySet()) {
launcher.appendCommands(TERRAFORM_PARAM_VARIABLE, entry.getKey().concat("=").concat(entry.getValue()));
}
launcher.appendCommands(TERRAFORM_PARAM_OUTPUT_PLAN);
launcher.appendCommands(TERRAFORM_PARAM_DISABLE_USER_INPUT);

break;
case apply:
if (terraformVariables.entrySet().isEmpty()) {
launcher.appendCommands(TERRAFORM_PARAM_AUTO_APPROVED);
launcher.appendCommands(TERRAFORM_PARAM_DISABLE_USER_INPUT);
launcher.appendCommands(TERRAFORM_PARAM_OUTPUT_PLAN_FILE);
} else {
for (Map.Entry<String, String> entry : terraformVariables.entrySet()) {
launcher.appendCommands(TERRAFORM_PARAM_VARIABLE, entry.getKey().concat("=").concat(entry.getValue()));
}
launcher.appendCommands(TERRAFORM_PARAM_AUTO_APPROVED);
launcher.appendCommands(TERRAFORM_PARAM_DISABLE_USER_INPUT);
}

break;
case destroy:
//https://www.terraform.io/upgrade-guides/0-15.html#other-minor-command-line-behavior-changes
if (version.compareTo(new ComparableVersion("0.15.0")) < 0)
launcher.appendCommands(TERRAFORM_PARAM_FORCE);
else
launcher.appendCommands(TERRAFORM_PARAM_AUTO_APPROVED);

for (Map.Entry<String, String> entry : terraformVariables.entrySet()) {
launcher.appendCommands(TERRAFORM_PARAM_VARIABLE, entry.getKey().concat("=").concat(entry.getValue()));
}

launcher.appendCommands(TERRAFORM_PARAM_DISABLE_USER_INPUT);
break;
case show:
case output:
Expand Down
4 changes: 2 additions & 2 deletions terraform-spring-boot-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.8</version>
<version>2.5.10</version>
</parent>

<groupId>org.azbuilder.terraform</groupId>
Expand All @@ -18,7 +18,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<revision>0.5.1</revision>
<revision>0.6.0</revision>
<maven.deploy.skip>false</maven.deploy.skip>
<lombok.version>1.18.20</lombok.version>
</properties>
Expand Down
4 changes: 2 additions & 2 deletions terraform-spring-boot-samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.8</version>
<version>2.5.10</version>
</parent>

<groupId>org.azbuilder.terraform.samples</groupId>
Expand All @@ -18,7 +18,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<revision>0.5.1</revision>
<revision>0.6.0</revision>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>

Expand Down
4 changes: 2 additions & 2 deletions terraform-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.8</version>
<version>2.5.10</version>
</parent>

<groupId>org.azbuilder.terraform</groupId>
Expand All @@ -13,7 +13,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<revision>0.5.1</revision>
<revision>0.6.0</revision>
<maven.deploy.skip>false</maven.deploy.skip>
</properties>

Expand Down

0 comments on commit 80a4943

Please sign in to comment.