Skip to content

Commit

Permalink
Merge branch 'develop' into fix/914-aws-loadbalancer-ui-link
Browse files Browse the repository at this point in the history
  • Loading branch information
mlabouardy authored Aug 21, 2023
2 parents 210ffd5 + f3a7b81 commit 8edcd44
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
* @mlabouardy @ShubhamPalriwala
* @mlabouardy @ShubhamPalriwala @AvineshTripathi
README.md @jakepage91
CONTRIBUTING.md @jakepage91
1 change: 1 addition & 0 deletions providers/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func listOfSupportedServices() []providers.FetchDataFunction {
rds.ProxyEndpoints,
rds.AutoBackups,
elb.LoadBalancers,
elb.TargetGroups,
efs.ElasticFileStorage,
apigateway.Apis,
elasticache.Clusters,
Expand Down
68 changes: 68 additions & 0 deletions providers/aws/elb/targetgroups.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package elb

import (
"context"
"fmt"
"time"

log "github.com/sirupsen/logrus"

"github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2"
. "github.com/tailwarden/komiser/models"
. "github.com/tailwarden/komiser/providers"
)

func TargetGroups(ctx context.Context, client ProviderClient) ([]Resource, error) {
resources := make([]Resource, 0)

var config elasticloadbalancingv2.DescribeTargetGroupsInput
elbtgClient := elasticloadbalancingv2.NewFromConfig(*client.AWSClient)

output, err := elbtgClient.DescribeTargetGroups(ctx, &config)

if err != nil {
return resources, err
}

for _, targetgroup := range output.TargetGroups {
resourceArn := *targetgroup.TargetGroupArn
outputTags, err := elbtgClient.DescribeTags(ctx, &elasticloadbalancingv2.DescribeTagsInput{
ResourceArns: []string{resourceArn},
})
if err != nil {
return resources, err
}

tags := make([]Tag, 0)
for _, tagDescription := range outputTags.TagDescriptions {
for _, tag := range tagDescription.Tags {
tags = append(tags, Tag{
Key: *tag.Key,
Value: *tag.Value,
})
}
}

resources = append(resources, Resource{
Provider: "AWS",
Account: client.Name,
Service: "Target Group",
ResourceId: resourceArn,
Region: client.AWSClient.Region,
Name: *targetgroup.TargetGroupName,
Tags: tags,
FetchedAt: time.Now(),
Link: fmt.Sprintf("https://%s.console.aws.amazon.com/ec2/home?region=%s#TargetGroup:targetGroupArn=%s", client.AWSClient.Region, client.AWSClient.Region, resourceArn),
})
}

log.WithFields(log.Fields{
"provider": "AWS",
"account": client.Name,
"region": client.AWSClient.Region,
"service": "Target Group",
"resources": len(resources),
}).Info("Fetched resources")

return resources, nil
}

0 comments on commit 8edcd44

Please sign in to comment.