tfenv
tfenv copied to clipboard
Installing tfenv to use in Github Actions
``Hi there
Currently trying to get tfenv working within a docker image but seem to have hit the problem below. Even though versions have been installed previously as part of the docker build.
Interestingly installs appear to be writing out to a folder labelled "versions" not "version"
Running Image locally
runner@1c2d16aa0363:~/.tfenv/versions$ pwd
/home/runner/.tfenv/versions
runner@1c2d16aa0363:~/.tfenv/versions$ ls -l
total 36
drwxr-xr-x 2 runner runner 4096 Aug 4 14:41 0.12.0
drwxr-xr-x 2 runner runner 4096 Aug 4 14:41 0.12.29
drwxr-xr-x 2 runner runner 4096 Aug 4 14:41 0.12.6
drwxr-xr-x 2 runner runner 4096 Aug 4 14:41 0.13.0
drwxr-xr-x 2 runner runner 4096 Aug 4 14:41 0.13.5
drwxr-xr-x 2 runner runner 4096 Aug 4 14:41 0.15.0
drwxr-xr-x 2 runner runner 4096 Aug 4 14:41 1.0.0
drwxr-xr-x 2 runner runner 4096 Aug 4 14:41 1.0.2
drwxr-xr-x 2 runner runner 4096 Aug 4 14:41 1.2.0
cat: /home/runner/.tfenv/version: No such file or directory
Version could not be resolved (set by /home/runner/.tfenv/version or tfenv use <version>)
DOCKERFILE
FROM summerwind/actions-runner:latest
RUN git clone --depth=1 https://github.com/tfutils/tfenv.git ~/.tfenv \
&& sudo ln -s ~/.tfenv/bin/* /usr/local/bin
COPY ./docker/scripts/tf_versions_install.sh tf_versions_install.sh
RUN bash tf_versions_install.sh
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64-2.0.30.zip" -o "awscliv2.zip" \
&& unzip awscliv2.zip \
&& ./aws/install \
&& rm awscliv2.zip \
&& curl -fsSL https://apt.releases.hashicorp.com/gpg | apt-key add -\
&& apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main" \
&& apt-get update
RUN apt-get install -y consul vault nomad terraform unzip \
&& apt-get install --reinstall -y vault \
&& rm -rf /var/lib/apt/lists/*
USER runner
I would suggest to use the offical setup-terraform action https://github.com/hashicorp/setup-terraform The same also exists for aws-cli.
@gthomson31 I think this may just be a misunderstanding.
The versions that get installed are installed under the versions/ directory. The version file is the file that specifies the "default" version to use when not specifying a version using a .terraform-version file or using TFENV_TERRAFORM_VERSION.
If you have not configured a default, then no default will be present. It is not required to have a default version, but if you are not declaring a version to use by other means, then you will need to specify a default.
$ tfenv list
1.3.1
1.3.0
* 1.2.9 (set by /opt/tfenv/version)
1.2.8
$ rm /opt/tfenv/version
$ tfenv list
1.3.1
1.3.0
1.2.9
1.2.8
No default set. Set with 'tfenv use <version>'