pkenv use should default to .packer-version
tfenv has the ability to default to the .terraform-version file when no version is specified in the use subcommand. In other words, when I use the command pkenv use without specifying a version, I'd like it to use whatever version I've specified in .packer-version. I really like this feature and would like it added to pkenv.
% pkenv use
pkenv: pkenv-use: [ERROR] usage: pkenv use <version>
@jlosito Thanks for filling this issue. First please note that I can make the modification to be as close as possible of tfenv features .
However I don't really understand your use case. As pkenv deal with the ".packer-version" in $HOME and in project directories it's not necessary to call pkenv use. An example : I have some packer versions installed:
$ pkenv list
1.6.6
1.5.6
* 1.4.5 (set by /home/iamhsa/.local/bin/tools/pkenv/version)
$ packer version
Packer v1.4.5
Your version of Packer is out of date! The latest version
is 1.6.6. You can update by downloading from www.packer.io/downloads.html
In a directory (packer project) with some packer files I have a ".packer-version" file
$ tree -a
.
├── packer.json
└── .packer-version
$ cat .packer-version
1.6.6
In this directory pkenv switch automatically without "use" command :
$ pkenv list
* 1.6.6 (set by /home/iamhsa/workspace/work/packer/packer-1/.packer-version)
1.5.6
1.4.5
$ packer version
Packer v1.6.6
So could you please give me more informations concerning your use case ?
In an automated job, I think it looks cleaner to just issue a pkenv use.
version=$(cat .packer-version)]
pkenv install ${version}
pkenv use ${version}
packer build .
vs
pkenv use
packer build .
I personally think the bottom one looks cleaner.
In tfenv, the use installs the version if it is not already installed and does the switch aftwards.
As install command execute use command you can do :
pkenv install
packer build .
It's seems also a clean approach. No ?
With more details :
$ cat .packer-version
1.6.6
$ pkenv install && packer version
[INFO] Installing Packer v1.6.6
[INFO] Downloading release tarball from https://releases.hashicorp.com/packer/1.6.6/packer_1.6.6_linux_amd64.zip
###################################################################################################################################################################################################################### 100.0%
[INFO] Downloading SHA hash file from https://releases.hashicorp.com/packer/1.6.6/packer_1.6.6_SHA256SUMS
pkenv: pkenv-install: [WARN] No keybase install found, skipping OpenPGP signature verification
Archive: pkenv_download.zJ4Gzd/packer_1.6.6_linux_amd64.zip
inflating: /home/hugosalesses/.local/bin/tools/pkenv/versions/1.6.6/packer
[INFO] Installation of packer v1.6.6 successful
[INFO] Switching to v1.6.6
[INFO] Switching completed
Packer v1.6.6
$ packer build .
docker.alpine: output will be in this color.
docker.debian: output will be in this color.
==> docker.debian: Creating a temporary directory for sharing data...
==> docker.debian: Pulling Docker image: debian:10
==> docker.alpine: Creating a temporary directory for sharing data...
==> docker.alpine: Pulling Docker image: alpine:3.9
docker.alpine: 3.9: Pulling from library/alpine
docker.alpine: Digest: sha256:414e0518bb9228d35e4cd5165567fb91d26c6a214e9c95899e1e056fcd349011
docker.alpine: Status: Image is up to date for alpine:3.9
docker.alpine: docker.io/library/alpine:3.9
[...]
==> Wait completed after 55 seconds 508 milliseconds
==> Builds finished. The artifacts of successful builds are:
--> docker.alpine: Imported Docker image: sha256:cf0cac81444a849adf270c7d61fb30bad29e36769ffd2055c201d80d8447f146
--> docker.alpine: Imported Docker image: iamhsa/alpine-ngninx-packer-build:1.0 with tags iamhsa/alpine-ngninx-packer-build:1.0
--> docker.debian: Imported Docker image: sha256:27bec1a8cfe8050506ba13af9c7522f4099e4c14ceee63af855fd26dc5a95941
--> docker.debian: Imported Docker image: iamhsa/debian-nginxpacker-build:1.0 with tags iamhsa/debian-nginxpacker-build:1.0
@jlosito What version of tfenv do you use? I made a test and here is the result:
$ tfenv --version
tfenv 2.0.0-37-g0494129
$ tfenv list
* 0.14.4 (set by /home/hugosalesses/.local/bin/tools/tfenv/version)
0.13.6
0.12.30
0.11.14
$ cd some_dir
$ cat .terraform-version
0.14.0
$ tfenv use
/home/hugosalesses/.local/bin/tools/tfenv/libexec/tfenv-use: line 84: 1: unbound variable
It seems to be related to tfutils/tfenv#221