Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ bin
# End of https://www.toptal.com/developers/gitignore/api/go

## IDEs
.vscode
.idea
.vscode
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/kreuzwerker/m1-terraform-provider-helper
go 1.19

require (
github.com/adrg/xdg v0.4.0
github.com/go-git/go-git/v5 v5.7.0
github.com/hashicorp/go-version v1.6.0
github.com/hashicorp/hcl/v2 v2.17.0
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ github.com/ProtonMail/go-crypto v0.0.0-20230518184743-7afd39499903 h1:ZK3C5DtzV2
github.com/ProtonMail/go-crypto v0.0.0-20230518184743-7afd39499903/go.mod h1:8TI4H3IbrackdNgv+92dI+rhpCaLqM0IfpgCgenFvRE=
github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ=
github.com/acomagu/bufpipe v1.0.4/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4=
github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls=
github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E=
github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tjT8=
github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
Expand Down Expand Up @@ -119,6 +121,7 @@ golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
17 changes: 7 additions & 10 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@ type Config struct {
}

const (
DefaultProvidersCacheDir = "/.m1-terraform-provider-helper"
DefaultTerraformPluginDir = "/.terraform.d/plugins"
DefaultTerraformPluginBackupDir = "/.terraform.d/plugins_backup"
DefaultTerraformRegistryURL = "https://registry.terraform.io/v1/providers/"
FileModePerm = 0777
DefaultRequestTimeoutInSeconds = 10
DefaultTerraformRegistryURL = "https://registry.terraform.io/v1/providers/"
FileModePerm = 0777
DefaultRequestTimeoutInSeconds = 10
)

func New() *App {
Expand All @@ -47,10 +44,10 @@ func New() *App {
Config: &Config{
BaseDir: BaseDir,
GoPath: GetCurrentGoPath(),
TerraformPluginDir: BaseDir + DefaultTerraformPluginDir,
TerraformPluginBackupDir: BaseDir + DefaultTerraformPluginBackupDir,
ProvidersCacheDir: BaseDir + DefaultProvidersCacheDir,
TerraformRegistryURL: DefaultTerraformRegistryURL,
TerraformPluginDir: GetTerraformPluginsPath(BaseDir),
TerraformPluginBackupDir: GetTerraformPluginsBackupPath(BaseDir),
ProvidersCacheDir: GetProvidersCachePath(BaseDir),
TerraformRegistryURL: GetTerraformRegistryURL(),
},
Out: os.Stdout,
}
Expand Down
37 changes: 37 additions & 0 deletions internal/app/utils.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package app

import (
"fmt"
"go/build"
"os"
"os/exec"
"strings"

"github.com/adrg/xdg"
)

func GetCurrentGoPath() string {
Expand All @@ -22,3 +26,36 @@ func GetCurrentGoPath() string {

return path
}

func GetTerraformPluginsPath(baseDir string) string {
return getTerraformDataPath(baseDir) + "/plugins"
}

func GetTerraformPluginsBackupPath(baseDir string) string {
return getTerraformDataPath(baseDir) + "/plugins_backup"
}

func GetProvidersCachePath(baseDir string) string {
relPath := "m1-terraform-provider-helper"
cacheDirPath, err := xdg.SearchCacheFile(relPath)
if err != nil {
return fmt.Sprintf("%s/.%s", baseDir, relPath)
}
return cacheDirPath
}

func GetTerraformRegistryURL() string {
registryURL, ok := os.LookupEnv("TF_HELPER_REGISTRY_URL")
if !ok {
return DefaultTerraformRegistryURL
}
return registryURL
}

func getTerraformDataPath(baseDir string) string {
dataDirPath, err := xdg.SearchDataFile("terraform")
if err != nil {
dataDirPath = baseDir + "/.terraform.d"
}
return dataDirPath
}