Skip to content

Commit 388feb7

Browse files
authored
Add table aws_trusted_advisor_check_result Closes #2501 (#2555)
1 parent 6e238b7 commit 388feb7

File tree

3 files changed

+459
-0
lines changed

3 files changed

+459
-0
lines changed

aws/plugin.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,7 @@ func Plugin(ctx context.Context) *plugin.Plugin {
671671
"aws_transfer_server": tableAwsTransferServer(ctx),
672672
"aws_transfer_user": tableAwsTransferUser(ctx),
673673
"aws_trusted_advisor_check_summary": tableAwsTrustedAdvisorCheckSummary(ctx),
674+
"aws_trusted_advisor_check_result": tableAwsTrustedAdvisorCheckResult(ctx),
674675
"aws_vpc": tableAwsVpc(ctx),
675676
"aws_vpc_customer_gateway": tableAwsVpcCustomerGateway(ctx),
676677
"aws_vpc_dhcp_options": tableAwsVpcDhcpOptions(ctx),
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
package aws
2+
3+
import (
4+
"context"
5+
6+
"github.com/aws/aws-sdk-go-v2/aws"
7+
"github.com/aws/aws-sdk-go-v2/service/support"
8+
"github.com/aws/aws-sdk-go-v2/service/support/types"
9+
10+
"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
11+
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
12+
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform"
13+
)
14+
15+
// TrustedAdvisorCheckResultData represents a flattened structure combining check result data with individual flagged resource details
16+
type TrustedAdvisorCheckResultData struct {
17+
CheckId *string `json:"checkId"`
18+
Timestamp *string `json:"timestamp"`
19+
Status *string `json:"status"`
20+
ResourcesSummary *types.TrustedAdvisorResourcesSummary `json:"resourcesSummary"`
21+
CategorySpecificSummary *types.TrustedAdvisorCategorySpecificSummary `json:"categorySpecificSummary"`
22+
23+
// Flagged resource properties (flattened from flaggedResources array)
24+
FlaggedResourceId *string `json:"flaggedResourceId"`
25+
FlaggedResourceStatus *string `json:"flaggedResourceStatus"`
26+
FlaggedResourceRegion *string `json:"flaggedResourceRegion"`
27+
FlaggedResourceIsSuppressed bool `json:"flaggedResourceIsSuppressed"`
28+
FlaggedResourceMetadata []*string `json:"flaggedResourceMetadata"`
29+
}
30+
31+
//// TABLE DEFINITION
32+
33+
func tableAwsTrustedAdvisorCheckResult(_ context.Context) *plugin.Table {
34+
return &plugin.Table{
35+
Name: "aws_trusted_advisor_check_result",
36+
Description: "AWS Trusted Advisor Check Result",
37+
List: &plugin.ListConfig{
38+
Hydrate: listTrustedAdvisorCheckResults,
39+
Tags: map[string]string{"service": "support", "action": "DescribeTrustedAdvisorCheckResult"},
40+
KeyColumns: plugin.KeyColumnSlice{
41+
{
42+
Name: "language",
43+
Require: plugin.Required,
44+
},
45+
{
46+
Name: "check_id",
47+
Require: plugin.Required,
48+
},
49+
},
50+
},
51+
Columns: awsAccountColumns([]*plugin.Column{
52+
{
53+
Name: "check_id",
54+
Description: "The unique identifier for the Trusted Advisor check.",
55+
Type: proto.ColumnType_STRING,
56+
},
57+
{
58+
Name: "language",
59+
Description: "The ISO 639-1 code for the language that you want your checks to appear in.",
60+
Type: proto.ColumnType_STRING,
61+
Transform: transform.FromQual("language"),
62+
},
63+
{
64+
Name: "status",
65+
Description: "The overall status of the Trusted Advisor check: 'ok' (green), 'warning' (yellow), 'error' (red), or 'not_available'.",
66+
Type: proto.ColumnType_STRING,
67+
},
68+
{
69+
Name: "timestamp",
70+
Description: "The time when the Trusted Advisor check was last refreshed.",
71+
Type: proto.ColumnType_TIMESTAMP,
72+
},
73+
{
74+
Name: "flagged_resource_id",
75+
Description: "The unique identifier for the flagged resource.",
76+
Type: proto.ColumnType_STRING,
77+
},
78+
{
79+
Name: "flagged_resource_status",
80+
Description: "The status of the flagged resource: 'ok' (green), 'warning' (yellow), 'error' (red), or 'not_available'.",
81+
Type: proto.ColumnType_STRING,
82+
},
83+
{
84+
Name: "flagged_resource_region",
85+
Description: "The AWS region of the flagged resource.",
86+
Type: proto.ColumnType_STRING,
87+
},
88+
{
89+
Name: "flagged_resource_is_suppressed",
90+
Description: "Specifies whether the flagged AWS resource was ignored by Trusted Advisor because it was marked as suppressed by the user.",
91+
Type: proto.ColumnType_BOOL,
92+
},
93+
{
94+
Name: "flagged_resource_metadata",
95+
Description: "Additional information about the flagged resource. The exact metadata and its order can be obtained by calling DescribeTrustedAdvisorChecks.",
96+
Type: proto.ColumnType_JSON,
97+
},
98+
{
99+
Name: "resources_summary",
100+
Description: "Summary information about the resources analyzed by the Trusted Advisor check.",
101+
Type: proto.ColumnType_JSON,
102+
},
103+
{
104+
Name: "category_specific_summary",
105+
Description: "Summary information that relates to the category of the check. Cost Optimizing is the only category that is currently supported.",
106+
Type: proto.ColumnType_JSON,
107+
},
108+
109+
// Steampipe standard columns
110+
{
111+
Name: "title",
112+
Description: resourceInterfaceDescription("title"),
113+
Type: proto.ColumnType_STRING,
114+
Transform: transform.FromField("FlaggedResourceId"),
115+
},
116+
}),
117+
}
118+
}
119+
120+
//// LIST FUNCTION
121+
122+
func listTrustedAdvisorCheckResults(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
123+
// Create session
124+
svc, err := SupportClient(ctx, d)
125+
if err != nil {
126+
plugin.Logger(ctx).Error("aws_trusted_advisor_check_result.listTrustedAdvisorCheckResults", "client_error", err)
127+
return nil, err
128+
}
129+
if svc == nil {
130+
return nil, nil
131+
}
132+
133+
language := d.EqualsQualString("language")
134+
checkId := d.EqualsQualString("check_id")
135+
136+
// Empty check
137+
if language == "" || checkId == "" {
138+
return nil, nil
139+
}
140+
141+
input := &support.DescribeTrustedAdvisorCheckResultInput{
142+
Language: aws.String(language),
143+
CheckId: aws.String(checkId),
144+
}
145+
146+
// Get call
147+
result, err := svc.DescribeTrustedAdvisorCheckResult(ctx, input)
148+
if err != nil {
149+
plugin.Logger(ctx).Error("aws_trusted_advisor_check_result.listTrustedAdvisorCheckResults", "api_error", err)
150+
return nil, err
151+
}
152+
153+
if result != nil && result.Result != nil {
154+
checkResult := result.Result
155+
156+
// Stream each flagged resource as a separate row
157+
for _, resource := range checkResult.FlaggedResources {
158+
resourceData := &TrustedAdvisorCheckResultData{
159+
CheckId: checkResult.CheckId,
160+
Timestamp: checkResult.Timestamp,
161+
Status: checkResult.Status,
162+
ResourcesSummary: checkResult.ResourcesSummary,
163+
CategorySpecificSummary: checkResult.CategorySpecificSummary,
164+
FlaggedResourceId: resource.ResourceId,
165+
FlaggedResourceStatus: resource.Status,
166+
FlaggedResourceRegion: resource.Region,
167+
FlaggedResourceIsSuppressed: resource.IsSuppressed,
168+
FlaggedResourceMetadata: resource.Metadata,
169+
}
170+
171+
d.StreamListItem(ctx, resourceData)
172+
173+
// Context can be cancelled due to manual cancellation or the limit has been hit
174+
if d.RowsRemaining(ctx) == 0 {
175+
return nil, nil
176+
}
177+
}
178+
}
179+
180+
return nil, nil
181+
}

0 commit comments

Comments
 (0)