Skip to content

Commit

Permalink
Error was not properly handled on init session with MFA
Browse files Browse the repository at this point in the history
  • Loading branch information
jocgir committed Aug 3, 2017
1 parent 3744c29 commit 413c988
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
6 changes: 3 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/service/ssm"
"gopkg.in/yaml.v2"

"github.com/coveo/terragrunt/aws_helper"
Expand Down Expand Up @@ -64,8 +65,7 @@ func (config *tgfConfig) SetDefaultValues(refresh bool) {
if !config.complete() && (getLastRefresh(awsDisabled).Equal(time.Time{}) || refresh) {
// If we need to read the parameter store, we must init the session first to ensure that
// the credentials are only initialized once (avoiding asking multiple type the MFA)
initSession("")
parameters, err := aws_helper.GetSSMParametersByPath(parameterFolder, "")
_, err := aws_helper.InitAwsSession("")

switch err := err.(type) {
case *errors.Error:
Expand All @@ -77,7 +77,7 @@ func (config *tgfConfig) SetDefaultValues(refresh bool) {
}
}

for _, parameter := range parameters {
for _, parameter := range Must(aws_helper.GetSSMParametersByPath(parameterFolder, "")).([]*ssm.Parameter) {
config.SetValue((*parameter.Name)[len(parameterFolder)+1:], *parameter.Value)
}
}
Expand Down
7 changes: 1 addition & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func main() {
os.Setenv("TERRAGRUNT_CACHE", filepath.Join("/local", os.TempDir(), "tgf-cache"))

if *awsProfile != "" {
initSession(*awsProfile)
Must(aws_helper.InitAwsSession(*awsProfile))
}

if *loggingLevel != "" {
Expand All @@ -85,8 +85,3 @@ func main() {

callDocker(config, !*noHome, unmanaged...)
}

func initSession(profile string) {
aws_helper.InitAwsSession(profile)
os.Unsetenv("AWS_PROFILE")
}

0 comments on commit 413c988

Please sign in to comment.