Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

Commit

Permalink
Fix e34d920: Call to ListAccounts in a non-org user (#337) (#349)
Browse files Browse the repository at this point in the history
Co-authored-by: Kemal Hadimli <disq@users.noreply.github.com>
  • Loading branch information
disq and disq authored Dec 15, 2021
1 parent eee6086 commit 3b9b148
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions resources/organizations_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/organizations"
"github.com/aws/aws-sdk-go-v2/service/organizations/types"
"github.com/aws/smithy-go"

"github.com/cloudquery/cq-provider-aws/client"

Expand Down Expand Up @@ -79,9 +79,12 @@ func fetchOrganizationsAccounts(ctx context.Context, meta schema.ClientMeta, par
var input organizations.ListAccountsInput
for {
response, err := svc.ListAccounts(ctx, &input)
var ade *types.AccessDeniedException
if errors.As(err, &ade) {
return diag.FromError(err, diag.IGNORE, diag.ACCESS, OrganizationsAccounts().Name, client.ParseSummaryMessage(c.Accounts, err, ade), "Missing permissions or account might not be root/organizational unit.")
var ae smithy.APIError
if errors.As(err, &ae) {
switch ae.ErrorCode() {
case "AWSOrganizationsNotInUseException", "AccessDeniedException":
return diag.FromError(err, diag.IGNORE, diag.ACCESS, OrganizationsAccounts().Name, client.ParseSummaryMessage(c.Accounts, err, ae), "Missing permissions or account might not be root/organizational unit.")
}
}
if err != nil {
return err
Expand Down

0 comments on commit 3b9b148

Please sign in to comment.