After successfully installing a version it's not possible to use it ("should be impossible")
nicod-pc opened this issue · 5 comments
I get the following Error on using tfenv. Can you please take a look into it, why it happens?
The Error:
´´´
Despite successfully installing a version matching '1.2.5:^1.2.5$', a matching version could not be found in '/opt/.tfenv/versions/' - This should be pretty much impossible
´´´
How to reproduce:
- Create Dockerfile with following content:
FROM amazonlinux
ARG TF_VERSION
RUN echo $TF_VERSION
# git in order to install tfenv
RUN yum install -y git unzip
# tfenv (to use a specific terraform version)
RUN git clone --single-branch https://github.com/tfutils/tfenv.git /opt/.tfenv
# make tfenv callable during build
ENV PATH "/opt/.tfenv/bin:$PATH"
# install proper terraform version
RUN tfenv install $TF_VERSION
RUN tfenv use $TF_VERSION
- Running it with
docker build . --build-arg TF_VERSION=1.2.5
for example.
More of the Terraform Log:
Step 1/8 : FROM amazonlinux
---> fc09a443bb53
Step 2/8 : ARG TF_VERSION
---> Using cache
---> efdce6779cf8
Step 3/8 : RUN echo $TF_VERSION
---> Running in 70f6a74126e5
1.2.5
Removing intermediate container 70f6a74126e5
---> 2474faa14be7
Step 4/8 : RUN yum install -y git unzip
---> Running in 65e5dcacbe5d
Amazon Linux 2023 repository 10 MB/s | 11 MB 00:01
[... lot of installing]
Complete!
Removing intermediate container 65e5dcacbe5d
---> 4eb91320b929
Step 5/8 : RUN git clone --single-branch https://github.com/tfutils/tfenv.git /opt/.tfenv
---> Running in 2765d1863bf4
Cloning into '/opt/.tfenv'...
Removing intermediate container 2765d1863bf4
---> d76f69d16a25
Step 6/8 : ENV PATH "/opt/.tfenv/bin:$PATH"
---> Running in e53e92625e20
Removing intermediate container e53e92625e20
---> dd0bb37b51d0
Step 7/8 : RUN tfenv install $TF_VERSION
---> Running in d738a03e40ae
Installing Terraform v1.2.5
Downloading release tarball from https://releases.hashicorp.com/terraform/1.2.5/terraform_1.2.5_linux_amd64.zip
######################################################################## 100.0%
Downloading SHA hash file from https://releases.hashicorp.com/terraform/1.2.5/terraform_1.2.5_SHA256SUMS
Not instructed to use Local PGP (/opt/.tfenv/use-{gpgv,gnupg}) & No keybase install found, skipping OpenPGP signature verification
terraform_1.2.5_linux_amd64.zip: OK
Archive: /tmp/tfenv_download.dnoPEG/terraform_1.2.5_linux_amd64.zip
inflating: /opt/.tfenv/versions/1.2.5/terraform
Installation of terraform v1.2.5 successful. To make this your default version, run 'tfenv use 1.2.5'
Removing intermediate container d738a03e40ae
---> 142d29cac71e
Step 8/8 : RUN tfenv use $TF_VERSION
---> Running in a4e82562ecc9
/opt/.tfenv/libexec/tfenv-use: line 108: find: command not found
No installed versions of terraform matched '1.2.5:^1.2.5$'. Trying to install a matching version since TFENV_AUTO_INSTALL=true
Terraform v1.2.5 is already installed
/opt/.tfenv/libexec/tfenv-use: line 127: find: command not found
Despite successfully installing a version matching '1.2.5:^1.2.5$', a matching version could not be found in '/opt/.tfenv/versions/' - This should be pretty much impossible
The command '/bin/sh -c tfenv use $TF_VERSION' returned a non-zero code: 1
The reason that is breaks now seems to be an change in the amazonlinux image. With amazonlinux:2.0.20230307.0
(10th of March) it’s working, if I use amazonlinux:2023.0.20230308.0
(10th of March) or amazonlinux:2023.0.20230315.0
(16th of March) it fails.
As the older amazonlinux
image has known vulnerabilities and alternative that is working as well is debian:
FROM debian
ARG TF_VERSION
RUN apt update
RUN apt install -yq git unzip curl
RUN git clone --single-branch --depth 1 https://github.com/tfutils/tfenv.git /opt/.tfenv
ENV PATH "/opt/.tfenv/bin:$PATH"
RUN tfenv install $TF_VERSION
RUN tfenv use $TF_VERSION
/opt/.tfenv/libexec/tfenv-use: line 127: find: command not found
is the relevant problem here; if you ensure find
is installed in your image, it should work.
As debian works, I will keep it, I think. Maybe it would be good to have a list of programs tfenv depends on or checking them on startup, so no confusing messages like "This should be pretty much impossible" are printed out. If a missing find
command is the issue here, it seems that tfenv isn't correctly recognizing that find
isn't available and instead thinks that the version is missing.
This helped me. I accidentally did go install
on a project that installed a find
file, and tfenv
broke as a result. Thanks!