Skip to content

Commit

Permalink
chore(GROW-2960): support custerm attributes for AWS Agentless scanni…
Browse files Browse the repository at this point in the history
…ng acounts
  • Loading branch information
PengyuanZhao committed Oct 15, 2024
1 parent 97a45bc commit db78b1d
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions lwgenerate/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -909,22 +909,34 @@ func createAwsProvider(args *GenerateAwsTfConfigurationArgs) ([]*hclwrite.Block,
seenAccounts := []string{}

for _, account := range accounts {
alias := fmt.Sprintf("%s-%s", account.AwsProfile, account.AwsRegion)
alias := account.AwsRegion
if account.Alias != "" {
alias = account.Alias
} else if account.AwsProfile != "" {
alias = fmt.Sprintf("%s-%s", account.AwsProfile, account.AwsRegion)
}
// Skip duplicate account
if slices.Contains(seenAccounts, alias) {
continue
}
seenAccounts = append(seenAccounts, alias)

attributes := map[string]interface{}{}
// set `access_key`, `secret_key` and `token` for single-account multiple-region Agentless
if args.Agentless {
for k, v := range args.ExtraProviderArguments {
attributes[k] = v
}
}
attributes["alias"] = alias
attributes["region"] = account.AwsRegion
if args.AwsProfile != "" {
attributes["profile"] = account.AwsProfile
}

providerBlock, err := lwgenerate.NewProvider(
"aws",
lwgenerate.HclProviderWithAttributes(map[string]interface{}{
"alias": alias,
"profile": account.AwsProfile,
"region": account.AwsRegion,
}),
lwgenerate.HclProviderWithAttributes(attributes),
).ToBlock()
if err != nil {
return nil, err
Expand Down

0 comments on commit db78b1d

Please sign in to comment.