Skip to content

Commit

Permalink
Merge branch 'rds-tags-fix-arn' of https://github.com/Ticketmaster/te…
Browse files Browse the repository at this point in the history
…rraform-provider-aws into Ticketmaster-rds-tags-fix-arn
  • Loading branch information
bflad committed Jul 12, 2018
2 parents 8511849 + b8cbeee commit 90538bc
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions aws/auth_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ import (

func GetAccountID(iamconn *iam.IAM, stsconn *sts.STS, authProviderName string) (string, error) {
var errors error

// First, try STS GetCallerIdentity
log.Println("[DEBUG] Trying to get account ID via sts:GetCallerIdentity")
outCallerIdentity, err := stsconn.GetCallerIdentity(&sts.GetCallerIdentityInput{})
if err == nil {
return parseAccountIDFromArn(*outCallerIdentity.Arn)
}
log.Printf("[DEBUG] Getting account ID via sts:GetCallerIdentity failed: %s", err)
errors = multierror.Append(errors, err)

// If we have creds from instance profile, we can use metadata API
if authProviderName == ec2rolecreds.ProviderName {
log.Println("[DEBUG] Trying to get account ID via AWS Metadata API")
Expand Down Expand Up @@ -67,15 +77,6 @@ func GetAccountID(iamconn *iam.IAM, stsconn *sts.STS, authProviderName string) (
log.Printf("[DEBUG] Getting account ID via iam:GetUser failed: %s", err)
}

// Then try STS GetCallerIdentity
log.Println("[DEBUG] Trying to get account ID via sts:GetCallerIdentity")
outCallerIdentity, err := stsconn.GetCallerIdentity(&sts.GetCallerIdentityInput{})
if err == nil {
return parseAccountIDFromArn(*outCallerIdentity.Arn)
}
log.Printf("[DEBUG] Getting account ID via sts:GetCallerIdentity failed: %s", err)
errors = multierror.Append(errors, err)

// Then try IAM ListRoles
log.Println("[DEBUG] Trying to get account ID via iam:ListRoles")
outRoles, err := iamconn.ListRoles(&iam.ListRolesInput{
Expand Down

0 comments on commit 90538bc

Please sign in to comment.