terraform-switcher
terraform-switcher copied to clipboard
Alpine linux compatible version
Installer does not install a correct version for alpine linux.
Alpine linux does not support musl and therefore needs a different compilation target.
Here's a simple docker to build it on alpine:
FROM alpine:3.11 AS build
RUN apk upgrade -U -a && \
apk upgrade && \
apk add --update go gcc g++ git ca-certificates curl make && \
git clone https://github.com/warrensbox/terraform-switcher.git /app
WORKDIR /app
RUN CGO_ENABLED=1 GOOS=linux go build
s/musl/glibc/
The above builder works great for a multi-stage docker image, where you can just COPY --from=build /app/terraform-switcher /usr/local/bin/tfswitch in a later image.
Also, if you want to 'pre-populate' your alpine based docker image with a terraform version so that tfswitch doesn't need to download it on each run:
ENV TERRAFORM_VERSION=0.14.7
RUN curl -L -o terraform.zip https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip \
&& unzip terraform.zip \
&& rm terraform.zip \
&& mkdir -p /root/.terraform.versions \
&& mv terraform /root/.terraform.versions/terraform_${TERRAFORM_VERSION}
repeat as needed for other TERRAFORM_VERSION's. Or make a loop and iterate through a list (tho that will blow the docker image cache if you change the list to add a new version).
It would be great oh have a tfswitch Dockerhub image that can just be pulled in CI. This way every new version releasse would also create a new Docker (latest) image.
@llamahunter
Also, if you want to 'pre-populate' your alpine based docker image with a terraform version so that tfswitch doesn't need to download it on each run:
Ain't it going to be a bit more straightforward to make use of tfswitch to pre-populate your docker image with needed TF versions? 😄 Something like this:
RUN curl_cmd_to_install_tfswitch
RUN for TF_VER in 0.14.7 0.15.3 …; do tfswitch ${TF_VER}; done; tfswitch <TF_VER_TO_USE_BY_DEFAULT>
I think pre-populating the image with a specific version defeats the purpose of tfswitch :)
Well, it depends on the security policies and all that stuff: imagine your build server has access to pre-approved external endpoints but your CI has not (or an approval is required from security team for all the external stuff you bundle into container image) — here comes the need to embed stuff into container image at buildtime rather than downloading it at runtime and tfswitch helps to switch between known in advance versions of TF. I'd say this is the use case of big corporations which sometime are referred as "bloody enterprises" =)
@llamahunter
Also, if you want to 'pre-populate' your alpine based docker image with a terraform version so that tfswitch doesn't need to download it on each run:
Ain't it going to be a bit more straightforward to make use of
tfswitchto pre-populate your docker image with needed TF versions? 😄 Something like this:
Ah, yeah, that seems a bit simpler. Just use tfswitch to download the binaries itself when building the image.
I think pre-populating the image with a specific version defeats the purpose of tfswitch :)
Er... not really. depends on your use case. This is an image used elsewhere. We know that many users will be using specific versions of terraform. Rather than EVERY execution needing to download those versions OVER AND OVER, we download them once and bake them in to the image.
@llamahunter - What do you think of my above comment regarding a dockerhub image? Please add a 👍 or 👎 . Should I open a separate issue for that?
Ideally, for us, it would be a binary installable from https://pkgs.alpinelinux.org/packages.
@llamahunter Ideally, I would like to create an Alpine linux binary. Similar to https://aur.archlinux.org/packages/tfswitch
where users can install with yay:
# compiled from source
yay tfswitch
# precompiled
yay tfswitch-bin
I'll look into this for Alpine linux
@barakbd I looked your docker MR. I have some suggestions. I will reach out to you soon.