diff --git a/Dockerfile b/Dockerfile
index b9197b2..fa1cb9f 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", "-jar","terraform-boot.jar"]
diff --git a/install_terraform.sh b/install_terraform.sh
new file mode 100644
index 0000000..d46b2bf
--- /dev/null
+++ b/install_terraform.sh
@@ -0,0 +1,31 @@
+#!/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"
+if [ -z "$TERRAFORM_VERSIONS" ]; then
+ 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"
+ unzip "terraform_${DEFAULT_TERRAFORM_VERSION}_linux_amd64.zip"
+ cp terraform /usr/bin/terraform
+ chmod +x /usr/bin/terraform
+ mv terraform "${TERRAFORM_INSTALL_PATH}/terraform-${DEFAULT_TERRAFORM_VERSION}"
+ chmod +x "${TERRAFORM_INSTALL_PATH}/terraform-${DEFAULT_TERRAFORM_VERSION}"
+ rm "terraform_${DEFAULT_TERRAFORM_VERSION}_linux_amd64.zip"
+ echo "Installed Terraform with default version ${DEFAULT_TERRAFORM_VERSION} into path ${TERRAFORM_INSTALL_PATH} successfully."
+else
+ 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"
+ unzip "terraform_${version}_linux_amd64.zip"
+ mv terraform "${TERRAFORM_INSTALL_PATH}/terraform-${version}"
+ chmod +x "${TERRAFORM_INSTALL_PATH}/terraform-${version}"
+ echo "Installed Terraform with version ${version} into path ${TERRAFORM_INSTALL_PATH} successfully."
+ done
+fi
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index b128e87..5d2d349 100644
--- a/pom.xml
+++ b/pom.xml
@@ -30,7 +30,6 @@
1.1.0
7.0.0.202409031743-r
5.4.0
- 1.18.1
3.13.0
3.5.0
3.5.0
@@ -54,7 +53,14 @@
org.springframework.boot
spring-boot-starter-web
-
+
+ org.springframework.boot
+ spring-boot-starter-cache
+
+
+ com.github.ben-manes.caffeine
+ caffeine
+
org.projectlombok
lombok
@@ -118,11 +124,6 @@
semver4j
${semver4j.version}
-
- org.jsoup
- jsoup
- ${jsoup.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..5972166 100644
--- a/src/main/java/org/eclipse/xpanse/terraform/boot/TerraformBootApplication.java
+++ b/src/main/java/org/eclipse/xpanse/terraform/boot/TerraformBootApplication.java
@@ -8,6 +8,7 @@
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;
@@ -16,6 +17,7 @@
*/
@EnableRetry
@EnableAsync
+@EnableCaching
@SpringBootApplication(exclude = {SecurityAutoConfiguration.class})
public class TerraformBootApplication {
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..894d435
--- /dev/null
+++ b/src/main/java/org/eclipse/xpanse/terraform/boot/cache/CaffeineCacheConfig.java
@@ -0,0 +1,52 @@
+/*
+ * 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 java.util.concurrent.TimeUnit;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+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";
+
+ public static final int DEFAULT_CACHE_EXPIRE_TIME_IN_MINUTES = 60;
+
+ @Value("${terraform.versions.cache.expire.time.in.minutes:60}")
+ private long terraformVersionCacheDuration;
+
+ /**
+ * 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