Skip to content

Commit

Permalink
erraform-boot new deploy and destroy service with script file content…
Browse files Browse the repository at this point in the history
…s in request body
  • Loading branch information
WangLiNaruto committed Aug 30, 2023
1 parent 2e6d99e commit 7426b61
Show file tree
Hide file tree
Showing 10 changed files with 389 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.xpanse.terraform.boot.models.TerraformBootSystemStatus;
import org.eclipse.xpanse.terraform.boot.models.request.TerraformDeployRequest;
import org.eclipse.xpanse.terraform.boot.models.request.TerraformDestroyRequest;
import org.eclipse.xpanse.terraform.boot.models.request.async.TerraformAsyncDeployRequest;
import org.eclipse.xpanse.terraform.boot.models.request.async.TerraformAsyncDestroyRequest;
import org.eclipse.xpanse.terraform.boot.models.request.TerraformDeployFromDirectoryRequest;
import org.eclipse.xpanse.terraform.boot.models.request.TerraformDeployWithScriptsRequest;
import org.eclipse.xpanse.terraform.boot.models.request.TerraformDestroyFromDirectoryRequest;
import org.eclipse.xpanse.terraform.boot.models.request.TerraformDestroyWithScriptsRequest;
import org.eclipse.xpanse.terraform.boot.models.request.async.TerraformAsyncDeployFromDirectoryRequest;
import org.eclipse.xpanse.terraform.boot.models.request.async.TerraformAsyncDestroyFromDirectoryRequest;
import org.eclipse.xpanse.terraform.boot.models.response.TerraformResult;
import org.eclipse.xpanse.terraform.boot.models.validation.TerraformValidationResult;
import org.eclipse.xpanse.terraform.boot.terraform.TerraformExecutor;
Expand Down Expand Up @@ -89,8 +91,10 @@ public TerraformResult deploy(
@Parameter(name = "module_directory",
description = "directory name where the Terraform module files exist.")
@PathVariable("module_directory") String moduleDirectory,
@Valid @RequestBody TerraformDeployRequest terraformDeployRequest) {
return this.terraformExecutor.deploy(terraformDeployRequest, moduleDirectory);
@Valid @RequestBody
TerraformDeployFromDirectoryRequest terraformDeployFromDirectoryRequest) {
return this.terraformExecutor.deployFromDirectory(terraformDeployFromDirectoryRequest,
moduleDirectory);
}

