Skip to content

Commit

Permalink
improve terragrunt support #36 (fixes)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvaumoron committed Jan 30, 2024
1 parent 3016285 commit 54d3955
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 10 deletions.
4 changes: 2 additions & 2 deletions cmd/tenv/subcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func addForceRemoteAndNoInstallFlags(flags *pflag.FlagSet, conf *config.Config,
descBuilder.WriteString(params.remoteEnvName)
descBuilder.WriteString(" url")

flags.BoolVarP(&conf.ForceRemote, "force-remote", "f", false, descBuilder.String())
flags.BoolVarP(&conf.ForceRemote, "force-remote", "f", conf.ForceRemote, descBuilder.String())
flags.BoolVarP(&conf.NoInstall, "no-install", "n", conf.NoInstall, "disable installation of missing version")
}

Expand All @@ -331,7 +331,7 @@ func addKeyFlag(flags *pflag.FlagSet, params subCmdParams) {

func addRemoteUrlFlag(flags *pflag.FlagSet, conf *config.Config, params subCmdParams) {
if params.needToken {
flags.StringVarP(&conf.GithubToken, "github-token", "t", "", "GitHub token (increases GitHub REST API rate limits)")
flags.StringVarP(&conf.GithubToken, "github-token", "t", conf.GithubToken, "GitHub token (increases GitHub REST API rate limits)")
}
flags.StringVarP(params.pRemote, "remote-url", "u", *params.pRemote, "remote url to install from")
}
2 changes: 1 addition & 1 deletion cmd/tenv/tenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func initRootCmd(conf *config.Config) *cobra.Command {
}
initSubCmds(tgCmd, conf, builder.BuildTgManager(conf), tgParams)

rootCmd.AddCommand(tfCmd)
rootCmd.AddCommand(tgCmd)

return rootCmd
}
Expand Down
4 changes: 2 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ func InitConfigFromEnv() (Config, error) {
}

tgRemoteURL := os.Getenv(TgRemoteURLEnvName)
if tfRemoteURL == "" {
tfRemoteURL = defaultTerragruntGithubURL
if tgRemoteURL == "" {
tgRemoteURL = defaultTerragruntGithubURL
}

tofuRemoteURL := os.Getenv(TofuRemoteURLEnvName)
Expand Down
1 change: 0 additions & 1 deletion versionmanager/retriever/terragrunt/terragruntretriever.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ func (r *TerragruntRetriever) ListReleases() ([]string, error) {
func buildAssetNames() []string {
var nameBuilder strings.Builder
nameBuilder.WriteString(baseFileName)
nameBuilder.WriteByte('_')
nameBuilder.WriteString(runtime.GOOS)
nameBuilder.WriteByte('_')
nameBuilder.WriteString(runtime.GOARCH)
Expand Down
6 changes: 3 additions & 3 deletions versionmanager/semantic/parser/terragrunt/gruntparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const (
terraformVersionConstraintName = "terraform_version_constraint"
terragruntVersionConstraintName = "terraform_version_constraint"

msgTerraGruntErr = "Failed to read terragrunt file :"
msgTerragruntErr = "Failed to read terragrunt file :"
)

var terraformVersionPartialSchema = &hcl.BodySchema{ //nolint
Expand Down Expand Up @@ -66,13 +66,13 @@ func retrieveVersionConstraint(versionPartialShema *hcl.BodySchema, versionConst
}

if verbose {
fmt.Println(msgTerraGruntErr, err) //nolint
fmt.Println(msgTerragruntErr, err) //nolint
}

data, err = os.ReadFile(jsonName)
if err != nil {
if verbose {
fmt.Println(msgTerraGruntErr, err) //nolint
fmt.Println(msgTerragruntErr, err) //nolint
}

return "", nil
Expand Down
15 changes: 14 additions & 1 deletion versionmanager/semantic/parser/tgswitch/tgswitchparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package tgswitchparser

import (
"fmt"
"os"
"path"

Expand All @@ -30,6 +31,8 @@ const (
tomlName = ".tgswitch.toml"

versionName = "version"

msgTgSwitchErr = "Failed to read tgswitch file :"
)

func RetrieveTerraguntVersion(conf *config.Config) (string, error) {
Expand All @@ -42,6 +45,9 @@ func RetrieveTerraguntVersion(conf *config.Config) (string, error) {

return parsed[versionName], nil
}
if conf.Verbose {
fmt.Println(msgTgSwitchErr, err) //nolint
}

data, err = os.ReadFile(path.Join(conf.UserPath, tomlName))
if err == nil {
Expand All @@ -51,10 +57,17 @@ func RetrieveTerraguntVersion(conf *config.Config) (string, error) {

return parsed[versionName], nil
}
if conf.Verbose {
fmt.Println(msgTgSwitchErr, err) //nolint
}

data, err = os.ReadFile(path.Join(conf.RootPath, tomlName))
if err != nil {
return "", err
if conf.Verbose {
fmt.Println(msgTgSwitchErr, err) //nolint
}

return "", nil
}

if _, err = toml.Decode(string(data), &parsed); err != nil {
Expand Down

0 comments on commit 54d3955

Please sign in to comment.