As a small distro Alpine Linux doesn’t have huge support regarding the APK
Alpine system manager package. So today I’ve decided to show you how to install Terraform on Alpine Linux.
Prerequisites
- Alpine Linux
- sudo privileges
Install Terraform on Alpine Linux
Step 1. As a first step, I’m going to create a release
variable so you should be able to always get the latest Terraform version. If you need to install a specific version just put the version number instead of the release
variable in step 2
.
sudo release=`curl -s https://api.github.com/repos/hashicorp/terraform/releases/latest | grep tag_name | cut -d: -f2 | tr -d \"\,\v | awk '{$1=$1};1'`
Step 2. Download the package.
sudo wget https://releases.hashicorp.com/terraform/${release}/terraform_${release}_linux_amd64.zip
Step 3. Unzip the file.
sudo unzip terraform_${release}_linux_amd64.zip
Step 4. Install Terraform.
sudo mv terraform /usr/bin/terraform
Step 5. Verify installation.
terraform version
Install Terraform within Alpine Linux Dockerfile
If you need to build Terraform within your Dockerfile using Alpine Linux use the following block.
FROM alpine:latest
RUN release=`curl -s https://api.github.com/repos/hashicorp/terraform/releases/latest | grep tag_name | cut -d: -f2 | tr -d \"\,\v | awk '{$1=$1};1'`
RUN wget https://releases.hashicorp.com/terraform/${release}/terraform_${release}_linux_amd64.zip
RUN unzip terraform_${release}_linux_amd64.zip
RUN mv terraform /usr/bin/terraform
Conclusion
Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.