Using Terraform versions newer than 1.6.0 ¶
To use Leverage CLI with Terraform versions newer than 1.6.0 you will need to create your own docker image.
To craft such image follow these steps:
-
Create a Dockerfile in the root of your project like so:
ARG IMAGE_TAG=1.9.1-tofu-0.3.0 FROM binbash/leverage-toolbox:$IMAGE_TAG ARG TERRAFORM_VERSION ARG PLATFORM=amd64 RUN ["/bin/bash", "-c", "wget https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_${PLATFORM}.zip && \ unzip terraform_${TERRAFORM_VERSION}_linux_${PLATFORM}.zip && \ mv terraform /usr/local/bin/ && \ ln -s /usr/local/bin/terraform /bin/terraform && \ terraform --version "] ENV UNAME=leverage ARG USERID ARG GROUPID RUN groupadd -g $GROUPID -o $UNAME RUN useradd -m -u $USERID -g $GROUPID -o -s /bin/bash $UNAME RUN chown -R $USERID:$GROUPID /home/leverage USER $UNAME
-
Build the docker image using this command:
IMAGE_NAME="myimage" && \ TERRAFORM_VERSION=1.6.6 && \ PLATFORM="amd64" && \ USERID=$(id -u) && \ GROUPID=$(id -g) && \ docker build -t ${IMAGE_NAME}:${TERRAFORM_VERSION}-${USERID}-${GROUPID} --build-arg TERRAFORM_VERSION=$TERRAFORM_VERSION --build-arg PLATFORM=$PLATFORM --build-arg USERID=$USERID --build-arg GROUPID=$GROUPID .
Make sure to replace
TERRAFORM_VERSION
for the desired target Terraform versionYou can additionally change
IMAGE_NAME
andPLATFORM
for values of your choosing. Even the basebinbash/leverage-toolbox
image can be selected by providing a suitableIMAGE_TAG
build argument. -
Change the values in your
build.env
like so:
TF_IMAGE="myimage" TF_IMAGE_TAG=1.6.6
Make sure that the values match the ones set for
IMAGE_NAME
andTERRAFORM_VERSION
in the previous step. -
Now you should be able to use Leverage CLI with your desired Terraform version using the
leverage terraform
command.