Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add columns steampipe_available and steampipe_default in the aws_region table #2158

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions aws/table_aws_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/aws/aws-sdk-go-v2/service/ec2/types"
"github.com/turbot/go-kit/helpers"
"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"
Expand Down Expand Up @@ -50,6 +51,18 @@ func tableAwsRegion(_ context.Context) *plugin.Table {
Type: proto.ColumnType_STRING,
Transform: transform.FromField("RegionName"),
},
{
Name: "steampipe_available",
Description: "True if the region is available for query in Steampipe.",
Type: proto.ColumnType_BOOL,
Hydrate: getAWSRegionsInConfig,
},
{
Name: "steampipe_default",
Description: "True if this region is the default region for Steampipe to use.",
Type: proto.ColumnType_BOOL,
Hydrate: getAWSRegionsInConfig,
},
}),
}
}
Expand Down Expand Up @@ -77,3 +90,32 @@ func getAwsRegionAkas(ctx context.Context, d *plugin.QueryData, h *plugin.Hydrat
akas := []string{"arn:" + commonColumnData.Partition + "::" + *region.RegionName + ":" + commonColumnData.AccountId}
return akas, nil
}

func getAWSRegionsInConfig(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
region := h.Item.(types.Region)

// Retrieve regions list from the AWS plugin steampipe connection config
configRegions, err := listQueryRegionsForConnection(ctx, d)
if err != nil {
return nil, err
}

var regionsInConfig RegionsInConfig

// check if the region is set as a default region in the connection config
defaultRegion := getAwsSpcConfigDefaultRegion(ctx, d)
if *region.RegionName == defaultRegion {
regionsInConfig.SteampipeDefault = true
}

// check if the region is set in the connection config
if helpers.StringSliceContains(configRegions, *region.RegionName) {
regionsInConfig.SteampipeAvailable = true
}
return regionsInConfig, nil
}

type RegionsInConfig struct {
SteampipeAvailable bool
SteampipeDefault bool
}
Loading