From 15b2b4b82ded87a6c980b345a336d18473cefcbb Mon Sep 17 00:00:00 2001
From: Patrick Schratz <patrick.schratz@gmail.com>
Date: Mon, 2 Dec 2024 23:10:34 +0100
Subject: [PATCH] fix: use dynamic arch for opentofu binary downloads (#122)

---
 Containerfile.multiarch | 2 +-
 plugin/utils.go         | 4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/Containerfile.multiarch b/Containerfile.multiarch
index 00b8b93..873d778 100644
--- a/Containerfile.multiarch
+++ b/Containerfile.multiarch
@@ -26,7 +26,7 @@ ENV TOFU_VERSION="${TOFU_VERSION:-v1.8.6}"
 
 RUN apk --update add --virtual .build-deps libarchive-tools && \
     apk add --no-cache curl git openssh-client && \
-    curl -SsfL "https://github.com/opentofu/opentofu/releases/download/${TOFU_VERSION}/tofu_${TOFU_VERSION##v}_linux_amd64.zip" | \
+    curl -SsfL "https://github.com/opentofu/opentofu/releases/download/${TOFU_VERSION}/tofu_${TOFU_VERSION##v}_linux_${TARGETARCH}.zip" | \
         bsdtar -xf - -C /usr/local/bin tofu && \
     chmod 755 /usr/local/bin/tofu && \
     apk del .build-deps && \
diff --git a/plugin/utils.go b/plugin/utils.go
index 2689996..28c3121 100644
--- a/plugin/utils.go
+++ b/plugin/utils.go
@@ -9,6 +9,7 @@ import (
 	"net/http"
 	"os"
 	"path/filepath"
+	"runtime"
 	"strings"
 
 	"github.com/Masterminds/semver/v3"
@@ -24,9 +25,10 @@ func installPackage(ctx context.Context, client *http.Client, version string, ma
 	}
 
 	packageURL := fmt.Sprintf(
-		"https://github.com/opentofu/opentofu/releases/download/v%s/tofu_%s_linux_amd64.zip",
+		"https://github.com/opentofu/opentofu/releases/download/v%s/tofu_%s_linux_%s.zip",
 		semverVersion.String(),
 		semverVersion.String(),
+		runtime.GOARCH,
 	)
 
 	tmpdir, err := os.MkdirTemp("/tmp", "tofu_dl_")