-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add aws_keyspaces_keyspace and aws_keyspaces_table tables Closes #2264 (
#2271) Co-authored-by: Priyanka Chatterjee <[email protected]>
- Loading branch information
1 parent
4966710
commit 7d017c6
Showing
17 changed files
with
859 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
7 changes: 7 additions & 0 deletions
7
aws-test/tests/aws_keyspaces_table/test-get-call-expected.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[ | ||
{ | ||
"akas": ["{{ output.resource_aka.value }}"], | ||
"table_name": "{{resourceName}}", | ||
"title": "{{resourceName}}" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
select title, akas, table_name | ||
from aws.aws_keyspaces_table | ||
where keyspace_name = '{{resourceName}}' and table_name = '{{resourceName}}'; |
10 changes: 10 additions & 0 deletions
10
aws-test/tests/aws_keyspaces_table/test-list-call-expected.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[ | ||
{ | ||
"akas": [ | ||
"{{ output.resource_aka.value }}" | ||
], | ||
"keyspace_name": "{{resourceName}}", | ||
"table_name": "{{resourceName}}", | ||
"title": "{{resourceName}}" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
select table_name, keyspace_name, title, akas | ||
from aws.aws_keyspaces_table | ||
where keyspace_name = '{{ resourceName }}'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[ | ||
{ | ||
"akas": [ | ||
"{{ output.resource_aka.value }}" | ||
], | ||
"title": "{{resourceName}}" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
select akas, title | ||
from aws.aws_keyspaces_table | ||
where keyspace_name = '{{ resourceName }}'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
|
||
variable "resource_name" { | ||
type = string | ||
default = "turbot-test-20200125-create-update" | ||
description = "Name of the resource used throughout the test." | ||
} | ||
|
||
variable "aws_profile" { | ||
type = string | ||
default = "default" | ||
description = "AWS credentials profile used for the test. Default is to use the default profile." | ||
} | ||
|
||
variable "aws_region" { | ||
type = string | ||
default = "us-east-1" | ||
description = "AWS region used for the test. Does not work with default region in config, so must be defined here." | ||
} | ||
|
||
variable "aws_region_alternate" { | ||
type = string | ||
default = "us-east-2" | ||
description = "Alternate AWS region used for tests that require two regions (e.g. DynamoDB global tables)." | ||
} | ||
|
||
provider "aws" { | ||
profile = var.aws_profile | ||
region = var.aws_region | ||
} | ||
|
||
provider "aws" { | ||
alias = "alternate" | ||
profile = var.aws_profile | ||
region = var.aws_region_alternate | ||
} | ||
|
||
data "aws_partition" "current" {} | ||
data "aws_caller_identity" "current" {} | ||
data "aws_region" "primary" {} | ||
data "aws_region" "alternate" { | ||
provider = aws.alternate | ||
} | ||
|
||
data "null_data_source" "resource" { | ||
inputs = { | ||
scope = "arn:${data.aws_partition.current.partition}:::${data.aws_caller_identity.current.account_id}" | ||
} | ||
} | ||
|
||
resource "aws_keyspaces_keyspace" "named_test_resource" { | ||
name = var.resource_name | ||
} | ||
|
||
resource "aws_keyspaces_table" "named_test_resource" { | ||
keyspace_name = aws_keyspaces_keyspace.named_test_resource.name | ||
table_name = var.resource_name | ||
|
||
schema_definition { | ||
column { | ||
name = "test_id" | ||
type = "ascii" | ||
} | ||
|
||
partition_key { | ||
name = "test_id" | ||
} | ||
} | ||
} | ||
|
||
output "resource_aka" { | ||
value = aws_keyspaces_table.named_test_resource.arn | ||
} | ||
|
||
output "resource_name" { | ||
value = var.resource_name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
package aws | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/aws-sdk-go-v2/service/keyspaces" | ||
// "github.com/aws/aws-sdk-go-v2/service/keyspaces/types" | ||
keyspacesv1 "github.com/aws/aws-sdk-go/service/keyspaces" | ||
|
||
"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 tableAwsKeyspacesKeyspace(ctx context.Context) *plugin.Table { | ||
return &plugin.Table{ | ||
Name: "aws_keyspaces_keyspace", | ||
Description: "AWS Keyspaces Keyspace", | ||
Get: &plugin.GetConfig{ | ||
KeyColumns: plugin.SingleColumn("keyspace_name"), // Identify the keyspace by its name | ||
Hydrate: getKeyspacesKeyspace, // Get function | ||
IgnoreConfig: &plugin.IgnoreConfig{ | ||
ShouldIgnoreErrorFunc: shouldIgnoreErrors([]string{"ResourceNotFoundException"}), | ||
}, | ||
Tags: map[string]string{"service": "keyspaces", "action": "GetKeyspace"}, | ||
}, | ||
List: &plugin.ListConfig{ | ||
Hydrate: listKeyspacesKeyspaces, // Parent hydrate function | ||
Tags: map[string]string{"service": "keyspaces", "action": "ListKeyspaces"}, | ||
}, | ||
GetMatrixItemFunc: SupportedRegionMatrix(keyspacesv1.EndpointsID), | ||
Columns: awsRegionalColumns([]*plugin.Column{ | ||
{ | ||
Name: "keyspace_name", | ||
Description: "The name of the keyspace.", | ||
Type: proto.ColumnType_STRING, | ||
}, | ||
{ | ||
Name: "arn", | ||
Description: "The unique identifier of the keyspace in the format of an Amazon Resource Name (ARN).", | ||
Type: proto.ColumnType_STRING, | ||
Transform: transform.FromField("ResourceArn"), | ||
}, | ||
{ | ||
Name: "replication_strategy", | ||
Description: "Returns the replication strategy of the keyspace. The options are SINGLE_REGION or MULTI_REGION .", | ||
Type: proto.ColumnType_STRING, | ||
}, | ||
{ | ||
Name: "replication_regions", | ||
Description: "If the replication strategy of the keyspace is MULTI_REGION, a list of replication regions is returned.", | ||
Type: proto.ColumnType_JSON, | ||
}, | ||
|
||
/// Steampipe standard columns | ||
{ | ||
Name: "title", | ||
Description: resourceInterfaceDescription("title"), | ||
Type: proto.ColumnType_STRING, | ||
Transform: transform.FromField("KeyspaceName"), | ||
}, | ||
{ | ||
Name: "akas", | ||
Description: resourceInterfaceDescription("akas"), | ||
Type: proto.ColumnType_JSON, | ||
Transform: transform.FromField("ResourceArn").Transform(transform.EnsureStringArray), | ||
}, | ||
}), | ||
} | ||
} | ||
|
||
//// LIST FUNCTION | ||
|
||
func listKeyspacesKeyspaces(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) { | ||
// Create session | ||
svc, err := KeyspacesClient(ctx, d) | ||
if err != nil { | ||
plugin.Logger(ctx).Error("aws_keyspaces_keyspace.listKeyspacesKeyspaces", "connection_error", err) | ||
return nil, err | ||
} | ||
|
||
if svc == nil { | ||
// Unsupported region check | ||
return nil, nil | ||
} | ||
|
||
// Define max results for the request | ||
maxItems := int32(1000) | ||
if d.QueryContext.Limit != nil { | ||
limit := int32(*d.QueryContext.Limit) | ||
if limit < maxItems { | ||
maxItems = limit | ||
} | ||
} | ||
|
||
input := &keyspaces.ListKeyspacesInput{ | ||
MaxResults: &maxItems, | ||
} | ||
|
||
paginator := keyspaces.NewListKeyspacesPaginator(svc, input, func(o *keyspaces.ListKeyspacesPaginatorOptions) { | ||
o.Limit = maxItems | ||
o.StopOnDuplicateToken = true | ||
}) | ||
|
||
for paginator.HasMorePages() { | ||
// apply rate limiting | ||
d.WaitForListRateLimit(ctx) | ||
|
||
output, err := paginator.NextPage(ctx) | ||
if err != nil { | ||
plugin.Logger(ctx).Error("aws_keyspaces_keyspace.listKeyspacesKeyspaces", "api_error", err) | ||
return nil, err | ||
} | ||
|
||
for _, keyspace := range output.Keyspaces { | ||
d.StreamListItem(ctx, keyspace) | ||
|
||
// Stop processing if context is canceled or limit is reached | ||
if d.RowsRemaining(ctx) == 0 { | ||
return nil, nil | ||
} | ||
} | ||
} | ||
|
||
return nil, nil | ||
} | ||
|
||
//// GET FUNCTION | ||
|
||
func getKeyspacesKeyspace(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) { | ||
keyspaceName := d.EqualsQualString("keyspace_name") | ||
|
||
// Empty check for keyspace name | ||
if keyspaceName == "" { | ||
return nil, nil | ||
} | ||
|
||
// Create session | ||
svc, err := KeyspacesClient(ctx, d) | ||
if err != nil { | ||
plugin.Logger(ctx).Error("aws_keyspaces_keyspace.getKeyspacesKeyspace", "connection_error", err) | ||
return nil, err | ||
} | ||
|
||
if svc == nil { | ||
// Unsupported region | ||
return nil, nil | ||
} | ||
|
||
// Build the input parameters | ||
input := &keyspaces.GetKeyspaceInput{ | ||
KeyspaceName: &keyspaceName, | ||
} | ||
|
||
// Make the GetKeyspace API call | ||
result, err := svc.GetKeyspace(ctx, input) | ||
if err != nil { | ||
plugin.Logger(ctx).Error("aws_keyspaces_keyspace.getKeyspacesKeyspace", "api_error", err) | ||
return nil, err | ||
} | ||
|
||
return result, nil | ||
} |
Oops, something went wrong.