From fb889cae6d02123618b62d9c4f26492ca36760e9 Mon Sep 17 00:00:00 2001 From: Kemal Hadimli Date: Thu, 22 Dec 2022 11:14:42 +0000 Subject: [PATCH] feat(aws): Fetch tags for aws_elasticache_clusters Implements #5899 --- plugins/source/aws/codegen/recipes/elasticache.go | 5 +++++ .../aws/docs/tables/aws_elasticache_clusters.md | 1 + .../aws/resources/services/elasticache/clusters.go | 5 +++++ .../services/elasticache/clusters_fetch.go | 14 ++++++++++++++ .../services/elasticache/clusters_mock_test.go | 7 +++++++ 5 files changed, 32 insertions(+) diff --git a/plugins/source/aws/codegen/recipes/elasticache.go b/plugins/source/aws/codegen/recipes/elasticache.go index 41a987f28ad86e..76f432fd859d86 100644 --- a/plugins/source/aws/codegen/recipes/elasticache.go +++ b/plugins/source/aws/codegen/recipes/elasticache.go @@ -22,6 +22,11 @@ func ElastiCacheResources() []*Resource { Resolver: `schema.PathResolver("ARN")`, Options: schema.ColumnCreationOptions{PrimaryKey: true}, }, + { + Name: "tags", + Type: schema.TypeJSON, + Resolver: `resolveClusterTags`, + }, }...), }, { diff --git a/plugins/source/aws/docs/tables/aws_elasticache_clusters.md b/plugins/source/aws/docs/tables/aws_elasticache_clusters.md index d40cac8fdf6aa2..482dcce52dc4a1 100644 --- a/plugins/source/aws/docs/tables/aws_elasticache_clusters.md +++ b/plugins/source/aws/docs/tables/aws_elasticache_clusters.md @@ -15,6 +15,7 @@ The primary key for this table is **arn**. |account_id|String| |region|String| |arn (PK)|String| +|tags|JSON| |at_rest_encryption_enabled|Bool| |auth_token_enabled|Bool| |auth_token_last_modified_date|Timestamp| diff --git a/plugins/source/aws/resources/services/elasticache/clusters.go b/plugins/source/aws/resources/services/elasticache/clusters.go index 980c4ab091cd1b..75af08b1fe1b89 100644 --- a/plugins/source/aws/resources/services/elasticache/clusters.go +++ b/plugins/source/aws/resources/services/elasticache/clusters.go @@ -32,6 +32,11 @@ func Clusters() *schema.Table { PrimaryKey: true, }, }, + { + Name: "tags", + Type: schema.TypeJSON, + Resolver: resolveClusterTags, + }, { Name: "at_rest_encryption_enabled", Type: schema.TypeBool, diff --git a/plugins/source/aws/resources/services/elasticache/clusters_fetch.go b/plugins/source/aws/resources/services/elasticache/clusters_fetch.go index 994107f10fbce4..8c39fdcee49a0e 100644 --- a/plugins/source/aws/resources/services/elasticache/clusters_fetch.go +++ b/plugins/source/aws/resources/services/elasticache/clusters_fetch.go @@ -5,6 +5,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/elasticache" + "github.com/aws/aws-sdk-go-v2/service/elasticache/types" "github.com/cloudquery/cloudquery/plugins/source/aws/client" "github.com/cloudquery/plugin-sdk/schema" ) @@ -23,3 +24,16 @@ func fetchElasticacheClusters(ctx context.Context, meta schema.ClientMeta, paren } return nil } + +func resolveClusterTags(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error { + cluster := resource.Item.(types.CacheCluster) + + svc := meta.(*client.Client).Services().Elasticache + response, err := svc.ListTagsForResource(ctx, &elasticache.ListTagsForResourceInput{ + ResourceName: cluster.ARN, + }) + if err != nil { + return err + } + return resource.Set(c.Name, client.TagsToMap(response.TagList)) +} diff --git a/plugins/source/aws/resources/services/elasticache/clusters_mock_test.go b/plugins/source/aws/resources/services/elasticache/clusters_mock_test.go index 9fc1db1a81bab5..4c17b4cac1aaf8 100644 --- a/plugins/source/aws/resources/services/elasticache/clusters_mock_test.go +++ b/plugins/source/aws/resources/services/elasticache/clusters_mock_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/aws/aws-sdk-go-v2/service/elasticache" + "github.com/aws/aws-sdk-go-v2/service/elasticache/types" "github.com/cloudquery/cloudquery/plugins/source/aws/client" "github.com/cloudquery/cloudquery/plugins/source/aws/client/mocks" "github.com/cloudquery/plugin-sdk/faker" @@ -19,7 +20,13 @@ func buildElasticacheClusters(t *testing.T, ctrl *gomock.Controller) client.Serv t.Fatal(err) } + var ta types.Tag + if err = faker.FakeObject(&ta); err != nil { + t.Fatal(err) + } + mockElasticache.EXPECT().DescribeCacheClusters(gomock.Any(), gomock.Any(), gomock.Any()).Return(&output, nil) + mockElasticache.EXPECT().ListTagsForResource(gomock.Any(), &elasticache.ListTagsForResourceInput{ResourceName: output.CacheClusters[0].ARN}, gomock.Any()).Return(&elasticache.ListTagsForResourceOutput{TagList: []types.Tag{ta}}, nil) return client.Services{ Elasticache: mockElasticache,