From 55dfdb7c0d7c81550434faab83e9a2abe146b9bc Mon Sep 17 00:00:00 2001 From: WangLiNaruto Date: Tue, 5 Sep 2023 18:56:11 +0800 Subject: [PATCH] implement terraform-boot for validate method --- .../boot/api/TerraformApiController.java | 15 +++++++++++++++ .../service/TerraformScriptsService.java | 10 ++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/main/java/org/eclipse/xpanse/terraform/boot/api/TerraformApiController.java b/src/main/java/org/eclipse/xpanse/terraform/boot/api/TerraformApiController.java index 1332203..b34c688 100644 --- a/src/main/java/org/eclipse/xpanse/terraform/boot/api/TerraformApiController.java +++ b/src/main/java/org/eclipse/xpanse/terraform/boot/api/TerraformApiController.java @@ -126,6 +126,21 @@ public TerraformResult destroy( moduleDirectory + File.separator + UUID.randomUUID()); } + /** + * Method to validate resources by scripts. + * + * @return Returns the status of the deployment. + */ + @Tag(name = "Terraform", description = "APIs for running Terraform commands") + @Operation(description = "Deploy resources via Terraform") + @PostMapping(value = "/validate/scripts", produces = + MediaType.APPLICATION_JSON_VALUE) + @ResponseStatus(HttpStatus.OK) + public TerraformValidationResult validateWithScripts( + @Valid @RequestBody TerraformDeployWithScriptsRequest request) { + return terraformScriptsService.validateWithScripts(request); + } + /** * Method to deploy resources by scripts. * diff --git a/src/main/java/org/eclipse/xpanse/terraform/boot/terraform/service/TerraformScriptsService.java b/src/main/java/org/eclipse/xpanse/terraform/boot/terraform/service/TerraformScriptsService.java index 9392b40..e255b37 100644 --- a/src/main/java/org/eclipse/xpanse/terraform/boot/terraform/service/TerraformScriptsService.java +++ b/src/main/java/org/eclipse/xpanse/terraform/boot/terraform/service/TerraformScriptsService.java @@ -19,6 +19,7 @@ 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; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; @@ -50,6 +51,15 @@ public TerraformScriptsService(TerraformExecutor executor, RestTemplate restTemp } + /** + * Method of deployment a service using a script. + */ + public TerraformValidationResult validateWithScripts( + TerraformDeployWithScriptsRequest request) { + String moduleDirectory = buildDeployEnv(request.getScripts()); + return tfValidateFromDirectory(moduleDirectory); + } + /** * Method of deployment a service using a script. */