'How to install terraform 0.12 in an alpine container with apk?

I want to add terraform version 0.12.21 in an alpine container, but I can only add 0.11.0 using apk. If I try to add it as the desired version I get the following error:

/ # apk upgrade terraform==0.12.21-r0
OK: 192 MiB in 66 packages
/ # apk add terraform==0.12.21-r0
ERROR: unsatisfiable constraints:
  terraform-0.11.0-r0:
    breaks: world[terraform=0.12.21-r0]

How do I fix this apk error?



Solution 1:[1]

I havent found an apk solution but I can just download the desired binary and replace the existing one with the following in the dockerfile:

# upgrade terraform to 0.12.21
RUN wget https://releases.hashicorp.com/terraform/0.12.21/terraform_0.12.21_linux_amd64.zip
RUN unzip terraform_0.12.21_linux_amd64.zip && rm terraform_0.12.21_linux_amd64.zip
RUN mv terraform /usr/bin/terraform

Solution 2:[2]

I'm documenting @SantaXL's comment as an answer just to make it easier to find in the future.

apk add terraform --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community

This doesn't specifically add version 0.12, as per the question. Instead, it installs the latest version of terraform held in the Alpine repository. Note that this isn't necessarily the latest version of terraform, but it usually is.

Solution 3:[3]

For example:

apk add terraform --repository=http://dl-cdn.alpinelinux.org/alpine/v3.12/main

where 3.12 is apk's branch

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alex Cohen
Solution 2 P. Šileikis
Solution 3