Skip to content

Commit

Permalink
chore(GROW-2960): support access keys for AWS Agentless multiple scan…
Browse files Browse the repository at this point in the history
…ning regions (#1659)

* chore(GROW-2960): support custerm attributes for AWS Agentless scanning acounts

* chore: fix gitlint workflow

* chore: add sudo

* chore: another try

* chore: another try

* chore: another try
  • Loading branch information
PengyuanZhao authored Oct 15, 2024
1 parent 97a45bc commit 2d7d669
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/commit-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Install gitlint
shell: bash
run: |
python -m pip install gitlint
python -m pip install gitlint --break-system-packages
- name: Run gitlint
shell: bash
Expand Down
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 2d7d669

Please sign in to comment.