Skip to content

Commit

Permalink
[AWS Orgs] Tag managment account resources (#1217)
Browse files Browse the repository at this point in the history
Use the same initialization for the management account as well.
  • Loading branch information
orestisfl authored Aug 14, 2023
1 parent cf48e5e commit 7c60421
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
22 changes: 9 additions & 13 deletions flavors/benchmark/aws_org.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,19 @@ func (a *AWSOrg) getAwsAccounts(ctx context.Context, initialCfg awssdk.Config, r
return nil, err
}

accounts := []factory.AwsAccount{
{
Identity: *rootIdentity,
Config: rootCfg,
},
}
var accounts []factory.AwsAccount
for _, identity := range accountIdentities {
var memberCfg awssdk.Config
if identity.Account == rootIdentity.Account {
continue
memberCfg = rootCfg
} else {
memberCfg = assumeRole(
stsClient,
rootCfg,
fmtIAMRole(identity.Account, memberRole),
)
}

memberCfg := assumeRole(
stsClient,
rootCfg,
fmtIAMRole(identity.Account, memberRole),
)

accounts = append(accounts, factory.AwsAccount{
Identity: identity,
Config: memberCfg,
Expand Down
26 changes: 15 additions & 11 deletions flavors/benchmark/aws_org_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ func TestAWSOrg_Initialize(t *testing.T) {
"123-" + fetching.EC2NetworkingType,
"123-" + fetching.RdsType,
"123-" + fetching.S3Type,
"test-account-" + fetching.IAMType,
"test-account-" + fetching.KmsType,
"test-account-" + fetching.TrailType,
"test-account-" + fetching.AwsMonitoringType,
"test-account-" + fetching.EC2NetworkingType,
"test-account-" + fetching.RdsType,
"test-account-" + fetching.S3Type,
"456-" + fetching.IAMType,
"456-" + fetching.KmsType,
"456-" + fetching.TrailType,
"456-" + fetching.AwsMonitoringType,
"456-" + fetching.EC2NetworkingType,
"456-" + fetching.RdsType,
"456-" + fetching.S3Type,
},
},
}
Expand Down Expand Up @@ -114,19 +114,19 @@ func Test_getAwsAccounts(t *testing.T) {
wantErr: "some error",
},
{
name: "",
name: "success",
accountProvider: mockAccountProviderWithIdentities([]cloud.Identity{
{
Account: "123",
Account: "123",
AccountAlias: "alias",
},
{
Account: "456",
AccountAlias: "alias2",
},
}),
rootIdentity: cloud.Identity{
Account: "123",
AccountAlias: "alias",
Account: "123",
},
want: []cloud.Identity{
{
Expand Down Expand Up @@ -171,6 +171,10 @@ func mockAccountProvider(err error) *awslib.MockAccountProviderAPI {
Account: "123",
AccountAlias: "some-name",
},
{
Account: "456",
AccountAlias: "some-other-name",
},
}, nil)
} else {
on.Return(nil, err)
Expand Down

0 comments on commit 7c60421

Please sign in to comment.