Skip to content

Commit e076217

Browse files
authored
fix: ECS Tags (#1515)
#### Summary ---
1 parent e0ddfcf commit e076217

File tree

4 files changed

+9
-51
lines changed

4 files changed

+9
-51
lines changed

plugins/source/aws/client/mocks/mock_ecs.go

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

plugins/source/aws/client/services.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ type EcrClient interface {
341341
type EcsClient interface {
342342
DescribeClusters(ctx context.Context, params *ecs.DescribeClustersInput, optFns ...func(*ecs.Options)) (*ecs.DescribeClustersOutput, error)
343343
ListClusters(ctx context.Context, params *ecs.ListClustersInput, optFns ...func(*ecs.Options)) (*ecs.ListClustersOutput, error)
344-
ListTagsForResource(ctx context.Context, params *ecs.ListTagsForResourceInput, optFns ...func(*ecs.Options)) (*ecs.ListTagsForResourceOutput, error)
345344
DescribeServices(ctx context.Context, params *ecs.DescribeServicesInput, optFns ...func(*ecs.Options)) (*ecs.DescribeServicesOutput, error)
346345
DescribeContainerInstances(ctx context.Context, params *ecs.DescribeContainerInstancesInput, optFns ...func(*ecs.Options)) (*ecs.DescribeContainerInstancesOutput, error)
347346
ListServices(ctx context.Context, params *ecs.ListServicesInput, optFns ...func(*ecs.Options)) (*ecs.ListServicesOutput, error)

plugins/source/aws/resources/services/ecs/cluster_mock_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ func buildEcsClusterMock(t *testing.T, ctrl *gomock.Controller) client.Services
3030
ClusterArns: []string{"randomClusteArn"},
3131
}
3232
m.EXPECT().ListClusters(gomock.Any(), gomock.Any(), gomock.Any()).Return(ecsListOutput, nil)
33-
var tags ecs.ListTagsForResourceOutput
34-
err = faker.FakeData(&tags)
35-
if err != nil {
36-
t.Fatal(err)
37-
}
3833

3934
servicesList := ecs.ListServicesOutput{
4035
ServiceArns: []string{"test"},
@@ -60,8 +55,6 @@ func buildEcsClusterMock(t *testing.T, ctrl *gomock.Controller) client.Services
6055
}
6156
m.EXPECT().DescribeContainerInstances(gomock.Any(), gomock.Any(), gomock.Any()).Return(&instances, nil)
6257

63-
m.EXPECT().ListTagsForResource(gomock.Any(), gomock.Any(), gomock.Any()).Return(&tags, nil)
64-
6558
listTasks := ecs.ListTasksOutput{}
6659
err = faker.FakeData(&listTasks)
6760
if err != nil {

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

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func Clusters() *schema.Table {
150150
Name: "tags",
151151
Description: "The metadata that you apply to the cluster to help you categorize and organize them",
152152
Type: schema.TypeJSON,
153-
Resolver: resolveClustersTags,
153+
Resolver: client.ResolveTags,
154154
},
155155
},
156156
Relations: []*schema.Table{
@@ -1446,7 +1446,10 @@ func fetchEcsClusters(ctx context.Context, meta schema.ClientMeta, parent *schem
14461446
if len(listClustersOutput.ClusterArns) == 0 {
14471447
return nil
14481448
}
1449-
describeClusterOutput, err := svc.DescribeClusters(ctx, &ecs.DescribeClustersInput{Clusters: listClustersOutput.ClusterArns}, func(o *ecs.Options) {
1449+
describeClusterOutput, err := svc.DescribeClusters(ctx, &ecs.DescribeClustersInput{
1450+
Clusters: listClustersOutput.ClusterArns,
1451+
Include: []types.ClusterField{types.ClusterFieldTags},
1452+
}, func(o *ecs.Options) {
14501453
o.Region = region
14511454
})
14521455
if err != nil {
@@ -1484,27 +1487,7 @@ func resolveClustersStatistics(ctx context.Context, meta schema.ClientMeta, reso
14841487
}
14851488
return diag.WrapError(resource.Set(c.Name, stats))
14861489
}
1487-
func resolveClustersTags(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error {
1488-
region := meta.(*client.Client).Region
1489-
svc := meta.(*client.Client).Services().ECS
1490-
cluster, ok := resource.Item.(types.Cluster)
1491-
if !ok {
1492-
return diag.WrapError(fmt.Errorf("expected to have types.Cluster but got %T", resource.Item))
1493-
}
1494-
listTagsForResourceOutput, err := svc.ListTagsForResource(ctx, &ecs.ListTagsForResourceInput{
1495-
ResourceArn: cluster.ClusterArn,
1496-
}, func(o *ecs.Options) {
1497-
o.Region = region
1498-
})
1499-
if err != nil {
1500-
return diag.WrapError(err)
1501-
}
1502-
tags := make(map[string]*string)
1503-
for _, s := range listTagsForResourceOutput.Tags {
1504-
tags[*s.Key] = s.Value
1505-
}
1506-
return diag.WrapError(resource.Set(c.Name, tags))
1507-
}
1490+
15081491
func resolveClusterAttachmentsDetails(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error {
15091492
attachment, ok := resource.Item.(types.Attachment)
15101493
if !ok {
@@ -1539,6 +1522,7 @@ func fetchEcsClusterTasks(ctx context.Context, meta schema.ClientMeta, parent *s
15391522
describeServicesInput := ecs.DescribeTasksInput{
15401523
Cluster: cluster.ClusterArn,
15411524
Tasks: listTasks.TaskArns,
1525+
Include: []types.TaskField{types.TaskFieldTags},
15421526
}
15431527
describeTasks, err := svc.DescribeTasks(ctx, &describeServicesInput, func(o *ecs.Options) {
15441528
o.Region = region
@@ -1587,6 +1571,7 @@ func fetchEcsClusterServices(ctx context.Context, meta schema.ClientMeta, parent
15871571
describeServicesInput := ecs.DescribeServicesInput{
15881572
Cluster: cluster.ClusterArn,
15891573
Services: listServicesOutput.ServiceArns,
1574+
Include: []types.ServiceField{types.ServiceFieldTags},
15901575
}
15911576
describeServicesOutput, err := svc.DescribeServices(ctx, &describeServicesInput, func(o *ecs.Options) {
15921577
o.Region = region
@@ -1645,6 +1630,7 @@ func fetchEcsClusterContainerInstances(ctx context.Context, meta schema.ClientMe
16451630
describeServicesInput := ecs.DescribeContainerInstancesInput{
16461631
Cluster: cluster.ClusterArn,
16471632
ContainerInstances: listContainerInstances.ContainerInstanceArns,
1633+
Include: []types.ContainerInstanceField{types.ContainerInstanceFieldTags},
16481634
}
16491635
describeContainerInstances, err := svc.DescribeContainerInstances(ctx, &describeServicesInput, func(o *ecs.Options) {
16501636
o.Region = region

0 commit comments

Comments
 (0)