Skip to content

Commit 65b5093

Browse files
authored
feat(aws): Fetch tags for aws_elasticache_clusters (#5911)
Implements #5899
1 parent 8d5adc3 commit 65b5093

5 files changed

Lines changed: 32 additions & 0 deletions

File tree

plugins/source/aws/codegen/recipes/elasticache.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ func ElastiCacheResources() []*Resource {
2222
Resolver: `schema.PathResolver("ARN")`,
2323
Options: schema.ColumnCreationOptions{PrimaryKey: true},
2424
},
25+
{
26+
Name: "tags",
27+
Type: schema.TypeJSON,
28+
Resolver: `resolveClusterTags`,
29+
},
2530
}...),
2631
},
2732
{

plugins/source/aws/docs/tables/aws_elasticache_clusters.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The primary key for this table is **arn**.
1515
|account_id|String|
1616
|region|String|
1717
|arn (PK)|String|
18+
|tags|JSON|
1819
|at_rest_encryption_enabled|Bool|
1920
|auth_token_enabled|Bool|
2021
|auth_token_last_modified_date|Timestamp|

plugins/source/aws/resources/services/elasticache/clusters.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/source/aws/resources/services/elasticache/clusters_fetch.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/aws/aws-sdk-go-v2/aws"
77
"github.com/aws/aws-sdk-go-v2/service/elasticache"
8+
"github.com/aws/aws-sdk-go-v2/service/elasticache/types"
89
"github.com/cloudquery/cloudquery/plugins/source/aws/client"
910
"github.com/cloudquery/plugin-sdk/schema"
1011
)
@@ -23,3 +24,16 @@ func fetchElasticacheClusters(ctx context.Context, meta schema.ClientMeta, paren
2324
}
2425
return nil
2526
}
27+
28+
func resolveClusterTags(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error {
29+
cluster := resource.Item.(types.CacheCluster)
30+
31+
svc := meta.(*client.Client).Services().Elasticache
32+
response, err := svc.ListTagsForResource(ctx, &elasticache.ListTagsForResourceInput{
33+
ResourceName: cluster.ARN,
34+
})
35+
if err != nil {
36+
return err
37+
}
38+
return resource.Set(c.Name, client.TagsToMap(response.TagList))
39+
}

plugins/source/aws/resources/services/elasticache/clusters_mock_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"testing"
55

66
"github.com/aws/aws-sdk-go-v2/service/elasticache"
7+
"github.com/aws/aws-sdk-go-v2/service/elasticache/types"
78
"github.com/cloudquery/cloudquery/plugins/source/aws/client"
89
"github.com/cloudquery/cloudquery/plugins/source/aws/client/mocks"
910
"github.com/cloudquery/plugin-sdk/faker"
@@ -19,7 +20,13 @@ func buildElasticacheClusters(t *testing.T, ctrl *gomock.Controller) client.Serv
1920
t.Fatal(err)
2021
}
2122

23+
var ta types.Tag
24+
if err = faker.FakeObject(&ta); err != nil {
25+
t.Fatal(err)
26+
}
27+
2228
mockElasticache.EXPECT().DescribeCacheClusters(gomock.Any(), gomock.Any(), gomock.Any()).Return(&output, nil)
29+
mockElasticache.EXPECT().ListTagsForResource(gomock.Any(), &elasticache.ListTagsForResourceInput{ResourceName: output.CacheClusters[0].ARN}, gomock.Any()).Return(&elasticache.ListTagsForResourceOutput{TagList: []types.Tag{ta}}, nil)
2330

2431
return client.Services{
2532
Elasticache: mockElasticache,

0 commit comments

Comments
 (0)