Repository: turbot/steampipe-plugin-aws (language: go)

Issue:
Directory Service shared into account causes some queries like SELECT ... FROM aws_directory_service_directory to fail
**Describe the bug**
There are two columns in aws_directory_service_directory that cause different failures when referenced during a query in an account that is the recipient of a shared Directory Service directory from another account. This shows up when the columns are referenced explicitly or when they are part of a wildcard SELECT list.

For `event_topics` the error looks like:

`ERROR:  rpc error: code = Unknown desc = sharedinto: table 'aws_directory_service_directory' column 'event_topics' requires hydrate data from getDirectoryServiceEventTopics, which failed with error operation error Directory Service: DescribeEventTopics, https response error StatusCode: 400, RequestID: 9de4802c-8491-4222-8682-effd5682b52d, ClientException: Operation is not supported for Shared MicrosoftAD directories. : RequestId: 9de4802c-8491-4222-8682-effd5682b52d.`

For `snapshot_limit` the error looks like:

`ERROR:  rpc error: code = Unknown desc = sharedinto: operation error Directory Service: GetSnapshotLimits, https response error StatusCode: 400, RequestID: 1f33dc2a-edce-435f-b37a-a81e64edaa69, ClientException: Snapshot limits can be fetched only for VPC or Microsoft AD directories. : RequestId: 1f33dc2a-edce-435f-b37a-a81e64edaa69`

**Steampipe version (`steampipe -v`)**
v0.22.1

**Plugin version (`steampipe plugin list`)**
0.131.0

**To reproduce**
`SELECT event_topics
  FROM sharedinto.aws_directory_service_directory ;`
  
`SELECT snapshot_limit
  FROM sharedinto.aws_directory_service_directory ;`

**Expected behavior**
Unclear. Should references to those columns return NULL when the API returns the specified errors? Those columns return apparently useful data in accounts that aren't the recipients of shared Directory Services. I don't know if these columns ever could contain meaningful data when querying rows describing a Directory Service that resides in another account and has been shared with the current account.

**Additional context**
In the source account, the one the directories are shared from, these columns return data with no errors. Note the first two columns of this query against that account:

```
c:steampipe(14.2)steampipe@steampipe=> SELECT event_topics, snapshot_limit,
       CAST(shared_directories[0] -> 'ShareStatus' AS TEXT) AS shared_status
  FROM sharedfrom.aws_directory_service_directory ;
┌──────────────┬─────────────────────────────────────────────────────────────────────────────────────────────────────┬───────────────┐
│ event_topics │                                           snapshot_limit                                            │ shared_status │
├──────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────┼───────────────┤
│ []           │ {"ManualSnapshotsLimit": 5, "ManualSnapshotsCurrentCount": 0, "ManualSnapshotsLimitReached": false} │ ¤             │
│ []           │ {"ManualSnapshotsLimit": 5, "ManualSnapshotsCurrentCount": 0, "ManualSnapshotsLimitReached": false} │ "Shared"      │
└──────────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────┴───────────────┘
(2 rows)

Time: 938.755 ms
c:steampipe(14.2)steampipe@steampipe=>
```



Discussion / hints:
Hi @spkendall, sorry to see that you are running into the issues. I'll look into it and let you know if I need more information from you.

Thank You!

Fix patch:
diff --git a/aws/table_aws_directory_service_directory.go b/aws/table_aws_directory_service_directory.go
index 237e58af3..cfd6b12e7 100644
--- a/aws/table_aws_directory_service_directory.go
+++ b/aws/table_aws_directory_service_directory.go
@@ -352,6 +352,12 @@ func getDirectoryServiceDirectory(ctx context.Context, d *plugin.QueryData, _ *p
 func getDirectoryServiceEventTopics(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
 	directory := h.Item.(types.DirectoryDescription)
 
+	// This operation is not supported for for Shared MicrosoftAD directories
+	// Error: aws: operation error Directory Service: DescribeEventTopics, https response error StatusCode: 400, ClientException: Operation is not supported for Shared MicrosoftAD directories.
+	if directory.Type == "SharedMicrosoftAD" {
+		return nil, nil
+	}
+
 	// Create service
 	svc, err := DirectoryServiceClient(ctx, d)
 	if err != nil {
@@ -383,6 +389,12 @@ func getDirectoryServiceEventTopics(ctx context.Context, d *plugin.QueryData, h
 func getDirectoryServiceSnapshotLimit(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
 	directory := h.Item.(types.DirectoryDescription)
 
+	// This operation is not supported for for Shared MicrosoftAD directories
+	// Error: aws: operation error Directory Service: GetSnapshotLimits, https response error StatusCode: 400, ClientException: Snapshot limits can be fetched only for VPC or Microsoft AD directories.
+	if directory.Type == "SharedMicrosoftAD" {
+		return nil, nil
+	}
+
 	// Create service
 	svc, err := DirectoryServiceClient(ctx, d)
 	if err != nil {


Test patch: