From c117e074b54e25d05ee03d4ffb014c51841a20ce Mon Sep 17 00:00:00 2001 From: Peter Wilcsinszky Date: Tue, 11 Aug 2020 18:22:20 +0200 Subject: [PATCH] Make the installer work with AWS_PROFILE set as an environment variable (warn if overrides config file setting). (#287) --- internal/cli/command/controlplane/utils.go | 8 +++++++- internal/cli/input/secret.go | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/cli/command/controlplane/utils.go b/internal/cli/command/controlplane/utils.go index 4f75ac0f..9807bf94 100644 --- a/internal/cli/command/controlplane/utils.go +++ b/internal/cli/command/controlplane/utils.go @@ -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 { diff --git a/internal/cli/input/secret.go b/internal/cli/input/secret.go index e2f1f0eb..53e17829 100644 --- a/internal/cli/input/secret.go +++ b/internal/cli/input/secret.go @@ -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 {