From 67817a712cd6e720ca68a216cc3ea84c40cc31c0 Mon Sep 17 00:00:00 2001 From: Pavan Gudiwada <25551553+pavangudiwada@users.noreply.github.com> Date: Tue, 5 Sep 2023 14:12:00 +0530 Subject: [PATCH 1/2] Added ELB listener rules and change listener name --- providers/aws/elb/loadbalancers.go | 43 ++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/providers/aws/elb/loadbalancers.go b/providers/aws/elb/loadbalancers.go index bfa3f575d..58856cac5 100644 --- a/providers/aws/elb/loadbalancers.go +++ b/providers/aws/elb/loadbalancers.go @@ -36,6 +36,7 @@ func LoadBalancers(ctx context.Context, client ProviderClient) ([]Resource, erro } var configListeners elasticloadbalancingv2.DescribeListenersInput + var configRules elasticloadbalancingv2.DescribeRulesInput for _, loadbalancer := range output.LoadBalancers { resourceArn := *loadbalancer.LoadBalancerArn @@ -109,14 +110,52 @@ func LoadBalancers(ctx context.Context, client ProviderClient) ([]Resource, erro resources = append(resources, Resource{ Provider: "AWS", Account: client.Name, - Service: "ELB Listener" + " " + elbValues[resourceType].elbType, + Service: "ELB " + elbValues[resourceType].elbType[:3] + " Listener", ResourceId: listenerArn, Region: client.AWSClient.Region, - Name: listenerArn, + Name: *loadbalancer.LoadBalancerName, Tags: tags, FetchedAt: time.Now(), Link: fmt.Sprintf("https://%s.console.aws.amazon.com/ec2/home?region=%s#ELBListenerV2:listenerArn=%s", client.AWSClient.Region, client.AWSClient.Region, listenerArn), }) + + configRules.ListenerArn = &listenerArn + output, err := elbClient.DescribeRules(ctx, &configRules) + if err != nil { + return resources, err + } + + for rule_number, rule := range output.Rules { + ruleArn := *rule.RuleArn + outputTags, err := elbClient.DescribeTags(ctx, &elasticloadbalancingv2.DescribeTagsInput{ + ResourceArns: []string{ruleArn}, + }) + 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: "ELB " + elbValues[resourceType].elbType[:3] + " Listener Rule", + ResourceId: ruleArn, + Region: client.AWSClient.Region, + Name: *loadbalancer.LoadBalancerName + " Rule " + fmt.Sprintf("%d", rule_number+1), + Tags: tags, + FetchedAt: time.Now(), + Link: fmt.Sprintf("https://%s.console.aws.amazon.com/ec2/home?region=%s#ListenerRuleDetails:ruleArn=%s", client.AWSClient.Region, client.AWSClient.Region, ruleArn), + }) + } + } } From fc420e076b3aa97b3750ad9679fb8d8774e3d0a7 Mon Sep 17 00:00:00 2001 From: Pavan Gudiwada <25551553+pavangudiwada@users.noreply.github.com> Date: Sat, 16 Sep 2023 10:35:09 +0530 Subject: [PATCH 2/2] Updated to fmt.Sprintf and revised to full ELB names --- providers/aws/elb/loadbalancers.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/providers/aws/elb/loadbalancers.go b/providers/aws/elb/loadbalancers.go index 58856cac5..3aea90989 100644 --- a/providers/aws/elb/loadbalancers.go +++ b/providers/aws/elb/loadbalancers.go @@ -71,7 +71,7 @@ func LoadBalancers(ctx context.Context, client ProviderClient) ([]Resource, erro resources = append(resources, Resource{ Provider: "AWS", Account: client.Name, - Service: "ELB" + " " + elbValues[resourceType].elbType, + Service: fmt.Sprintf("ELB %s", elbValues[resourceType].elbType), ResourceId: resourceArn, Region: client.AWSClient.Region, Name: *loadbalancer.LoadBalancerName, @@ -110,7 +110,7 @@ func LoadBalancers(ctx context.Context, client ProviderClient) ([]Resource, erro resources = append(resources, Resource{ Provider: "AWS", Account: client.Name, - Service: "ELB " + elbValues[resourceType].elbType[:3] + " Listener", + Service: fmt.Sprintf("ELB %s Listener", elbValues[resourceType].elbType), ResourceId: listenerArn, Region: client.AWSClient.Region, Name: *loadbalancer.LoadBalancerName, @@ -146,10 +146,10 @@ func LoadBalancers(ctx context.Context, client ProviderClient) ([]Resource, erro resources = append(resources, Resource{ Provider: "AWS", Account: client.Name, - Service: "ELB " + elbValues[resourceType].elbType[:3] + " Listener Rule", + Service: fmt.Sprintf("ELB %s Listener Rule", elbValues[resourceType].elbType), ResourceId: ruleArn, Region: client.AWSClient.Region, - Name: *loadbalancer.LoadBalancerName + " Rule " + fmt.Sprintf("%d", rule_number+1), + Name: *loadbalancer.LoadBalancerName + fmt.Sprintf(" Rule %d", rule_number+1), Tags: tags, FetchedAt: time.Now(), Link: fmt.Sprintf("https://%s.console.aws.amazon.com/ec2/home?region=%s#ListenerRuleDetails:ruleArn=%s", client.AWSClient.Region, client.AWSClient.Region, ruleArn),