Skip to content

Commit

Permalink
Add table aws_wellarchitected_notification #1688 (#1693)
Browse files Browse the repository at this point in the history
  • Loading branch information
karanpopat authored Apr 20, 2023
1 parent 87be08f commit 861b9df
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 0 deletions.
1 change: 1 addition & 0 deletions aws/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ func Plugin(ctx context.Context) *plugin.Plugin {
"aws_wafv2_web_acl": tableAwsWafv2WebAcl(ctx),
"aws_wellarchitected_lens_review": tableAwsWellArchitectedLensReview(ctx),
"aws_wellarchitected_milestone": tableAwsWellArchitectedMilestone(ctx),
"aws_wellarchitected_notification": tableAwsWellArchitectedNotification(ctx),
"aws_wellarchitected_workload": tableAwsWellArchitectedWorkload(ctx),
"aws_wellarchitected_workload_share": tableAwsWellArchitectedWorkloadShare(ctx),
"aws_workspaces_workspace": tableAwsWorkspace(ctx),
Expand Down
130 changes: 130 additions & 0 deletions aws/table_aws_wellarchitected_notification.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package aws

import (
"context"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/wellarchitected"

wellarchitectedv1 "github.com/aws/aws-sdk-go/service/wellarchitected"

"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform"
)

//// TABLE DEFINITION

func tableAwsWellArchitectedNotification(_ context.Context) *plugin.Table {
return &plugin.Table{
Name: "aws_wellarchitected_notification",
Description: "AWS Well-Architected Notification",
List: &plugin.ListConfig{
Hydrate: listWellArchitectedNotifications,
KeyColumns: []*plugin.KeyColumn{
{Name: "workload_id", Require: plugin.Optional},
},
},
GetMatrixItemFunc: SupportedRegionMatrix(wellarchitectedv1.EndpointsID),
Columns: awsRegionalColumns([]*plugin.Column{
{
Name: "current_lens_version",
Description: "The current version of the lens.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("LensUpgradeSummary.CurrentLensVersion"),
},
{
Name: "latest_lens_version",
Description: "The latest version of the lens.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("LensUpgradeSummary.LatestLensVersion"),
},
{
Name: "lens_alias",
Description: "The alias of the lens.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("LensUpgradeSummary.LensAlias"),
},
{
Name: "lens_arn",
Description: "The ARN of the lens.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("LensUpgradeSummary.LensArn"),
},
{
Name: "type",
Description: "The type of notification.",
Type: proto.ColumnType_STRING,
},
{
Name: "workload_id",
Description: "The ID assigned to the workload.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("LensUpgradeSummary.WorkloadId"),
},
{
Name: "workload_name",
Description: "The name of the workload.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("LensUpgradeSummary.WorkloadName"),
},
}),
}
}

//// LIST FUNCTION

func listWellArchitectedNotifications(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
// Create session
svc, err := WellArchitectedClient(ctx, d)
if err != nil {
plugin.Logger(ctx).Error("aws_wellarchitected_notification.listWellArchitectedNotifications", "client_error", err)
return nil, err
}
if svc == nil {
// Unsupported region, return no data
return nil, nil
}

// Limiting the results
maxLimit := int32(50)
if d.QueryContext.Limit != nil {
limit := int32(*d.QueryContext.Limit)
if limit < maxLimit {
maxLimit = limit
}
}

input := &wellarchitected.ListNotificationsInput{
MaxResults: maxLimit,
}

if d.EqualsQualString("workload_id") != "" {
input.WorkloadId = aws.String(d.EqualsQualString("workload_id"))
}

paginator := wellarchitected.NewListNotificationsPaginator(svc, input, func(o *wellarchitected.ListNotificationsPaginatorOptions) {
o.Limit = maxLimit
o.StopOnDuplicateToken = true
})

// List call
for paginator.HasMorePages() {
output, err := paginator.NextPage(ctx)
if err != nil {
plugin.Logger(ctx).Error("aws_wellarchitected_notification.listWellArchitectedNotifications", "api_error", err)
return nil, err
}

for _, item := range output.NotificationSummaries {
d.StreamListItem(ctx, item)

// Context can be cancelled due to manual cancellation or the limit has been hit
if d.RowsRemaining(ctx) == 0 {
return nil, nil
}
}
}

return nil, nil
}
50 changes: 50 additions & 0 deletions docs/tables/aws_wellarchitected_notification.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Table: aws_wellarchitected_notification

A Notification indicates that a new version of a Well-Architected lens is available.

## Examples

### List notifications for workloads where lens version is upgraded

```sql
select
workload_name,
lens_alias,
lens_arn,
current_lens_version,
latest_lens_version
from
aws_wellarchitected_notification
where
notification_type = 'LENS_VERSION_UPGRADED';
```

### List notifications for workloads where lens version is deprecated

```sql
select
workload_name,
lens_alias,
lens_arn,
current_lens_version,
latest_lens_version
from
aws_wellarchitected_notification
where
notification_type = 'LENS_VERSION_DEPRECATED';
```

### Check if there is a notification for a particular workload

```sql
select
workload_name,
lens_alias,
lens_arn,
current_lens_version,
latest_lens_version
from
aws_wellarchitected_notification
where
workload_id = '123451c59cebcd4612f1f858bf75566';
```

0 comments on commit 861b9df

Please sign in to comment.