Skip to content
Snippets Groups Projects
Commit f626e34a authored by Timo Furrer's avatar Timo Furrer
Browse files

Merge branch 'issue-128' into 'main'

fix var_file related error in older tofu versions #128

Closes #128

See merge request components/opentofu!276
parents 02975cf2 6a0caec1
No related branches found
No related tags found
No related merge requests found
Pipeline #272647 failed
......@@ -25,6 +25,7 @@ RUN apk add --no-cache \
# see https://opentofu.org/docs/intro/install/standalone
# We may want to switch to installing manually from GitHub and verifying signature
ARG OPENTOFU_VERSION
ENV OPENTOFU_VERSION=${OPENTOFU_VERSION}
RUN curl --proto '=https' --tlsv1.2 -fsSL https://get.opentofu.org/install-opentofu.sh -o install-opentofu.sh && \
chmod +x install-opentofu.sh && \
./install-opentofu.sh --install-method standalone --opentofu-version "${OPENTOFU_VERSION}" && \
......
......@@ -40,6 +40,7 @@ RUN wget https://gitlab.com/gitlab-org/cli/-/releases/v${GLAB_VERSION}/downloads
# see https://opentofu.org/docs/intro/install/standalone
# We may want to switch to installing manually from GitHub and verifying signature
ARG OPENTOFU_VERSION
ENV OPENTOFU_VERSION=${OPENTOFU_VERSION}
RUN curl --proto '=https' --tlsv1.2 -fsSL https://get.opentofu.org/install-opentofu.sh -o install-opentofu.sh && \
chmod +x install-opentofu.sh && \
./install-opentofu.sh --install-method standalone --opentofu-version "${OPENTOFU_VERSION}" && \
......
......@@ -231,6 +231,11 @@ fi
# Helper functions
# ================
# is_tofu_at_least checks if OPENTOFU_VERSION is at least the one provided
is_tofu_at_least() {
test "$(printf "%s\n$1" "$OPENTOFU_VERSION" | sort -V | head -1)" = "$1"
}
# define_http_backend defines the HTTP backend in a file called __gitlab-opentofu-backend.tf if no backend can be found.
# The backend configuration is attempted to be found with a simple grep.
define_http_backend() {
......@@ -430,6 +435,11 @@ if [ $sourced -eq 0 ]; then
;;
"validate")
$should_do_implicit_init && tofu_init -backend=false
if ! is_tofu_at_least "1.8.0"; then
var_file_args=""
fi
# shellcheck disable=SC2086
tofu "${tf_chdir_opt}" "${@}" ${var_file_args}
;;
......@@ -440,6 +450,11 @@ if [ $sourced -eq 0 ]; then
;;
"graph")
$should_do_implicit_init && tofu_init
if ! is_tofu_at_least "1.8.0"; then
var_file_args=""
fi
# shellcheck disable=SC2086
tofu "${tf_chdir_opt}" "${@}" ${var_file_args}
;;
......
......@@ -230,3 +230,16 @@ EOF
$SHELL test.sh
}
@test "is_tofu_at_least helper function" {
load $(which gitlab-tofu)
OPENTOFU_VERSION="1.9.1" run is_tofu_at_least "1.8.0"
assert_success
OPENTOFU_VERSION="1.8.0" run is_tofu_at_least "1.8.0"
assert_success
OPENTOFU_VERSION="1.6.3" run is_tofu_at_least "1.8.0"
assert_failure
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment