This repository has been archived by the owner on Aug 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add RDS event subscriptions
- Loading branch information
Showing
11 changed files
with
304 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,19 @@ | ||
|
||
# Table: aws_rds_event_subscriptions | ||
Contains the results of a successful invocation of the DescribeEventSubscriptions action. | ||
## Columns | ||
| Name | Type | Description | | ||
| ------------- | ------------- | ----- | | ||
|account_id|text|The AWS Account ID of the resource.| | ||
|region|text|The AWS Region of the resource.| | ||
|cust_subscription_id|text|The RDS event notification subscription Id.| | ||
|customer_aws_id|text|The AWS customer account associated with the RDS event notification subscription.| | ||
|enabled|boolean|A Boolean value indicating if the subscription is enabled| | ||
|event_categories_list|text[]|A list of event categories for the RDS event notification subscription.| | ||
|arn|text|The Amazon Resource Name (ARN) for the event subscription.| | ||
|sns_topic_arn|text|The topic ARN of the RDS event notification subscription.| | ||
|source_ids_list|text[]|A list of source IDs for the RDS event notification subscription.| | ||
|source_type|text|The source type for the RDS event notification subscription.| | ||
|status|text|The status of the RDS event notification subscription| | ||
|subscription_creation_time|text|The time the RDS event notification subscription was created.| | ||
|tags|jsonb|List of tags| |
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
34 changes: 34 additions & 0 deletions
34
resources/integration_tests/aws_rds_event_subscriptions_test.go
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,34 @@ | ||
package integration_tests | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/cloudquery/cq-provider-aws/resources" | ||
providertest "github.com/cloudquery/cq-provider-sdk/provider/testing" | ||
) | ||
|
||
func TestIntegrationRdsEventSubscriptions(t *testing.T) { | ||
table := resources.RdsEventSubscriptions() | ||
awsTestIntegrationHelper(t, table, []string{"aws_rds_event_subscriptions.tf", "aws_sns.tf", "aws_rds_instances.tf"}, func(res *providertest.ResourceIntegrationTestData) providertest.ResourceIntegrationVerification { | ||
return providertest.ResourceIntegrationVerification{ | ||
Name: table.Name, | ||
ExpectedValues: []providertest.ExpectedValue{ | ||
{ | ||
Count: 1, | ||
Data: map[string]interface{}{ | ||
"cust_subscription_id": fmt.Sprintf("rds-event-sub-%s-%s", res.Prefix, res.Suffix), | ||
"enabled": true, | ||
"event_categories_list": []interface{}{"failure"}, | ||
"source_type": "db-instance", | ||
"status": "active", | ||
"tags": map[string]interface{}{ | ||
"Type": "integration_test", | ||
"TestId": res.Suffix, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
}) | ||
} |
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
11 changes: 11 additions & 0 deletions
11
resources/integration_tests/infra/aws_rds_event_subscriptions.tf
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,11 @@ | ||
resource "aws_db_event_subscription" "rds_event_subscription" { | ||
name = "rds-event-sub-${var.test_prefix}-${var.test_suffix}" | ||
sns_topic = aws_sns_topic.sns_test2.arn | ||
|
||
source_type = "db-instance" | ||
source_ids = [aws_db_instance.rds_db_instance.id] | ||
|
||
event_categories = [ | ||
"failure", | ||
] | ||
} |
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,138 @@ | ||
package resources | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/service/rds" | ||
"github.com/aws/aws-sdk-go-v2/service/rds/types" | ||
"github.com/cloudquery/cq-provider-aws/client" | ||
"github.com/cloudquery/cq-provider-sdk/provider/schema" | ||
) | ||
|
||
func RdsEventSubscriptions() *schema.Table { | ||
return &schema.Table{ | ||
Name: "aws_rds_event_subscriptions", | ||
Description: "Contains the results of a successful invocation of the DescribeEventSubscriptions action.", | ||
Resolver: fetchRdsEventSubscriptions, | ||
Multiplex: client.AccountRegionMultiplex, | ||
IgnoreError: client.IgnoreAccessDeniedServiceDisabled, | ||
DeleteFilter: client.DeleteAccountRegionFilter, | ||
Options: schema.TableCreationOptions{PrimaryKeys: []string{"arn"}}, | ||
Columns: []schema.Column{ | ||
{ | ||
Name: "account_id", | ||
Description: "The AWS Account ID of the resource.", | ||
Type: schema.TypeString, | ||
Resolver: client.ResolveAWSAccount, | ||
}, | ||
{ | ||
Name: "region", | ||
Description: "The AWS Region of the resource.", | ||
Type: schema.TypeString, | ||
Resolver: client.ResolveAWSRegion, | ||
}, | ||
{ | ||
Name: "cust_subscription_id", | ||
Description: "The RDS event notification subscription Id.", | ||
Type: schema.TypeString, | ||
}, | ||
{ | ||
Name: "customer_aws_id", | ||
Description: "The AWS customer account associated with the RDS event notification subscription.", | ||
Type: schema.TypeString, | ||
}, | ||
{ | ||
Name: "enabled", | ||
Description: "A Boolean value indicating if the subscription is enabled", | ||
Type: schema.TypeBool, | ||
}, | ||
{ | ||
Name: "event_categories_list", | ||
Description: "A list of event categories for the RDS event notification subscription.", | ||
Type: schema.TypeStringArray, | ||
}, | ||
{ | ||
Name: "arn", | ||
Description: "The Amazon Resource Name (ARN) for the event subscription.", | ||
Type: schema.TypeString, | ||
Resolver: schema.PathResolver("EventSubscriptionArn"), | ||
}, | ||
{ | ||
Name: "sns_topic_arn", | ||
Description: "The topic ARN of the RDS event notification subscription.", | ||
Type: schema.TypeString, | ||
}, | ||
{ | ||
Name: "source_ids_list", | ||
Description: "A list of source IDs for the RDS event notification subscription.", | ||
Type: schema.TypeStringArray, | ||
}, | ||
{ | ||
Name: "source_type", | ||
Description: "The source type for the RDS event notification subscription.", | ||
Type: schema.TypeString, | ||
}, | ||
{ | ||
Name: "status", | ||
Description: "The status of the RDS event notification subscription", | ||
Type: schema.TypeString, | ||
}, | ||
{ | ||
Name: "subscription_creation_time", | ||
Description: "The time the RDS event notification subscription was created.", | ||
Type: schema.TypeString, | ||
}, | ||
{ | ||
Name: "tags", | ||
Description: "List of tags", | ||
Type: schema.TypeJSON, | ||
Resolver: resolveRDSEventSubscriptionTags, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
// ==================================================================================================================== | ||
// Table Resolver Functions | ||
// ==================================================================================================================== | ||
func fetchRdsEventSubscriptions(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan interface{}) error { | ||
cl := meta.(*client.Client) | ||
svc := cl.Services().RDS | ||
var input rds.DescribeEventSubscriptionsInput | ||
for { | ||
out, err := svc.DescribeEventSubscriptions(ctx, &input, func(o *rds.Options) { | ||
o.Region = cl.Region | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
res <- out.EventSubscriptionsList | ||
if aws.ToString(out.Marker) == "" { | ||
break | ||
} | ||
input.Marker = out.Marker | ||
} | ||
return nil | ||
} | ||
|
||
func resolveRDSEventSubscriptionTags(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error { | ||
s, ok := resource.Item.(types.EventSubscription) | ||
if !ok { | ||
return fmt.Errorf("not a %T: %T", s, resource.Item) | ||
} | ||
cl := meta.(*client.Client) | ||
svc := cl.Services().RDS | ||
out, err := svc.ListTagsForResource(ctx, &rds.ListTagsForResourceInput{ResourceName: s.EventSubscriptionArn}, func(o *rds.Options) { | ||
o.Region = cl.Region | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
tags := make(map[string]string, len(out.TagList)) | ||
for _, t := range out.TagList { | ||
tags[aws.ToString(t.Key)] = aws.ToString(t.Value) | ||
} | ||
return resource.Set(c.Name, tags) | ||
} |
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,41 @@ | ||
package resources | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/service/rds" | ||
"github.com/aws/aws-sdk-go-v2/service/rds/types" | ||
"github.com/cloudquery/cq-provider-aws/client" | ||
"github.com/cloudquery/cq-provider-aws/client/mocks" | ||
"github.com/cloudquery/faker/v3" | ||
"github.com/golang/mock/gomock" | ||
) | ||
|
||
func buildRDSEventSubscriptions(t *testing.T, ctrl *gomock.Controller) client.Services { | ||
mock := mocks.NewMockRdsClient(ctrl) | ||
var s types.EventSubscription | ||
if err := faker.FakeData(&s); err != nil { | ||
t.Fatal(err) | ||
} | ||
mock.EXPECT().DescribeEventSubscriptions(gomock.Any(), &rds.DescribeEventSubscriptionsInput{}, gomock.Any()).Return( | ||
&rds.DescribeEventSubscriptionsOutput{EventSubscriptionsList: []types.EventSubscription{s}}, | ||
nil, | ||
) | ||
|
||
mock.EXPECT().ListTagsForResource( | ||
gomock.Any(), | ||
&rds.ListTagsForResourceInput{ResourceName: s.EventSubscriptionArn}, | ||
gomock.Any(), | ||
).Return( | ||
&rds.ListTagsForResourceOutput{ | ||
TagList: []types.Tag{{Key: aws.String("key"), Value: aws.String("value")}}, | ||
}, | ||
nil, | ||
) | ||
return client.Services{RDS: mock} | ||
} | ||
|
||
func TestRDSEventSubscriptions(t *testing.T) { | ||
awsTestHelper(t, RdsEventSubscriptions(), buildRDSEventSubscriptions, TestOptions{}) | ||
} |