From e77b48c2a9b44855846a19feb29b51123cb865d0 Mon Sep 17 00:00:00 2001 From: Sivaram Sajeev Date: Wed, 12 Oct 2022 01:43:18 +0530 Subject: [PATCH 1/4] Default version flag added --- README.md | 5 +++++ main.go | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/README.md b/README.md index 5eb459aa..3f444481 100644 --- a/README.md +++ b/README.md @@ -169,6 +169,11 @@ tfswitch -c terraform_dir To install from a remote mirror other than the default(https://releases.hashicorp.com/terraform). Use the `-m` or `--mirror` parameter. Ex: `tfswitch --mirror https://example.jfrog.io/artifactory/hashicorp` +### Set a default TF version to pick +1. Help the CI systems to default to a version in case version is not detected from above steps. +2. Ex: `tfswitch -d 1.2.3` or `tfswitch --default 1.2.3` installs version `1.2.3` in case no other versions could be detected. +3. Hit **Enter** to install. + ## Automation **Automatically switch with bash** diff --git a/main.go b/main.go index 6f44443e..d5c63b0a 100644 --- a/main.go +++ b/main.go @@ -63,6 +63,7 @@ func main() { mirrorURL := getopt.StringLong("mirror", 'm', defaultMirror, "Install from a remote API other than the default. Default: "+defaultMirror) chDirPath := getopt.StringLong("chdir", 'c', dir, "Switch to a different working directory before executing the given command. Ex: tfswitch --chdir terraform_project will run tfswitch in the terraform_project directory") versionFlag := getopt.BoolLong("version", 'v', "Displays the version of tfswitch") + defaultVersion := getopt.StringLong("default", 'd', defaultLatest, "Default to version to pick up. Ex: tfswitch --default 1.2.4") helpFlag := getopt.BoolLong("help", 'h', "Displays help message") _ = versionFlag @@ -211,6 +212,10 @@ func main() { fmt.Printf("Terraform version environment variable: %s\n", tfversion) installVersion(tfversion, custBinPath, mirrorURL) + /* if default version is provided - Pick this instead of going for prompt */ + case *defaultVersion != "": + installVersion(*defaultVersion, custBinPath, mirrorURL) + // if no arg is provided default: listAll := false //set list all false - only official release will be displayed From d8d713f8725c192c79b2558d02d41acc068ca1cc Mon Sep 17 00:00:00 2001 From: sivaramsajeev <44951806+sivaramsajeev@users.noreply.github.com> Date: Thu, 13 Oct 2022 01:03:56 +0530 Subject: [PATCH 2/4] Update main.go Co-authored-by: George L. Yermulnik --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index d5c63b0a..0d96c530 100644 --- a/main.go +++ b/main.go @@ -63,7 +63,7 @@ func main() { mirrorURL := getopt.StringLong("mirror", 'm', defaultMirror, "Install from a remote API other than the default. Default: "+defaultMirror) chDirPath := getopt.StringLong("chdir", 'c', dir, "Switch to a different working directory before executing the given command. Ex: tfswitch --chdir terraform_project will run tfswitch in the terraform_project directory") versionFlag := getopt.BoolLong("version", 'v', "Displays the version of tfswitch") - defaultVersion := getopt.StringLong("default", 'd', defaultLatest, "Default to version to pick up. Ex: tfswitch --default 1.2.4") + defaultVersion := getopt.StringLong("default", 'd', defaultLatest, "Default to this version in case no other versions could be detected. Ex: tfswitch --default 1.2.4") helpFlag := getopt.BoolLong("help", 'h', "Displays help message") _ = versionFlag From 8a7f5f5a7b5a6745da79d4664863359b60d0c29d Mon Sep 17 00:00:00 2001 From: "warren.veerasingam@gmail.com" Date: Sun, 5 Feb 2023 17:08:10 -0800 Subject: [PATCH 3/4] Add default or fallback version for CICD pipelines --- README.md | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3f444481..1c000856 100644 --- a/README.md +++ b/README.md @@ -169,10 +169,11 @@ tfswitch -c terraform_dir To install from a remote mirror other than the default(https://releases.hashicorp.com/terraform). Use the `-m` or `--mirror` parameter. Ex: `tfswitch --mirror https://example.jfrog.io/artifactory/hashicorp` -### Set a default TF version to pick -1. Help the CI systems to default to a version in case version is not detected from above steps. -2. Ex: `tfswitch -d 1.2.3` or `tfswitch --default 1.2.3` installs version `1.2.3` in case no other versions could be detected. +### Set a default TF version for CICD pipeline +1. When using a CICD pipeline, you may want a default or fallback version to avoid the pipe from hanging. +2. Ex: `tfswitch -d 1.2.3` or `tfswitch --default 1.2.3` installs version `1.2.3` when no other versions could be detected. 3. Hit **Enter** to install. +[Also, see CICD example](#cicd) ## Automation **Automatically switch with bash** @@ -244,7 +245,7 @@ function switch_terraform --on-event fish_postexec end end ``` - +## CICD ### Jenkins setup drawing @@ -264,6 +265,10 @@ export PATH=$PATH:$CUSTOMBIN #Add custom bin path to PATH environment $CUSTOMBIN/tfswitch -b $CUSTOMBIN/terraform 0.11.7 #or simply tfswitch -b $CUSTOMBIN/terraform 0.11.7 +#OR + +$CUSTOMBIN/tfswitch -d 0.11.7 -b $CUSTOMBIN/terraform #or simply tfswitch -d 0.11.7 -b $CUSTOMBIN/terraform + terraform -v #testing version ``` @@ -305,6 +310,9 @@ jobs: $CUSTOMBIN/tfswitch -b $CUSTOMBIN/terraform 0.11.7 #or simply tfswitch -b $CUSTOMBIN/terraform 0.11.7 + #OR + $CUSTOMBIN/tfswitch -d 0.11.7 -b $CUSTOMBIN/terraform #or simply tfswitch -d 0.11.7 -b $CUSTOMBIN/terraform + terraform -v #testing version ``` ## Order of precedence From f1c77e1defcf2064029a3a200b9cd3f975f333d0 Mon Sep 17 00:00:00 2001 From: "warren.veerasingam@gmail.com" Date: Sun, 5 Feb 2023 17:21:44 -0800 Subject: [PATCH 4/4] added fallback option --- README.md | 3 +-- www/docs/Continuous-Integration.md | 6 ++++++ www/docs/Quick-Start.md | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1c000856..2ccee01d 100644 --- a/README.md +++ b/README.md @@ -170,9 +170,8 @@ To install from a remote mirror other than the default(https://releases.hashicor Ex: `tfswitch --mirror https://example.jfrog.io/artifactory/hashicorp` ### Set a default TF version for CICD pipeline -1. When using a CICD pipeline, you may want a default or fallback version to avoid the pipe from hanging. +1. When using a CICD pipeline, you may want a default or fallback version to avoid the pipeline from hanging. 2. Ex: `tfswitch -d 1.2.3` or `tfswitch --default 1.2.3` installs version `1.2.3` when no other versions could be detected. -3. Hit **Enter** to install. [Also, see CICD example](#cicd) ## Automation diff --git a/www/docs/Continuous-Integration.md b/www/docs/Continuous-Integration.md index 62a4939e..e1f26bc9 100644 --- a/www/docs/Continuous-Integration.md +++ b/www/docs/Continuous-Integration.md @@ -17,6 +17,9 @@ export PATH=$PATH:$CUSTOMBIN #Add custom bin path to PATH environment $CUSTOMBIN/tfswitch -b $CUSTOMBIN/terraform 0.11.7 #or simply tfswitch -b $CUSTOMBIN/terraform 0.11.7 +#OR +$CUSTOMBIN/tfswitch -d 0.11.7 -b $CUSTOMBIN/terraform #or simply tfswitch -d 0.11.7 -b $CUSTOMBIN/terraform + terraform -v #testing version ``` @@ -57,6 +60,9 @@ jobs: export PATH=$PATH:$CUSTOMBIN #Add custom bin path to PATH environment $CUSTOMBIN/tfswitch -b $CUSTOMBIN/terraform 0.11.7 #or simply tfswitch -b $CUSTOMBIN/terraform 0.11.7 + + #OR + $CUSTOMBIN/tfswitch -d 0.11.7 -b $CUSTOMBIN/terraform #or simply tfswitch -d 0.11.7 -b $CUSTOMBIN/terraform terraform -v #testing version ``` \ No newline at end of file diff --git a/www/docs/Quick-Start.md b/www/docs/Quick-Start.md index fa689361..4242098d 100644 --- a/www/docs/Quick-Start.md +++ b/www/docs/Quick-Start.md @@ -118,6 +118,11 @@ tfswitch -c terraform_dir To install from a remote mirror other than the default(https://releases.hashicorp.com/terraform). Use the `-m` or `--mirror` parameter. Ex: `tfswitch --mirror https://example.jfrog.io/artifactory/hashicorp` +### Set a default TF version for CICD pipeline +1. When using a CICD pipeline, you may want a default or fallback version to avoid the pipeline from hanging. +2. Ex: `tfswitch -d 1.2.3` or `tfswitch --default 1.2.3` installs version `1.2.3` when no other versions could be detected. +[Also, see CICD example](../continuous-integration) + **Automatically switch with bash** Add the following to the end of your `~/.bashrc` file: