Skip to content

Commit cae9858

Browse files
authored
Added tags_src, and tags column to the table aws_ec2_load_balancer_listener_rule Close (#2625)
1 parent 78d809c commit cae9858

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

aws/table_aws_ec2_load_balancer_listener_rule.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/aws/aws-sdk-go-v2/aws"
88
"github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2"
9+
"github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2/types"
910

1011
"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
1112
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
@@ -34,6 +35,12 @@ func tableAwsEc2ApplicationLoadBalancerListenerRule(_ context.Context) *plugin.T
3435
Tags: map[string]string{"service": "elasticloadbalancing", "action": "DescribeRules"},
3536
},
3637
GetMatrixItemFunc: SupportedRegionMatrix(AWS_ELASTICLOADBALANCING_SERVICE_ID),
38+
HydrateConfig: []plugin.HydrateConfig{
39+
{
40+
Func: getEc2LoadBalancerListenerRuleTags,
41+
Tags: map[string]string{"service": "elasticloadbalancing", "action": "DescribeTags"},
42+
},
43+
},
3744
Columns: awsRegionalColumns([]*plugin.Column{
3845
{
3946
Name: "arn",
@@ -67,6 +74,20 @@ func tableAwsEc2ApplicationLoadBalancerListenerRule(_ context.Context) *plugin.T
6774
Description: "The conditions. Each rule can include zero or one of the following conditions: http-request-method , host-header , path-pattern , and source-ip , and zero or more of the following conditions: http-header and query-string.",
6875
Type: proto.ColumnType_JSON,
6976
},
77+
{
78+
Name: "tags_src",
79+
Description: "A list of tags assigned to the rule.",
80+
Type: proto.ColumnType_JSON,
81+
Hydrate: getEc2LoadBalancerListenerRuleTags,
82+
Transform: transform.FromValue(),
83+
},
84+
{
85+
Name: "tags",
86+
Description: resourceInterfaceDescription("tags"),
87+
Type: proto.ColumnType_JSON,
88+
Hydrate: getEc2LoadBalancerListenerRuleTags,
89+
Transform: transform.From(getEc2LoadBalancerListenerRuleTurbotTags),
90+
},
7091
}),
7192
}
7293
}
@@ -137,3 +158,52 @@ func listEc2LoadBalancerListenerRules(ctx context.Context, d *plugin.QueryData,
137158

138159
return nil, err
139160
}
161+
162+
//// HYDRATE FUNCTIONS
163+
164+
func getEc2LoadBalancerListenerRuleTags(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
165+
rule := h.Item.(types.Rule)
166+
167+
// Create service
168+
svc, err := ELBV2Client(ctx, d)
169+
if err != nil {
170+
plugin.Logger(ctx).Error("aws_ec2_load_balancer_listener_rule.getEc2LoadBalancerListenerRuleTags", "connection_error", err)
171+
return nil, err
172+
}
173+
174+
params := &elasticloadbalancingv2.DescribeTagsInput{
175+
ResourceArns: []string{*rule.RuleArn},
176+
}
177+
178+
ruleData, err := svc.DescribeTags(ctx, params)
179+
if err != nil {
180+
plugin.Logger(ctx).Error("aws_ec2_load_balancer_listener_rule.getEc2LoadBalancerListenerRuleTags", "api_error", err)
181+
return nil, err
182+
}
183+
184+
var tags []types.Tag
185+
if len(ruleData.TagDescriptions) > 0 {
186+
for _, tagDescription := range ruleData.TagDescriptions {
187+
if tagDescription.ResourceArn != nil && *tagDescription.ResourceArn == *rule.RuleArn {
188+
tags = append(tags, tagDescription.Tags...)
189+
}
190+
}
191+
}
192+
193+
return tags, nil
194+
}
195+
196+
//// TRANSFORM FUNCTIONS
197+
198+
func getEc2LoadBalancerListenerRuleTurbotTags(_ context.Context, d *transform.TransformData) (interface{}, error) {
199+
ruleTags := d.HydrateItem.([]types.Tag)
200+
201+
if ruleTags != nil {
202+
turbotTagsMap := map[string]string{}
203+
for _, i := range ruleTags {
204+
turbotTagsMap[*i.Key] = *i.Value
205+
}
206+
return turbotTagsMap, nil
207+
}
208+
return nil, nil
209+
}

0 commit comments

Comments
 (0)