diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 6cb7047..4a71db9 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -15,7 +15,11 @@ on:
- Major Version
- Minor Version
- Patch Version
-
+ DEFAULT_TERRAFORM_VERSION:
+ type: string
+ description: Input the default version of Terraform to install
+ required: true
+ default: '1.6.0'
env:
BOT_USER_NAME: eclipse-xpanse-bot
BOT_EMAIL_ID: xpanse-bot@eclipse.org
@@ -103,7 +107,8 @@ jobs:
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.new_version.outputs.next-version }}
labels: ${{ steps.meta.outputs.labels }}
provenance: false
-
+ build-args: |
+ DEFAULT_TERRAFORM_VERSION=${{ github.event.inputs.DEFAULT_TERRAFORM_VERSION }}
- name: Push POM updates with release version
uses: EndBug/add-and-commit@v9
with:
diff --git a/Dockerfile b/Dockerfile
index b9197b2..f4893ba 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -3,10 +3,15 @@ FROM eclipse-temurin:21-jre-alpine
RUN addgroup -S terraform-boot && adduser -S -G terraform-boot terraform-boot
RUN apk update && \
apk add --no-cache unzip wget
-ENV TERRAFORM_VERSION=1.4.4
-RUN wget https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip
-RUN unzip terraform_${TERRAFORM_VERSION}_linux_amd64.zip
-RUN mv terraform /usr/bin/terraform
+
+ENV TERRAFORM_INSTALL_PATH=/opt/terraform
+ENV DEFAULT_TERRAFORM_VERSION=1.6.0
+ENV TERRAFORM_VERSIONS=1.6.0,1.7.0,1.8.0,1.9.0
+COPY install_terraform.sh /install_terraform.sh
+RUN chmod +x /install_terraform.sh
+RUN echo "Downloading and installing Terraform with multiple versions $TERRAFORM_VERSIONS into path $TERRAFORM_INSTALL_PATH"; \
+ /install_terraform.sh "$TERRAFORM_INSTALL_PATH" "$DEFAULT_TERRAFORM_VERSION" "$TERRAFORM_VERSIONS"
+
COPY target/terraform-boot-*.jar terraform-boot.jar
USER terraform-boot
-ENTRYPOINT ["java","-jar","terraform-boot.jar"]
\ No newline at end of file
+ENTRYPOINT ["java", "-Dterraform.install.dir=${TERRAFORM_INSTALL_PATH}", "-Dterraform.versions=${TERRAFORM_VERSIONS}", "-jar", "terraform-boot.jar"]
\ No newline at end of file
diff --git a/install_terraform.sh b/install_terraform.sh
new file mode 100644
index 0000000..82d3030
--- /dev/null
+++ b/install_terraform.sh
@@ -0,0 +1,42 @@
+#!/bin/sh
+if [ -z "$1" ] || [ -z "$2" ]; then
+ echo "Error:TERRAFORM_INSTALL_PATH and DEFAULT_OPENTOFU_VERSION could not be empty."
+ exit 1
+fi
+TERRAFORM_INSTALL_PATH="$1"
+DEFAULT_TERRAFORM_VERSION="$2"
+TERRAFORM_VERSIONS="$3"
+mkdir -p "${TERRAFORM_INSTALL_PATH}"
+# Install default version of Terraform in system path and custom path
+echo "Start installing Terraform with default version ${DEFAULT_TERRAFORM_VERSION}"
+wget -c "https://releases.hashicorp.com/terraform/${DEFAULT_TERRAFORM_VERSION}/terraform_${DEFAULT_TERRAFORM_VERSION}_linux_amd64.zip"
+if [ -f "terraform_${DEFAULT_TERRAFORM_VERSION}_linux_amd64.zip" ]; then
+ unzip -o "terraform_${DEFAULT_TERRAFORM_VERSION}_linux_amd64.zip"
+ cp -f terraform /usr/bin/terraform
+ chmod +x /usr/bin/terraform
+ mv -f terraform "${TERRAFORM_INSTALL_PATH}/terraform-${DEFAULT_TERRAFORM_VERSION}"
+ chmod +x "${TERRAFORM_INSTALL_PATH}/terraform-${DEFAULT_TERRAFORM_VERSION}"
+ rm -f "terraform_${DEFAULT_TERRAFORM_VERSION}_linux_amd64.zip"
+ echo "Installed Terraform with default version ${DEFAULT_TERRAFORM_VERSION} into path ${TERRAFORM_INSTALL_PATH} successfully."
+else
+ echo "Failed to download zip package of Terraform with default version terraform_${DEFAULT_TERRAFORM_VERSION}_linux_amd64.zip."
+fi
+if [ -z "$TERRAFORM_VERSIONS" ]; then
+ echo "No Terraform versions specified, skip installing Terraform versions."
+ exit 0
+fi
+# Install versions of Terraform specified in TERRAFORM_VERSIONS into custom path
+VERSIONS=$(echo "$TERRAFORM_VERSIONS" | tr ',' '\n' | tr -d ' ')
+for version in $VERSIONS; do
+ echo "Start installing Terraform with version ${version} into path ${TERRAFORM_INSTALL_PATH}"
+ wget -c "https://releases.hashicorp.com/terraform/${version}/terraform_${version}_linux_amd64.zip"
+ if [ ! -f "terraform_${version}_linux_amd64.zip" ]; then
+ echo "Failed to download zip package of Terraform with version terraform_${version}_linux_amd64.zip."
+ continue
+ fi
+ unzip -o "terraform_${version}_linux_amd64.zip"
+ mv -f terraform "${TERRAFORM_INSTALL_PATH}/terraform-${version}"
+ chmod +x "${TERRAFORM_INSTALL_PATH}/terraform-${version}"
+ rm -f "terraform_${version}_linux_amd64.zip"
+ echo "Installed Terraform with version ${version} into path ${TERRAFORM_INSTALL_PATH} successfully."
+done
diff --git a/pom.xml b/pom.xml
index 55169fc..6abe2ee 100644
--- a/pom.xml
+++ b/pom.xml
@@ -30,7 +30,7 @@
1.1.0
7.0.0.202409031743-r
5.4.0
- 1.18.1
+ 1.326
3.13.0
3.5.0
3.5.0
@@ -54,7 +54,14 @@
org.springframework.boot
spring-boot-starter-web
-
+
+ org.springframework.boot
+ spring-boot-starter-cache
+
+
+ com.github.ben-manes.caffeine
+ caffeine
+
org.projectlombok
lombok
@@ -119,9 +126,9 @@
${semver4j.version}
- org.jsoup
- jsoup
- ${jsoup.version}
+ org.kohsuke
+ github-api
+ ${github-api.version}
diff --git a/src/main/java/org/eclipse/xpanse/terraform/boot/TerraformBootApplication.java b/src/main/java/org/eclipse/xpanse/terraform/boot/TerraformBootApplication.java
index 65d6349..afb2033 100644
--- a/src/main/java/org/eclipse/xpanse/terraform/boot/TerraformBootApplication.java
+++ b/src/main/java/org/eclipse/xpanse/terraform/boot/TerraformBootApplication.java
@@ -8,14 +8,18 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
+import org.springframework.cache.annotation.EnableCaching;
import org.springframework.retry.annotation.EnableRetry;
import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.annotation.EnableScheduling;
/**
* Main entry class to terraform-boot. This class can be directly executed to start the server.
*/
@EnableRetry
@EnableAsync
+@EnableCaching
+@EnableScheduling
@SpringBootApplication(exclude = {SecurityAutoConfiguration.class})
public class TerraformBootApplication {
diff --git a/src/main/java/org/eclipse/xpanse/terraform/boot/api/controllers/TerraformBootFromDirectoryApi.java b/src/main/java/org/eclipse/xpanse/terraform/boot/api/controllers/TerraformBootFromDirectoryApi.java
index 9a7075d..6fe2657 100644
--- a/src/main/java/org/eclipse/xpanse/terraform/boot/api/controllers/TerraformBootFromDirectoryApi.java
+++ b/src/main/java/org/eclipse/xpanse/terraform/boot/api/controllers/TerraformBootFromDirectoryApi.java
@@ -26,8 +26,8 @@
import org.eclipse.xpanse.terraform.boot.models.request.directory.TerraformModifyFromDirectoryRequest;
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.TerraformVersionHelper;
import org.eclipse.xpanse.terraform.boot.terraform.service.TerraformDirectoryService;
+import org.eclipse.xpanse.terraform.boot.terraform.tool.TerraformVersionsHelper;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
@@ -79,7 +79,7 @@ public TerraformValidationResult validateFromDirectory(
@PathVariable("module_directory") String moduleDirectory,
@Parameter(name = "terraform_version",
description = "version of Terraform to execute the module files.")
- @NotBlank @Pattern(regexp = TerraformVersionHelper.TERRAFORM_REQUIRED_VERSION_REGEX)
+ @NotBlank @Pattern(regexp = TerraformVersionsHelper.TERRAFORM_REQUIRED_VERSION_REGEX)
@PathVariable("terraform_version") String terraformVersion) {
UUID uuid = UUID.randomUUID();
MDC.put(REQUEST_ID, uuid.toString());
diff --git a/src/main/java/org/eclipse/xpanse/terraform/boot/cache/CaffeineCacheConfig.java b/src/main/java/org/eclipse/xpanse/terraform/boot/cache/CaffeineCacheConfig.java
new file mode 100644
index 0000000..54f049e
--- /dev/null
+++ b/src/main/java/org/eclipse/xpanse/terraform/boot/cache/CaffeineCacheConfig.java
@@ -0,0 +1,44 @@
+/*
+ * SPDX-License-Identifier: Apache-2.0
+ * SPDX-FileCopyrightText: Huawei Inc.
+ *
+ */
+
+package org.eclipse.xpanse.terraform.boot.cache;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.cache.CacheManager;
+import org.springframework.cache.caffeine.CaffeineCacheManager;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * Caffeine cache configuration class.
+ */
+@Slf4j
+@Configuration
+public class CaffeineCacheConfig {
+
+ public static final String TERRAFORM_VERSIONS_CACHE_NAME = "TERRAFORM_VERSIONS_CACHE";
+
+ /**
+ * Config cache manager with caffeine.
+ *
+ * @return caffeineCacheManager
+ */
+ @Bean
+ public CacheManager caffeineCacheManager() {
+ CaffeineCacheManager cacheManager = new CaffeineCacheManager();
+ cacheManager.registerCustomCache(TERRAFORM_VERSIONS_CACHE_NAME,
+ getTerraformVersionsCache());
+ return cacheManager;
+ }
+
+
+ private Cache