From afdb7263611f2f0bfc9eb4ca2bf0f13a2c3adfca Mon Sep 17 00:00:00 2001 From: Andreas Sommer Date: Tue, 12 Sep 2023 12:44:39 +0200 Subject: [PATCH] Support arm64 installation of etcd (#91) --- service/etcd/main.tf | 10 +++++++--- service/etcd/scripts/install.sh | 24 +++++++++++++++++++----- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/service/etcd/main.tf b/service/etcd/main.tf index a5c6751..3e492b2 100644 --- a/service/etcd/main.tf +++ b/service/etcd/main.tf @@ -38,11 +38,15 @@ resource "null_resource" "etcd" { agent = true } + provisioner "file" { + source = "${path.module}/scripts/install.sh" + destination = "/tmp/install-etcd.sh" + } + provisioner "remote-exec" { inline = [ - templatefile("${path.module}/scripts/install.sh", { - version = var.etcd_version - }) + "chmod +x /tmp/install-etcd.sh", + "/tmp/install-etcd.sh '${var.etcd_version}'" ] } diff --git a/service/etcd/scripts/install.sh b/service/etcd/scripts/install.sh index 7f6ea4b..ad532ec 100644 --- a/service/etcd/scripts/install.sh +++ b/service/etcd/scripts/install.sh @@ -1,9 +1,23 @@ #!/bin/sh -set -e +set -eu -rm -f /opt/etcd-${version}-linux-amd64.tar.gz +[ $# = 1 ] || { >&2 echo "Usage: ${0} ETCD_VERSION"; exit 1; } + +version="${1}" +if ! echo "${version}" | grep -qE '^v[0-9]'; then + >&2 printf "ERROR: Must provide valid etcd version, got \`%s\`\n" "${version}" + exit 1 +fi + +arch="$(arch | sed 's/x86_64/amd64/; s/aarch64/arm64/')" + +rm -f "/opt/etcd-${version}-linux-${arch}.tar.gz" rm -rf /opt/etcd && mkdir -p /opt/etcd -curl -L https://storage.googleapis.com/etcd/${version}/etcd-${version}-linux-amd64.tar.gz \ - -o /opt/etcd-${version}-linux-amd64.tar.gz -tar xzvf /opt/etcd-${version}-linux-amd64.tar.gz -C /opt/etcd --strip-components=1 +( + set -x + curl --fail-with-body -L "https://storage.googleapis.com/etcd/${version}/etcd-${version}-linux-${arch}.tar.gz" \ + -o "/opt/etcd-${version}-linux-${arch}.tar.gz" + tar xzvf "/opt/etcd-${version}-linux-${arch}.tar.gz" -C /opt/etcd --strip-components=1 + rm "/opt/etcd-${version}-linux-${arch}.tar.gz" +)