13

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?

β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
Alex Cohen
  • 5,596
  • 16
  • 54
  • 104

3 Answers3

25

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
Alex Cohen
  • 5,596
  • 16
  • 54
  • 104
  • After doing these commands, running terraform does not work because it cannot be found. – Essej Mar 24 '22 at 17:22
8

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.

P. Šileikis
  • 724
  • 1
  • 12
  • 26
Software Engineer
  • 15,457
  • 7
  • 74
  • 102
  • This is the better solution, because it automatically picks the latest stable version. – Gerrit Brouwer Feb 24 '22 at 08:53
  • 1
    Just to be clear, doing this means that you are installing the latest terraform version from the Alpine repository. So you cannot really choose which terraform version you want, you are bound to be using the one that is in the repository. – Essej Mar 24 '22 at 17:24
  • Thanks @Essej -- You're right about the clarification so I've added it to the answer to make it more explicit. – Software Engineer Mar 29 '22 at 10:29
  • If need special the version, try this command `apk add terraform=1.2.5-r0 --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community` – BMW Jul 24 '22 at 12:11
1

For example:

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

where 3.12 is apk's branch

SantaXL
  • 618
  • 8
  • 19
  • The latest would be: `apk add terraform --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main` But still, it gives outdated `v0.12.25` – Vladimir Vukanac Oct 23 '20 at 12:31
  • 1
    @VladimirVukanac that's incorrect. Open in your browser `http://dl-cdn.alpinelinux.org/alpine/edge/main` - outdated 0.12.25. But if you open `http://dl-cdn.alpinelinux.org/alpine/edge/community`, you've got the latest version. In other words, use `apk add terraform --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community`. Check `repository` column on this site: `https://pkgs.alpinelinux.org/packages?name=terraform&branch=edge&arch=x86_64` – SantaXL Oct 23 '20 at 13:17
  • Maybe I did something wrong during the process, but purely by running this in Dockerfile I got that version. Here is an example: `docker run --rm -it $(echo "FROM alpine\nRUN apk add terraform --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main" | docker build -q - ) sh -c "terraform --version"` The result is: `Terraform v0.12.25 Your version of Terraform is out of date! The latest version is 0.13.5. You can update by downloading from https://www.terraform.io/downloads.html` – Vladimir Vukanac Oct 25 '20 at 21:56
  • Nice! Thanks! This: `docker run --rm -it $(echo "FROM alpine\nRUN apk add terraform --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community" | docker build -q - ) sh -c "terraform --version"` gives the latest version: `Terraform v0.13.5` – Vladimir Vukanac Oct 29 '20 at 08:28