|
6 | 6 |
|
7 | 7 | "github.com/aws/aws-sdk-go-v2/aws" |
8 | 8 | "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2" |
| 9 | + "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2/types" |
9 | 10 |
|
10 | 11 | "github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto" |
11 | 12 | "github.com/turbot/steampipe-plugin-sdk/v5/plugin" |
@@ -34,6 +35,12 @@ func tableAwsEc2ApplicationLoadBalancerListenerRule(_ context.Context) *plugin.T |
34 | 35 | Tags: map[string]string{"service": "elasticloadbalancing", "action": "DescribeRules"}, |
35 | 36 | }, |
36 | 37 | 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 | + }, |
37 | 44 | Columns: awsRegionalColumns([]*plugin.Column{ |
38 | 45 | { |
39 | 46 | Name: "arn", |
@@ -67,6 +74,20 @@ func tableAwsEc2ApplicationLoadBalancerListenerRule(_ context.Context) *plugin.T |
67 | 74 | 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.", |
68 | 75 | Type: proto.ColumnType_JSON, |
69 | 76 | }, |
| 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 | + }, |
70 | 91 | }), |
71 | 92 | } |
72 | 93 | } |
@@ -137,3 +158,52 @@ func listEc2LoadBalancerListenerRules(ctx context.Context, d *plugin.QueryData, |
137 | 158 |
|
138 | 159 | return nil, err |
139 | 160 | } |
| 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