Skip to content

Commit

Permalink
Fix problem with hcl config files
Browse files Browse the repository at this point in the history
Add support for custom terragrunt entry-point
  • Loading branch information
jocgir committed Jan 26, 2018
1 parent defb3ef commit ab89fe5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 48 deletions.
77 changes: 36 additions & 41 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (config *TGFConfig) InitAWS(profile string) error {
// SetDefaultValues sets the uninitialized values from the config files and the parameter store
func (config *TGFConfig) SetDefaultValues() {
for _, configFile := range findConfigFiles(Must(os.Getwd()).(string)) {
var content interface{}
var content map[string]interface{}
if debug {
printfDebug(os.Stderr, "# Reading configuration from %s\n", configFile)
}
Expand All @@ -144,53 +144,48 @@ func (config *TGFConfig) SetDefaultValues() {
content = utils.MapKeyInterface2string(content).(map[string]interface{})
}

switch content := content.(type) {
case map[string]interface{}:
extract := func(key string) (result interface{}) {
result = content[key]
delete(content, key)
extract := func(key string) (result interface{}) {
result = content[key]
delete(content, key)
return
}

apply := func(content interface{}) {
if content == nil {
return
}

apply := func(content interface{}) {
if content == nil {
return
switch content := content.(type) {
case map[string]interface{}:
// We sort the keys to ensure that we alway process them in the same order
keys := make([]string, 0, len(content))
for key := range content {
keys = append(keys, key)
}
switch content := content.(type) {
case map[string]interface{}:
// We sort the keys to ensure that we alway process them in the same order
keys := make([]string, 0, len(content))
for key := range content {
keys = append(keys, key)
}
sort.Strings(keys)
for _, key := range keys {
config.SetValue(key, content[key])
}
default:
fmt.Fprintln(os.Stderr, errorString("Invalid configuration format in file %s", configFile))
sort.Strings(keys)
for _, key := range keys {
config.SetValue(key, content[key])
}
default:
fmt.Fprintln(os.Stderr, errorString("Invalid configuration format in file %s (%T)", configFile, content))
}
}

windows := extract("windows")
darwin := extract("darwin")
linux := extract("linux")
ix := extract("ix")

switch runtime.GOOS {
case "windows":
apply(windows)
case "darwin":
apply(darwin)
apply(ix)
case "linux":
apply(linux)
apply(ix)
}
apply(content)
default:
fmt.Fprintln(os.Stderr, errorString("Invalid configuration format in file %s", configFile))
windows := extract("windows")
darwin := extract("darwin")
linux := extract("linux")
ix := extract("ix")

switch runtime.GOOS {
case "windows":
apply(windows)
case "darwin":
apply(darwin)
apply(ix)
case "linux":
apply(linux)
apply(ix)
}
apply(content)
}

if awsConfigExist() {
Expand Down
4 changes: 2 additions & 2 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func callDocker(args ...string) int {

// Change the default log level for terragrunt
const logLevelArg = "--terragrunt-logging-level"
if !util.ListContainsElement(command, logLevelArg) && config.EntryPoint == "terragrunt" {
if !util.ListContainsElement(command, logLevelArg) && filepath.Base(config.EntryPoint) == "terragrunt" {
if config.LogLevel == "6" || strings.ToLower(config.LogLevel) == "full" {
config.LogLevel = "debug"
config.Environment["TF_LOG"] = "DEBUG"
Expand All @@ -40,7 +40,7 @@ func callDocker(args ...string) int {
}
}

if flushCache && config.EntryPoint == "terragrunt" {
if flushCache && filepath.Base(config.EntryPoint) == "terragrunt" {
command = append(command, "--terragrunt-source-update")
}

Expand Down
10 changes: 5 additions & 5 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ab89fe5

Please sign in to comment.