@@ -3,6 +3,7 @@ package provider
33import (
44 "context"
55 "fmt"
6+ "os"
67 "os/exec"
78 "sort"
89 "strings"
@@ -72,11 +73,16 @@ var (
7273func mkAWS (conf config.Config ) (provider * AWSProvider , err error ) {
7374 ctx := context .Background ()
7475
75- iamSession , err := GetAWSCallerIdentity (ctx )
76+ iamSession , callerIdentity , err := GetAWSCallerIdentity (ctx )
7677 if err != nil {
7778 return nil , plrlErrors .ErrorWrap (err , "Failed to get AWS caller identity" )
7879 }
7980
81+ fmt .Printf ("\n Using %s AWS profile\n " , getAWSProfileName ())
82+ fmt .Printf ("Caller identity ARN: %s\n " , lo .FromPtr (callerIdentity .Arn ))
83+ fmt .Printf ("Caller identity account: %s\n " , lo .FromPtr (callerIdentity .Account ))
84+ fmt .Printf ("Caller identity user ID: %s\n \n " , lo .FromPtr (callerIdentity .UserId ))
85+
8086 provider = & AWSProvider {
8187 goContext : & ctx ,
8288 ctx : map [string ]any {
@@ -402,29 +408,41 @@ func (aws *AWSProvider) testIamPermissions() error {
402408 return fmt .Errorf ("you do not meet all required iam permissions to deploy an eks cluster: %s, this is not necessarily a full list, we recommend using as close to AdministratorAccess as possible to run plural" , strings .Join (missing , "," ))
403409}
404410
411+ func getAWSProfileName () string {
412+ if profile := os .Getenv ("AWS_PROFILE" ); profile != "" {
413+ return profile
414+ }
415+
416+ if profile := os .Getenv ("AWS_DEFAULT_PROFILE" ); profile != "" {
417+ return profile
418+ }
419+
420+ return "default"
421+ }
422+
405423// GetAWSCallerIdentity returns the IAM role ARN of the current caller identity.
406- func GetAWSCallerIdentity (ctx context.Context ) (string , error ) {
424+ func GetAWSCallerIdentity (ctx context.Context ) (string , * sts. GetCallerIdentityOutput , error ) {
407425 cfg , err := getAwsConfig (ctx )
408426 if err != nil {
409- return "" , err
427+ return "" , nil , err
410428 }
411429
412430 svc := sts .NewFromConfig (cfg )
413431 callerIdentity , err := svc .GetCallerIdentity (ctx , & sts.GetCallerIdentityInput {})
414432 if err != nil {
415- return "" , plrlErrors .ErrorWrap (err , "Error getting caller identity: " )
433+ return "" , callerIdentity , plrlErrors .ErrorWrap (err , "Error getting caller identity: " )
416434 }
417435
418436 callerIdentityArn := lo .FromPtr (callerIdentity .Arn )
419437 roleName , _ := RoleNameSessionFromARN (callerIdentityArn )
420438 if ! lo .IsEmpty (roleName ) {
421439 role , err := iam .NewFromConfig (cfg ).GetRole (ctx , & iam.GetRoleInput {RoleName : & roleName })
422440 if err != nil {
423- return "" , plrlErrors .ErrorWrap (err , "Error getting IAM role: " )
441+ return "" , callerIdentity , plrlErrors .ErrorWrap (err , "Error getting IAM role: " )
424442 }
425443
426- return lo .FromPtr (role .Role .Arn ), nil
444+ return lo .FromPtr (role .Role .Arn ), callerIdentity , nil
427445 }
428446
429- return callerIdentityArn , nil
447+ return callerIdentityArn , callerIdentity , nil
430448}
0 commit comments