Skip to content

Commit

Permalink
Merge pull request #933 from pavangudiwada/feature/534-aws-elb-listen…
Browse files Browse the repository at this point in the history
…er-rules

Added ELB listener rules and change listener name
  • Loading branch information
mlabouardy authored Sep 16, 2023
2 parents 18e1dbc + fc420e0 commit 314a7e9
Showing 1 changed file with 42 additions and 3 deletions.
45 changes: 42 additions & 3 deletions providers/aws/elb/loadbalancers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -70,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,
Expand Down Expand Up @@ -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: fmt.Sprintf("ELB %s Listener", elbValues[resourceType].elbType),
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: fmt.Sprintf("ELB %s Listener Rule", elbValues[resourceType].elbType),
ResourceId: ruleArn,
Region: client.AWSClient.Region,
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),
})
}

}

}
Expand Down

0 comments on commit 314a7e9

Please sign in to comment.