@@ -2,6 +2,7 @@ package aws
22
33import (
44 "context"
5+ "fmt"
56
67 "github.com/aws/aws-sdk-go-v2/service/opensearch"
78 "github.com/aws/aws-sdk-go-v2/service/opensearch/types"
@@ -33,9 +34,12 @@ func tableAwsOpenSearchDomain(_ context.Context) *plugin.Table {
3334 Tags : map [string ]string {"service" : "es" , "action" : "DescribeDomain" },
3435 },
3536 {
36- Func : listOpenSearchDomainTags ,
37- Tags : map [string ]string {"service" : "es" , "action" : "ListTags" },
38- Depends : []plugin.HydrateFunc {getOpenSearchDomain },
37+ Func : listOpenSearchDomainTags ,
38+ Tags : map [string ]string {"service" : "es" , "action" : "ListTags" },
39+ },
40+ {
41+ Func : getOpenSearchDomainArn ,
42+ Tags : map [string ]string {"service" : "sts" , "action" : "GetCallerIdentity" },
3943 },
4044 },
4145 GetMatrixItemFunc : SupportedRegionMatrix (AWS_ES_SERVICE_ID ),
@@ -54,14 +58,15 @@ func tableAwsOpenSearchDomain(_ context.Context) *plugin.Table {
5458 Name : "domain_id" ,
5559 Description : "The unique identifier for the specified domain." ,
5660 Type : proto .ColumnType_STRING ,
57- Hydrate : getOpenSearchDomain ,
61+ Hydrate : getOpenSearchDomainArn ,
62+ Transform : transform .FromField ("DomainId" ),
5863 },
5964 {
6065 Name : "arn" ,
6166 Description : "The Amazon Resource Name (ARN) of the domain." ,
6267 Type : proto .ColumnType_STRING ,
63- Hydrate : getOpenSearchDomain ,
64- Transform : transform .FromField ("ARN " ),
68+ Hydrate : getOpenSearchDomainArn ,
69+ Transform : transform .FromField ("Arn " ),
6570 },
6671 {
6772 Name : "access_policies" ,
@@ -262,8 +267,8 @@ func tableAwsOpenSearchDomain(_ context.Context) *plugin.Table {
262267 Name : "akas" ,
263268 Description : resourceInterfaceDescription ("akas" ),
264269 Type : proto .ColumnType_JSON ,
265- Hydrate : getOpenSearchDomain ,
266- Transform : transform .FromField ("ARN " ).Transform (transform .EnsureStringArray ),
270+ Hydrate : getOpenSearchDomainArn ,
271+ Transform : transform .FromField ("Arn " ).Transform (transform .EnsureStringArray ),
267272 },
268273 }),
269274 }
@@ -347,13 +352,42 @@ func getOpenSearchDomain(ctx context.Context, d *plugin.QueryData, h *plugin.Hyd
347352 return data .DomainStatus , nil
348353}
349354
355+ type openSearchDomainArnData struct {
356+ Arn string
357+ DomainId string
358+ }
359+
360+ func getOpenSearchDomainArn (ctx context.Context , d * plugin.QueryData , h * plugin.HydrateData ) (interface {}, error ) {
361+ domainName := openSearchDomainName (h .Item )
362+ region := d .EqualsQualString (matrixKeyRegion )
363+
364+ commonData , err := getCommonColumns (ctx , d , h )
365+ if err != nil {
366+ plugin .Logger (ctx ).Error ("aws_opensearch_domain.getOpenSearchDomainArn" , "common_columns_error" , err )
367+ return nil , err
368+ }
369+ commonColumnData := commonData .(* awsCommonColumnData )
370+
371+ arn := fmt .Sprintf ("arn:%s:es:%s:%s:domain/%s" ,
372+ commonColumnData .Partition , region , commonColumnData .AccountId , domainName )
373+ domainId := fmt .Sprintf ("%s/%s" , commonColumnData .AccountId , domainName )
374+
375+ return & openSearchDomainArnData {Arn : arn , DomainId : domainId }, nil
376+ }
377+
350378func listOpenSearchDomainTags (ctx context.Context , d * plugin.QueryData , h * plugin.HydrateData ) (interface {}, error ) {
351- // Domain will be nil if getOpenSearchDomain returned an error but
352- // was ignored through ignore_error_codes config arg
353- if h .HydrateResults ["getOpenSearchDomain" ] == nil {
354- return nil , nil
379+ domainName := openSearchDomainName (h .Item )
380+ region := d .EqualsQualString (matrixKeyRegion )
381+
382+ commonData , err := getCommonColumns (ctx , d , h )
383+ if err != nil {
384+ plugin .Logger (ctx ).Error ("aws_opensearch_domain.listOpenSearchDomainTags" , "common_columns_error" , err )
385+ return nil , err
355386 }
356- arn := h .HydrateResults ["getOpenSearchDomain" ].(* types.DomainStatus ).ARN
387+ commonColumnData := commonData .(* awsCommonColumnData )
388+
389+ arn := fmt .Sprintf ("arn:%s:es:%s:%s:domain/%s" ,
390+ commonColumnData .Partition , region , commonColumnData .AccountId , domainName )
357391
358392 // Create Session
359393 svc , err := OpenSearchClient (ctx , d )
@@ -369,7 +403,7 @@ func listOpenSearchDomainTags(ctx context.Context, d *plugin.QueryData, h *plugi
369403
370404 // Build the params
371405 params := & opensearch.ListTagsInput {
372- ARN : arn ,
406+ ARN : & arn ,
373407 }
374408
375409 // Get call
@@ -382,6 +416,16 @@ func listOpenSearchDomainTags(ctx context.Context, d *plugin.QueryData, h *plugi
382416 return op , nil
383417}
384418
419+ func openSearchDomainName (item interface {}) string {
420+ switch v := item .(type ) {
421+ case types.DomainInfo :
422+ return * v .DomainName
423+ case * types.DomainStatus :
424+ return * v .DomainName
425+ }
426+ return ""
427+ }
428+
385429//// TRANSFORM FUNCTION
386430
387431func openSearchDomaintagListToTurbotTags (ctx context.Context , d * transform.TransformData ) (interface {}, error ) {
0 commit comments