Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

Commit

Permalink
Add DMS Replication Instance (#280)
Browse files Browse the repository at this point in the history
* Add DMS Replication Instance
  • Loading branch information
spangenberg authored Nov 24, 2021
1 parent c22a1eb commit f16316f
Show file tree
Hide file tree
Showing 14 changed files with 546 additions and 11 deletions.
3 changes: 3 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/aws/aws-sdk-go-v2/service/cognitoidentity"
"github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider"
"github.com/aws/aws-sdk-go-v2/service/configservice"
"github.com/aws/aws-sdk-go-v2/service/databasemigrationservice"
"github.com/aws/aws-sdk-go-v2/service/directconnect"
"github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/aws/aws-sdk-go-v2/service/ec2/types"
Expand Down Expand Up @@ -101,6 +102,7 @@ type Services struct {
CognitoIdentityPools CognitoIdentityPoolsClient
CognitoUserPools CognitoUserPoolsClient
Directconnect DirectconnectClient
DMS DatabasemigrationserviceClient
ECR EcrClient
ECS EcsClient
EC2 Ec2Client
Expand Down Expand Up @@ -360,6 +362,7 @@ func initServices(region string, c aws.Config) Services {
CognitoUserPools: cognitoidentityprovider.NewFromConfig(awsCfg),
ConfigService: configservice.NewFromConfig(awsCfg),
Directconnect: directconnect.NewFromConfig(awsCfg),
DMS: databasemigrationservice.NewFromConfig(awsCfg),
EC2: ec2.NewFromConfig(awsCfg),
ECR: ecr.NewFromConfig(awsCfg),
ECS: ecs.NewFromConfig(awsCfg),
Expand Down
37 changes: 34 additions & 3 deletions client/mocks/builders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"testing"

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

"github.com/aws/aws-sdk-go-v2/service/autoscaling"
autoscalingTypes "github.com/aws/aws-sdk-go-v2/service/autoscaling/types"
"github.com/aws/aws-sdk-go-v2/service/cloudfront"
Expand All @@ -13,6 +12,8 @@ import (
cloudwatchTypes "github.com/aws/aws-sdk-go-v2/service/cloudwatch/types"
"github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs"
cloudwatchlogsTypes "github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs/types"
"github.com/aws/aws-sdk-go-v2/service/databasemigrationservice"
databasemigrationserviceTypes "github.com/aws/aws-sdk-go-v2/service/databasemigrationservice/types"
"github.com/aws/aws-sdk-go-v2/service/directconnect"
directconnectTypes "github.com/aws/aws-sdk-go-v2/service/directconnect/types"
"github.com/aws/aws-sdk-go-v2/service/ec2"
Expand All @@ -34,10 +35,12 @@ import (
route53Types "github.com/aws/aws-sdk-go-v2/service/route53/types"
"github.com/aws/aws-sdk-go-v2/service/sns"
snsTypes "github.com/aws/aws-sdk-go-v2/service/sns/types"
"github.com/golang/mock/gomock"

"github.com/cloudquery/faker/v3"

"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 buildAutoscalingLaunchConfigurationsMock(t *testing.T, ctrl *gomock.Controller) client.Services {
Expand Down Expand Up @@ -290,6 +293,34 @@ func buildDirectconnectVirtualInterfacesMock(t *testing.T, ctrl *gomock.Controll
}
}

func buildDmsReplicationInstances(t *testing.T, ctrl *gomock.Controller) client.Services {
m := mocks.NewMockDatabasemigrationserviceClient(ctrl)
l := databasemigrationserviceTypes.ReplicationInstance{}
if err := faker.FakeData(&l); err != nil {
t.Fatal(err)
}
l.ReplicationInstancePrivateIpAddress = aws.String("1.2.3.4")
l.ReplicationInstancePrivateIpAddresses = []string{"1.2.3.4"}
l.ReplicationInstancePublicIpAddress = aws.String("1.2.3.4")
l.ReplicationInstancePublicIpAddresses = []string{"1.2.3.4"}
m.EXPECT().DescribeReplicationInstances(gomock.Any(), gomock.Any(), gomock.Any()).Return(
&databasemigrationservice.DescribeReplicationInstancesOutput{
ReplicationInstances: []databasemigrationserviceTypes.ReplicationInstance{l},
}, nil)
lt := databasemigrationserviceTypes.Tag{}
if err := faker.FakeData(&lt); err != nil {
t.Fatal(err)
}
lt.ResourceArn = l.ReplicationInstanceArn
m.EXPECT().ListTagsForResource(gomock.Any(), gomock.Any(), gomock.Any()).Return(
&databasemigrationservice.ListTagsForResourceOutput{
TagList: []databasemigrationserviceTypes.Tag{lt},
}, nil)
return client.Services{
DMS: m,
}
}

func buildEc2ByoipCidrsMock(t *testing.T, ctrl *gomock.Controller) client.Services {
m := mocks.NewMockEc2Client(ctrl)
l := ec2Types.ByoipCidr{}
Expand Down
76 changes: 76 additions & 0 deletions client/mocks/mock_databasemigrationservice.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions client/mocks/resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import (
"os"
"testing"

providertest "github.com/cloudquery/cq-provider-sdk/provider/testing"

"github.com/cloudquery/cq-provider-aws/client"
"github.com/cloudquery/cq-provider-aws/resources"
"github.com/cloudquery/cq-provider-sdk/logging"
"github.com/cloudquery/cq-provider-sdk/provider/schema"
providertest "github.com/cloudquery/cq-provider-sdk/provider/testing"
"github.com/cloudquery/faker/v3"
"github.com/golang/mock/gomock"
"github.com/hashicorp/go-hclog"
"github.com/jackc/pgx/v4"

"github.com/cloudquery/cq-provider-aws/client"
"github.com/cloudquery/cq-provider-aws/resources"
)

type TestResource struct {
Expand Down Expand Up @@ -84,6 +84,11 @@ func TestResources(t *testing.T) {
mockBuilder: buildDirectconnectVirtualInterfacesMock,
mainTable: resources.DirectconnectVirtualInterfaces(),
},
{
resource: "dms.replication_instances",
mockBuilder: buildDmsReplicationInstances,
mainTable: resources.DmsReplicationInstances(),
},
{
resource: "ec2.customer_gateways",
mockBuilder: buildEc2CustomerGateways,
Expand Down
7 changes: 7 additions & 0 deletions client/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/aws/aws-sdk-go-v2/service/cognitoidentity"
"github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider"
"github.com/aws/aws-sdk-go-v2/service/configservice"
"github.com/aws/aws-sdk-go-v2/service/databasemigrationservice"
"github.com/aws/aws-sdk-go-v2/service/directconnect"
"github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/aws/aws-sdk-go-v2/service/ecr"
Expand Down Expand Up @@ -146,6 +147,12 @@ type DirectconnectClient interface {
DescribeVirtualInterfaces(ctx context.Context, params *directconnect.DescribeVirtualInterfacesInput, optFns ...func(*directconnect.Options)) (*directconnect.DescribeVirtualInterfacesOutput, error)
}

//go:generate mockgen -package=mocks -destination=./mocks/mock_databasemigrationservice.go . DatabasemigrationserviceClient
type DatabasemigrationserviceClient interface {
DescribeReplicationInstances(ctx context.Context, params *databasemigrationservice.DescribeReplicationInstancesInput, optFns ...func(*databasemigrationservice.Options)) (*databasemigrationservice.DescribeReplicationInstancesOutput, error)
ListTagsForResource(ctx context.Context, params *databasemigrationservice.ListTagsForResourceInput, optFns ...func(*databasemigrationservice.Options)) (*databasemigrationservice.ListTagsForResourceOutput, error)
}

//go:generate mockgen -package=mocks -destination=./mocks/mock_ec2.go . Ec2Client
type Ec2Client interface {
DescribeRegions(ctx context.Context, params *ec2.DescribeRegionsInput, optFns ...func(*ec2.Options)) (*ec2.DescribeRegionsOutput, error)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

# Table: aws_dms_replication_instance_replication_subnet_group_subnets
In response to a request by the DescribeReplicationSubnetGroups operation, this object identifies a subnet by its given Availability Zone, subnet identifier, and status.
## Columns
| Name | Type | Description |
| ------------- | ------------- | ----- |
|replication_instance_cq_id|uuid|Unique CloudQuery ID of aws_dms_replication_instances table (FK)|
|subnet_availability_zone_name|text|The name of the Availability Zone.|
|subnet_identifier|text|The subnet identifier.|
|subnet_status|text|The status of the subnet.|
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

# Table: aws_dms_replication_instance_vpc_security_groups
Describes the status of a security group associated with the virtual private cloud (VPC) hosting your replication and DB instances.
## Columns
| Name | Type | Description |
| ------------- | ------------- | ----- |
|replication_instance_cq_id|uuid|Unique CloudQuery ID of aws_dms_replication_instances table (FK)|
|status|text|The status of the VPC security group.|
|vpc_security_group_id|text|The VPC security group ID.|
37 changes: 37 additions & 0 deletions docs/tables/aws_dms_replication_instances.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

# Table: aws_dms_replication_instances
Provides information that defines a replication instance.
## Columns
| Name | Type | Description |
| ------------- | ------------- | ----- |
|account_id|text|The AWS Account ID of the resource.|
|region|text|The AWS Region of the resource.|
|tags|jsonb|Any tags assigned to the resource|
|allocated_storage|integer|The amount of storage (in gigabytes) that is allocated for the replication instance.|
|auto_minor_version_upgrade|boolean|Boolean value indicating if minor version upgrades will be automatically applied to the instance.|
|availability_zone|text|The Availability Zone for the instance.|
|dns_name_servers|text|The DNS name servers supported for the replication instance to access your on-premise source or target database.|
|engine_version|text|The engine version number of the replication instance|
|free_until|timestamp without time zone|The expiration date of the free replication instance that is part of the Free DMS program.|
|instance_create_time|timestamp without time zone|The time the replication instance was created.|
|kms_key_id|text|An KMS key identifier that is used to encrypt the data on the replication instance|
|multi_az|boolean|Specifies whether the replication instance is a Multi-AZ deployment|
|pending_modified_values_allocated_storage|integer|The amount of storage (in gigabytes) that is allocated for the replication instance.|
|pending_modified_values_engine_version|text|The engine version number of the replication instance.|
|pending_modified_values_multi_az|boolean|Specifies whether the replication instance is a Multi-AZ deployment|
|pending_modified_values_class|text|The compute and memory capacity of the replication instance as defined for the specified replication instance class|
|preferred_maintenance_window|text|The maintenance window times for the replication instance|
|publicly_accessible|boolean|Specifies the accessibility options for the replication instance|
|arn|text|The Amazon Resource Name (ARN) of the replication instance.|
|class|text|The compute and memory capacity of the replication instance as defined for the specified replication instance class|
|identifier|text|The replication instance identifier is a required parameter|
|private_ip_address|inet|The private IP address of the replication instance. Deprecated: This member has been deprecated.|
|private_ip_addresses|inet[]|One or more private IP addresses for the replication instance.|
|public_ip_address|inet|The public IP address of the replication instance. Deprecated: This member has been deprecated.|
|public_ip_addresses|inet[]|One or more public IP addresses for the replication instance.|
|status|text|The status of the replication instance|
|replication_subnet_group_description|text|A description for the replication subnet group.|
|replication_subnet_group_identifier|text|The identifier of the replication instance subnet group.|
|replication_subnet_group_subnet_group_status|text|The status of the subnet group.|
|replication_subnet_group_vpc_id|text|The ID of the VPC.|
|secondary_availability_zone|text|The Availability Zone of the standby replication instance in a Multi-AZ deployment.|
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/cognitoidentity v1.3.1
github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider v1.3.3
github.com/aws/aws-sdk-go-v2/service/configservice v1.5.1
github.com/aws/aws-sdk-go-v2/service/databasemigrationservice v1.12.0
github.com/aws/aws-sdk-go-v2/service/directconnect v1.4.1
github.com/aws/aws-sdk-go-v2/service/ec2 v1.16.0
github.com/aws/aws-sdk-go-v2/service/ecr v1.2.0
Expand Down Expand Up @@ -49,7 +50,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/waf v1.2.1
github.com/aws/aws-sdk-go-v2/service/wafv2 v1.5.1
github.com/aws/smithy-go v1.9.0
github.com/cloudquery/cq-provider-sdk v0.5.1
github.com/cloudquery/cq-provider-sdk v0.5.2
github.com/cloudquery/faker/v3 v3.7.5
github.com/gocarina/gocsv v0.0.0-20210516172204-ca9e8a8ddea8
github.com/golang/mock v1.6.0
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider v1.3.3 h1:IXdOmBAbB
github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider v1.3.3/go.mod h1:pGkyEZbQnRNds1m9YQXBAySf1vvriQp8dPHHF7/WMd8=
github.com/aws/aws-sdk-go-v2/service/configservice v1.5.1 h1:igD4rC85NHdUmiuQXanoSoTcqm+rOLPocgVDR/RX70g=
github.com/aws/aws-sdk-go-v2/service/configservice v1.5.1/go.mod h1:efUKiPp2CUVafK4KyqmqZYQ6hDGNsTk4KBnXMo88wqQ=
github.com/aws/aws-sdk-go-v2/service/databasemigrationservice v1.12.0 h1:gA5e9bNVqvH0mblX9859g2Co0wydd50MEAkq1S/c02k=
github.com/aws/aws-sdk-go-v2/service/databasemigrationservice v1.12.0/go.mod h1:+hQLUNCCL6W5nQuc3XXM/FTZtwx8mn3weKXZgcpBfCg=
github.com/aws/aws-sdk-go-v2/service/directconnect v1.4.1 h1:5rRF1Jf+PPIV9AmcbH54MPUlAFvon2+L+gnPZP0zzvI=
github.com/aws/aws-sdk-go-v2/service/directconnect v1.4.1/go.mod h1:LqxpptZWyNW7ussTuz4Sy9QWt5Y1X7o/f1hskqQ+qU0=
github.com/aws/aws-sdk-go-v2/service/ec2 v1.16.0 h1:ldzPZKVNRgz1kuteSua3m90ypksWIOXeIa6xGpqkxxk=
Expand Down Expand Up @@ -304,8 +306,8 @@ github.com/cilium/ebpf v0.4.0/go.mod h1:4tRaxcgiL706VnOzHOdBlY8IEAIdxINsQBcU4xJJ
github.com/cilium/ebpf v0.6.2/go.mod h1:4tRaxcgiL706VnOzHOdBlY8IEAIdxINsQBcU4xJJXRs=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58/go.mod h1:EOBUe0h4xcZ5GoxqC5SDxFQ8gwyZPKQoEzownBlhI80=
github.com/cloudquery/cq-provider-sdk v0.5.1 h1:nRR4Pa1HTFrlTABKSxxclgiQNKktw0tJMHZbD79HLIg=
github.com/cloudquery/cq-provider-sdk v0.5.1/go.mod h1:R9dd0bLv9GM4KH+ckxRpvkzSYoWAE3Z0me2v2w5uCJA=
github.com/cloudquery/cq-provider-sdk v0.5.2 h1:kNPKpY5sk8kHwETpx+l7eAROw6UEp7/R+EmMVBeUS2A=
github.com/cloudquery/cq-provider-sdk v0.5.2/go.mod h1:R9dd0bLv9GM4KH+ckxRpvkzSYoWAE3Z0me2v2w5uCJA=
github.com/cloudquery/faker/v3 v3.7.4/go.mod h1:1b8WVG9Gh0T2hVo1a8dWeXfu0AhqSB6J/mmJaesqOeo=
github.com/cloudquery/faker/v3 v3.7.5 h1:G7ANdEEcm8TvAAjIwNWSLrYK36CFCiSlrCqOTGCccL0=
github.com/cloudquery/faker/v3 v3.7.5/go.mod h1:1b8WVG9Gh0T2hVo1a8dWeXfu0AhqSB6J/mmJaesqOeo=
Expand Down
Loading

0 comments on commit f16316f

Please sign in to comment.