How to install terraform 0.12 in an alpine container with apk?
Asked Answered
G

3

14

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?

Gastric answered 24/7, 2020 at 20:26 Comment(1)
Use the Terraform Docker image instead.Sherrillsherrington
G
26

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
Gastric answered 24/7, 2020 at 21:13 Comment(1)
After doing these commands, running terraform does not work because it cannot be found.Endpaper
B
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.

Bors answered 9/2, 2022 at 11:22 Comment(4)
This is the better solution, because it automatically picks the latest stable version.Tumbling
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.Endpaper
Thanks @Endpaper -- You're right about the clarification so I've added it to the answer to make it more explicit.Bors
If need special the version, try this command apk add terraform=1.2.5-r0 --repository=https://dl-cdn.alpinelinux.org/alpine/edge/communityUpi
A
1

For example:

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

where 3.12 is apk's branch

Allhallows answered 28/8, 2020 at 13:37 Comment(4)
The latest would be: apk add terraform --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main But still, it gives outdated v0.12.25Argyll
@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_64Allhallows
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.htmlArgyll
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.5Argyll

© 2022 - 2024 — McMap. All rights reserved.