Skip to content

Commit

Permalink
Fix terraform destroy after version 0.15.0 use -auto-approve instead …
Browse files Browse the repository at this point in the history
…of -force
  • Loading branch information
alfespa17 committed May 15, 2021
1 parent 4ef21cb commit 50d4408
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 13 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Simply add the following dependency to your project's `pom.xml` will enable you
<dependency>
<groupId>org.azbuilder.terraform</groupId>
<artifactId>terraform-client</artifactId>
<version>0.0.3</version>
<version>0.0.6</version>
</dependency>
```

Expand Down Expand Up @@ -56,16 +56,15 @@ System.out.println(terraformDownloader.downloadTerraformVersion("0.14.9"));

TerraformClient terraformClient = new TerraformClient();

System.out.println(terraformClient.version().get());
terraformClient.setTerraformVersion("0.15.0");

System.out.println(terraformClient.version().get());
terraformClient.setTerraformVersion("0.14.9");

terraformClient.setTerraformVersion("0.14.9");
System.out.println(terraformClient.version().get());
terraformClient.setTerraformVersion("0.14.7");

terraformClient.setTerraformVersion("0.14.7");
System.out.println(terraformClient.version().get());

```

### Spring boot
Expand All @@ -76,7 +75,7 @@ Let's still use the terraform file `storage.tf` under `/some/local/path/` folder
<dependency>
<groupId>org.azbuilder.terraform</groupId>
<artifactId>terraform-spring-boot-starter</artifactId>
<version>0.0.3</version>
<version>0.0.6</version>
</dependency>
```

Expand Down Expand Up @@ -104,6 +103,7 @@ public class SpringStarterSampleApp implements CommandLineRunner {
this.terraform.setOutputListener(System.out::println);
this.terraform.setErrorListener(System.err::println);

this.terraform.setTerraformVersion("0.15.0");
this.terraform.setWorkingDirectory("/some/local/path/");
this.terraform.plan().get();
this.terraform.apply().get();
Expand Down
9 changes: 8 additions & 1 deletion terraform-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<revision>0.0.5</revision>
<revision>0.0.6</revision>
<maven.deploy.skip>false</maven.deploy.skip>
<okhttp.version>4.9.1</okhttp.version>
<commons-io.version>2.8.0</commons-io.version>
<maven-artifact.version>3.8.1</maven-artifact.version>
</properties>

<licenses>
Expand Down Expand Up @@ -104,6 +105,12 @@
<artifactId>log4j-slf4j-impl</artifactId>
</dependency>

<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>${maven-artifact.version}</version>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.azbuilder.terraform;

import lombok.extern.slf4j.Slf4j;
import org.apache.maven.artifact.versioning.ComparableVersion;

import java.io.*;
import java.nio.file.*;
Expand Down Expand Up @@ -143,6 +144,9 @@ private void checkRunningParameters() {
if (this.getWorkingDirectory() == null) {
throw new IllegalArgumentException("working directory should not be null");
}
if (this.terraformVersion == null) {
throw new IllegalArgumentException("Terraform version should not be null");
}
}

private ProcessLauncher getTerraformLauncher(TerraformCommand command) throws IOException {
Expand All @@ -156,7 +160,7 @@ private ProcessLauncher getTerraformLauncher(TerraformCommand command) throws IO

switch (command) {
case init:
if(getBackendConfig() !=null){
if (getBackendConfig() != null) {
launcher.appendCommands("-backend-config=".concat(this.getBackendConfig()));
}
break;
Expand All @@ -172,7 +176,12 @@ private ProcessLauncher getTerraformLauncher(TerraformCommand command) throws IO
launcher.appendCommands("-auto-approve");
break;
case destroy:
launcher.appendCommands("-force");
ComparableVersion version0_15_0 = new ComparableVersion("0.15.0"); //https://www.terraform.io/upgrade-guides/0-15.html#other-minor-command-line-behavior-changes
ComparableVersion version = new ComparableVersion(this.terraformVersion);
if (version.compareTo(version0_15_0) < 0)
launcher.appendCommands("-force");
else
launcher.appendCommands("-auto-approve");
break;
}
launcher.setOutputListener(this.getOutputListener());
Expand Down
2 changes: 1 addition & 1 deletion terraform-spring-boot-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

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

Expand Down
2 changes: 1 addition & 1 deletion terraform-spring-boot-samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public static void main(String[] args) throws Exception {

TerraformClient terraformClient = new TerraformClient();

System.out.println(terraformClient.version().get());
terraformClient.setTerraformVersion("0.15.0");
System.out.println(terraformClient.version().get());

terraformClient.setTerraformVersion("0.14.9");
System.out.println(terraformClient.version().get());
terraformClient.setTerraformVersion("0.14.7");
Expand Down
2 changes: 1 addition & 1 deletion terraform-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

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

Expand Down

0 comments on commit 50d4408

Please sign in to comment.