Skip to content

Commit

Permalink
Make the installer work with AWS_PROFILE set as an environment variab…
Browse files Browse the repository at this point in the history
…le (warn if overrides config file setting). (#287)
  • Loading branch information
pepov authored Aug 11, 2020
1 parent 08807bc commit c117e07
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion internal/cli/command/controlplane/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,19 @@ func getImageMetadata(cpContext *cpContext, values map[string]interface{}, write

awsAccessKeyID := ""
if values["provider"] == providerEc2 || imageMeta.Custom.CredentialType == "aws" {
profile := "default"
profile := ""
assumeRole := ""
if v, ok := values["providerConfig"]; ok {
providerConfig := cast.ToStringMap(v)
profile = cast.ToString(providerConfig["profile"])
assumeRole = cast.ToString(providerConfig["assume_role"])
}
if envProfile, ok := os.LookupEnv("AWS_PROFILE"); ok {
if profile != "" {
log.Warnf("AWS profile `%s` in the providerConfig is overridden to `%s` by AWS_PROFILE env var explicitly", profile, envProfile)
}
profile = envProfile
}
log.Debug("using local AWS credentials")
id, creds, err := input.GetAmazonCredentials(profile, assumeRole)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/input/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func GetAmazonCredentials(profile string, assumeRole string) (string, map[string
// use direct auth based on exported env vars
if id, ok := os.LookupEnv("AWS_ACCESS_KEY_ID"); ok {
if profile != "" {
log.Warnf("AWS profile %s is overridden by access key id %s explicitly", profile, id)
log.Warnf("AWS profile `%s` is overridden to `%s` by AWS_ACCESS_KEY_ID env var explicitly", profile, id)
}
sess, err = session.NewSession(&aws.Config{})
} else {
Expand Down

0 comments on commit c117e07

Please sign in to comment.