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!
Thank you for addressing this.

The event_topics error has been fixed, but I still get errors when querying snapshot_limit or * is in the SELECT list.

```
c:steampipe(14.2)steampipe@steampipe=> SELECT * FROM aws_all.aws_directory_service_directory ;
ERROR:  rpc error: code = Unknown desc = sampleshared: operation error Directory Service: GetSnapshotLimits, https response error StatusCode: 400, RequestID: 47f0d8af-bad9-4ddd-8d9c-43c89ed9c33b, ClientException: Snapshot limits can be fetched only for VPC or Microsoft AD directories. : RequestId: 47f0d8af-bad9-4ddd-8d9c-43c89ed9c33b
Time: 1120.085 ms (00:01.120)
c:steampipe(14.2)steampipe@steampipe=> SELECT event_topics FROM sharedinto.aws_directory_service_directory ;
┌──────────────┐
│ event_topics │
├──────────────┤
│ ¤            │
│ ¤            │
│ []           │
└──────────────┘
(3 rows)

Time: 883.561 ms
c:steampipe(14.2)steampipe@steampipe=> SELECT snapshot_limit FROM sharedinto.aws_directory_service_directory ;
ERROR:  rpc error: code = Unknown desc = sharedinto: operation error Directory Service: GetSnapshotLimits, https response error StatusCode: 400, RequestID: 77313bb2-ca7f-4eb7-8187-d90d9d8c8a14, ClientException: Snapshot limits can be fetched only for VPC or Microsoft AD directories. : RequestId: 77313bb2-ca7f-4eb7-8187-d90d9d8c8a14
Time: 174.193 ms
c:steampipe(14.2)steampipe@steampipe=>
\q
spk@spkm1air ~ % steampipe plugin list                                                                                                                           ⏱233113 Tue16 115912
+--------------------------------------------+---------+--------------------+
| Installed                                  | Version | Connections        |
+--------------------------------------------+---------+--------------------+
| hub.steampipe.io/plugins/turbot/aws@latest | 0.135.0 |  [omitted]         |
|                                            |         |                    |
|                                            |         |                    |
+--------------------------------------------+---------+--------------------+

spk@spkm1air ~ %
```

Fix patch:
diff --git a/aws/table_aws_directory_service_directory.go b/aws/table_aws_directory_service_directory.go
index cfd6b12e7..3a0830e99 100644
--- a/aws/table_aws_directory_service_directory.go
+++ b/aws/table_aws_directory_service_directory.go
@@ -8,6 +8,7 @@ import (
 	"github.com/aws/aws-sdk-go-v2/service/directoryservice/types"
 
 	directoryservicev1 "github.com/aws/aws-sdk-go/service/directoryservice"
+	"github.com/turbot/go-kit/helpers"
 
 	"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
 	"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
@@ -389,9 +390,10 @@ 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
+	// This operation is not supported for for Shared MicrosoftAD and ADConnector 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" {
+	supportedDirectoryType := []string{"SimpleAD", "MicrosoftAD"}
+	if !helpers.StringSliceContains(supportedDirectoryType, string(directory.Type)) {
 		return nil, nil
 	}
 


Test patch: