Skip to content

Commit

Permalink
Add terraform CLI
Browse files Browse the repository at this point in the history
Fixes: #200

Tested with unit tests and by downloading terraform to my Mac.

Also adds --version to "arkade get" so you can bring down
terraform 0.12.0 etc.

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
  • Loading branch information
alexellis committed Aug 28, 2020
1 parent 653c4b3 commit 08ce44c
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ and provides a fast and easy alternative to a package manager.`,
}

command.Flags().Bool("stash", true, "When set to true, stash binary in HOME/.arkade/bin/, otherwise store in /tmp/")
command.Flags().StringP("version", "v", "", "Download a specific version")

command.RunE = func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
Expand All @@ -40,6 +41,7 @@ and provides a fast and easy alternative to a package manager.`,
fmt.Println(arkadeGet + "\n" + buf)
return nil
}

var tool *get.Tool

if len(args) == 1 {
Expand All @@ -59,6 +61,10 @@ and provides a fast and easy alternative to a package manager.`,
arch, operatingSystem := env.GetClientArch()
version := ""

if command.Flags().Changed("version") {
version, _ = command.Flags().GetString("version")
}

stash, _ := command.Flags().GetBool("stash")
dlMode := get.DownloadTempDir
if stash {
Expand Down
42 changes: 42 additions & 0 deletions pkg/get/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,3 +666,45 @@ func Test_DownloadCivo(t *testing.T) {
}
}
}

func Test_DownloadTerraform(t *testing.T) {
tools := MakeTools()
name := "terraform"

tool := getTool(name, tools)

const toolVersion = "0.13.1"

tests := []test{
{os: "mingw64_nt-10.0-18362",
arch: arch64bit,
version: toolVersion,
url: `https://releases.hashicorp.com/terraform/0.13.1/terraform_0.13.1_windows_amd64.zip`,
},
{os: "linux",
arch: arch64bit,
version: toolVersion,
url: `https://releases.hashicorp.com/terraform/0.13.1/terraform_0.13.1_linux_amd64.zip`,
},
{os: "darwin",
arch: arch64bit,
version: toolVersion,
url: `https://releases.hashicorp.com/terraform/0.13.1/terraform_0.13.1_darwin_amd64.zip`,
},
{os: "linux",
arch: archARM7,
version: toolVersion,
url: `https://releases.hashicorp.com/terraform/0.13.1/terraform_0.13.1_linux_arm.zip`,
},
}

for _, tc := range tests {
got, err := tool.GetURL(tc.os, tc.arch, tc.version)
if err != nil {
t.Fatal(err)
}
if got != tc.url {
t.Errorf("want: %s, got: %s", tc.url, got)
}
}
}
22 changes: 22 additions & 0 deletions pkg/get/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,5 +361,27 @@ https://github.com/{{.Owner}}/{{.Repo}}/releases/download/{{.Version}}/{{.Name}}
https://github.com/{{.Owner}}/{{.Repo}}/releases/download/v{{.Version}}/{{.Name}}-{{.Version}}-{{$osStr}}-{{$archStr}}.{{$extStr}}`,
})

// https://releases.hashicorp.com/terraform/0.13.1/terraform_0.13.1_linux_amd64.zip
tools = append(tools,
Tool{
Owner: "hashicorp",
Repo: "terraform",
Name: "terraform",
Version: "0.13.1",
URLTemplate: `{{$arch := .Arch}}
{{- if eq .Arch "x86_64" -}}
{{$arch = "amd64"}}
{{- else if eq .Arch "armv7l" -}}
{{$arch = "arm"}}
{{- end -}}
{{$os := .OS}}
{{ if HasPrefix .OS "ming" -}}
{{$os = "windows"}}
{{- end -}}
https://releases.hashicorp.com/terraform/{{.Version}}/terraform_{{.Version}}_{{$os}}_{{$arch}}.zip`})

return tools
}

0 comments on commit 08ce44c

Please sign in to comment.