terraform-switcher icon indicating copy to clipboard operation
terraform-switcher copied to clipboard

feat: allow to show required by module version explicitly

Open ikorchynskyi opened this issue 1 year ago • 5 comments

Proposed changes simplify the possibility to use tfswitch in automation: my own use-case is to fetch the required by project terraform version and to use specific version of docker image with terraform inside the CI/CD pipeline.

Related diagnostic messages has been moved to stderr to allow output to be fetched like

$ echo "Version required by module: $(go run main.go --chdir ~/foo/ --show-latest-required)"
Reading required version from terraform file
Reading required version from constraint: ~> 1.4.0, < 1.4.5
Matched version: 1.4.4
Version required by module: 1.4.4

ikorchynskyi avatar Apr 20 '23 14:04 ikorchynskyi

Somewhat alike use case that I created issue two years ago for: https://github.com/warrensbox/terraform-switcher/issues/154

yermulnik avatar Apr 21 '23 11:04 yermulnik

  1. This feature might probably need to be reflected in README
  2. New cmdline arg should be covered with test(s) if possible please
  3. This works oddly on my end:

But seems any "--show-*" flag works in a same way when there is a .toml file provided

	case fileExists(TOMLConfigFile) || fileExists(HomeTOMLConfigFile):

in that case there is no --show flag check at all.

ikorchynskyi avatar Apr 21 '23 12:04 ikorchynskyi

  1. This works oddly on my end:

But seems any "--show-*" flag works in a same way when there is a .toml file provided

	case fileExists(TOMLConfigFile) || fileExists(HomeTOMLConfigFile):

in that case there is no --show flag check at all.

Oh, good catch. I missed this behavior =( Could you probably file an issue for this to get fixed (so that --show* flags don't actually switch TF version)? Thanks.

@warrensbox @jukie Any clue on whether this was implemented this way on purpose or this is indeed a bug?

yermulnik avatar Apr 23 '23 19:04 yermulnik

Created #302 to clarify the flags logic

ikorchynskyi avatar Apr 24 '23 11:04 ikorchynskyi