Skip to content

Commit

Permalink
ensure that client.DescribeTags is always called with data
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidS-ovm committed Nov 9, 2023
1 parent a14c5b9 commit edd9eea
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
25 changes: 12 additions & 13 deletions sources/elb/elb.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,27 @@ func loadBalancerOutputMapper(ctx context.Context, client elbClient, scope strin
items := make([]*sdp.Item, 0)

loadBalancerNames := make([]string, 0)

for _, desc := range output.LoadBalancerDescriptions {
if desc.LoadBalancerName != nil {
loadBalancerNames = append(loadBalancerNames, *desc.LoadBalancerName)
}
}

// Get all tags for all load balancers in this output
tagsOut, err := client.DescribeTags(ctx, &elb.DescribeTagsInput{
LoadBalancerNames: loadBalancerNames,
})

if err != nil {
return nil, err
}

// Map of load balancer name to tags
tagsMap := make(map[string][]types.Tag)
if len(loadBalancerNames) > 0 {
// Get all tags for all load balancers in this output
tagsOut, err := client.DescribeTags(ctx, &elb.DescribeTagsInput{
LoadBalancerNames: loadBalancerNames,
})
if err != nil {
return nil, err
}

for _, tagDesc := range tagsOut.TagDescriptions {
if tagDesc.LoadBalancerName != nil {
tagsMap[*tagDesc.LoadBalancerName] = tagDesc.Tags
for _, tagDesc := range tagsOut.TagDescriptions {
if tagDesc.LoadBalancerName != nil {
tagsMap[*tagDesc.LoadBalancerName] = tagDesc.Tags
}
}
}

Expand Down
21 changes: 11 additions & 10 deletions sources/elbv2/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,18 @@ func tagsToMap(tags []types.Tag) map[string]string {
func getTagsMap(ctx context.Context, client elbClient, arns []string) (map[string]map[string]string, error) {
tagsMap := make(map[string]map[string]string)

tagsOut, err := client.DescribeTags(ctx, &elbv2.DescribeTagsInput{
ResourceArns: arns,
})

if err != nil {
return nil, err
}
if len(arns) > 0 {
tagsOut, err := client.DescribeTags(ctx, &elbv2.DescribeTagsInput{
ResourceArns: arns,
})
if err != nil {
return nil, err
}

for _, tagDescription := range tagsOut.TagDescriptions {
if tagDescription.ResourceArn != nil {
tagsMap[*tagDescription.ResourceArn] = tagsToMap(tagDescription.Tags)
for _, tagDescription := range tagsOut.TagDescriptions {
if tagDescription.ResourceArn != nil {
tagsMap[*tagDescription.ResourceArn] = tagsToMap(tagDescription.Tags)
}
}
}

Expand Down

0 comments on commit edd9eea

Please sign in to comment.