/**
Expand All @@ -107,41 +111,77 @@ public TerraformResult destroy(
@Parameter(name = "module_directory",
description = "directory name where the Terraform module files exist.")
@PathVariable("module_directory") String moduleDirectory,
@Valid @RequestBody TerraformDestroyRequest terraformDestroyRequest) {
return this.terraformExecutor.destroy(terraformDestroyRequest, moduleDirectory);
@Valid @RequestBody
TerraformDestroyFromDirectoryRequest terraformDestroyFromDirectoryRequest) {
return this.terraformExecutor.destroyFromDirectory(terraformDestroyFromDirectoryRequest,
moduleDirectory);
}

/**
* Method to async deploy resources requested in a workspace.
* Method to deploy resources by scripts.
*
* @return Returns the status of the deployment.
*/
@Tag(name = "Terraform", description = "APIs for running Terraform commands")
@Operation(description = "async deploy resources via Terraform")
@PostMapping(value = "/deploy/async/{module_directory}", produces =
@Operation(description = "Deploy resources via Terraform")
@PostMapping(value = "/deploy/scripts/{module_directory}", produces =
MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.ACCEPTED)
public void asyncDeploy(
@ResponseStatus(HttpStatus.OK)
public TerraformResult deployWithScripts(
@Parameter(name = "module_directory",
description = "directory name where the Terraform module files exist.")
@PathVariable("module_directory") String moduleDirectory,
@Valid @RequestBody TerraformAsyncDeployRequest asyncDeployRequest) {
terraformExecutor.asyncDeploy(asyncDeployRequest, moduleDirectory);
@Valid @RequestBody TerraformDeployWithScriptsRequest request) {
return terraformExecutor.deployWithScripts(request, moduleDirectory);
}

/**
* Method to async destroy resources requested in a workspace.
* Method to destroy resources by scripts.
*
* @return Returns the status of the destroy.
*/
@Tag(name = "Terraform", description = "APIs for running Terraform commands")
@Operation(description = "Deploy resources via Terraform")
@PostMapping(value = "/destroy/scripts/{module_directory}", produces =
MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public TerraformResult destroyWithScripts(
@Parameter(name = "module_directory",
description = "directory name where the Terraform module files exist.")
@PathVariable("module_directory") String moduleDirectory,
@Valid @RequestBody TerraformDestroyWithScriptsRequest request) {
return terraformExecutor.destroyWithScripts(request, moduleDirectory);
}

/**
* Method to async deploy resources requested in a workspace.
*/
@Tag(name = "Terraform", description = "APIs for running Terraform commands")
@Operation(description = "async deploy resources via Terraform")
@PostMapping(value = "/deploy/scripts/async/{module_directory}", produces =
MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.ACCEPTED)
public void asyncDeployWithScripts(
@Parameter(name = "module_directory", description = "directory name where the "
+ "Terraform module files exist.")
@PathVariable("module_directory") String moduleDirectory,
@Valid @RequestBody TerraformAsyncDeployFromDirectoryRequest asyncDeployRequest) {
terraformExecutor.asyncDeployWithScripts(asyncDeployRequest, moduleDirectory);
}

/**
* Method to async destroy resources requested in a workspace.
*/
@Tag(name = "Terraform", description = "APIs for running Terraform commands")
@Operation(description = "Async destroy the Terraform modules")
@DeleteMapping(value = "/destroy/async/{module_directory}",
@DeleteMapping(value = "/destroy/scripts/async/{module_directory}",
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.ACCEPTED)
public void asyncDestroy(
@Parameter(name = "module_directory",
description = "directory name where the Terraform module files exist.")
public void asyncDestroyWithScripts(
@Parameter(name = "module_directory", description = "directory name where the "
+ "Terraform module files exist.")
@PathVariable("module_directory") String moduleDirectory,
@Valid @RequestBody TerraformAsyncDestroyRequest asyncDestroyRequest) {
terraformExecutor.asyncDestroy(asyncDestroyRequest, moduleDirectory);
@Valid @RequestBody TerraformAsyncDestroyFromDirectoryRequest asyncDestroyRequest) {
terraformExecutor.asyncDestroyWithScripts(asyncDestroyRequest, moduleDirectory);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ public TerraformExecutorException(String message) {
public TerraformExecutorException(String message, String output) {
super("Executor Exception:" + message + System.lineSeparator() + output);
}

public TerraformExecutorException(String message, Throwable ex) {
super(message, ex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
* Data model for the terraform deploy requests.
*/
@Data
public class TerraformDeployRequest {
public class TerraformDeployFromDirectoryRequest {

@NotNull
@Schema(description = "Task ID for deployment requests deployed via script")
private String taskId;

@NotNull
@Schema(description = "Flag to control if the deployment must only generate the terraform "
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* SPDX-License-Identifier: Apache-2.0
* SPDX-FileCopyrightText: Huawei Inc.
*
*/

package org.eclipse.xpanse.terraform.boot.models.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data;

/**
* Terraform uses the request object deployed by the script.
*/
@Data
public class TerraformDeployWithScriptsRequest extends TerraformDeployFromDirectoryRequest {

@NotNull
@Schema(description = "List of script files for deployment requests deployed via scripts")
private String files;

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
* Data model for the terraform destroy requests.
*/
@Data
public class TerraformDestroyRequest {
public class TerraformDestroyFromDirectoryRequest {

@NotNull
@Schema(description = "Task ID for deployment requests deployed via script")
private String taskId;

@NotNull
@Schema(description = "Key-value pairs of regular variables that must be used to execute the "
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* SPDX-License-Identifier: Apache-2.0
* SPDX-FileCopyrightText: Huawei Inc.
*/

package org.eclipse.xpanse.terraform.boot.models.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data;

/**
* Terraform uses the request object destroy by the script.
*/
@Data
public class TerraformDestroyWithScriptsRequest extends TerraformDestroyFromDirectoryRequest {

@NotNull
@Schema(description = "List of script files for destroy requests deployed via scripts")
private String files;

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import org.eclipse.xpanse.terraform.boot.models.request.TerraformDeployRequest;
import org.eclipse.xpanse.terraform.boot.models.request.TerraformDeployWithScriptsRequest;

/**
* Data model for the terraform async deploy requests.
*/
@Data
public class TerraformAsyncDeployRequest extends TerraformDeployRequest {
public class TerraformAsyncDeployFromDirectoryRequest extends TerraformDeployWithScriptsRequest {

@NotNull
@Schema(description = "Configuration information of webhook.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import org.eclipse.xpanse.terraform.boot.models.request.TerraformDestroyRequest;
import org.eclipse.xpanse.terraform.boot.models.request.TerraformDestroyWithScriptsRequest;

/**
* Data model for the terraform async destroy requests.
*/
@Data
public class TerraformAsyncDestroyRequest extends TerraformDestroyRequest {
public class TerraformAsyncDestroyFromDirectoryRequest extends TerraformDestroyWithScriptsRequest {

@NotNull
@Schema(description = "Configuration information of webhook.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package org.eclipse.xpanse.terraform.boot.models.response;

import java.util.Map;
import lombok.Builder;
import lombok.Data;

Expand All @@ -18,6 +19,8 @@ public class TerraformResult {
private boolean isCommandSuccessful;
private String commandStdOutput;
private String commandStdError;
private String terraformState;
private Map<String, String> importantFileContentMap;


}
Loading

0 comments on commit 7426b61

Please sign in to comment.