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.
feat: Added lightsail database snapshots (#1263)
* feat: Added lightsail database snapshots * generate mock
- Loading branch information
Showing
7 changed files
with
271 additions
and
0 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,23 @@ | ||
|
||
# Table: aws_lightsail_database_snapshots | ||
Describes a database snapshot | ||
## Columns | ||
| Name | Type | Description | | ||
| ------------- | ------------- | ----- | | ||
|account_id|text|The AWS Account ID of the resource.| | ||
|region|text|The AWS Region of the resource.| | ||
|arn|text|The Amazon Resource Name (ARN) of the database snapshot| | ||
|created_at|timestamp without time zone|The timestamp when the database snapshot was created| | ||
|engine|text|The software of the database snapshot (for example, MySQL)| | ||
|engine_version|text|The database engine version for the database snapshot (for example, 5723)| | ||
|from_relational_database_arn|text|The Amazon Resource Name (ARN) of the database from which the database snapshot was created| | ||
|from_relational_database_blueprint_id|text|The blueprint ID of the database from which the database snapshot was created| | ||
|from_relational_database_bundle_id|text|The bundle ID of the database from which the database snapshot was created| | ||
|from_relational_database_name|text|The name of the source database from which the database snapshot was created| | ||
|availability_zone|text|The Availability Zone| | ||
|name|text|The name of the database snapshot| | ||
|resource_type|text|The Lightsail resource type| | ||
|size_in_gb|integer|The size of the disk in GB (for example, 32) for the database snapshot| | ||
|state|text|The state of the database snapshot| | ||
|support_code|text|The support code for the database snapshot| | ||
|tags|jsonb|The tag keys and optional values for the resource| |
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,147 @@ | ||
package lightsail | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/service/lightsail" | ||
"github.com/aws/aws-sdk-go-v2/service/lightsail/types" | ||
"github.com/cloudquery/cq-provider-aws/client" | ||
"github.com/cloudquery/cq-provider-sdk/provider/diag" | ||
"github.com/cloudquery/cq-provider-sdk/provider/schema" | ||
) | ||
|
||
//go:generate cq-gen --resource database_snapshots --config gen.hcl --output . | ||
func DatabaseSnapshots() *schema.Table { | ||
return &schema.Table{ | ||
Name: "aws_lightsail_database_snapshots", | ||
Description: "Describes a database snapshot", | ||
Resolver: fetchLightsailDatabaseSnapshots, | ||
Multiplex: client.ServiceAccountRegionMultiplexer("lightsail"), | ||
IgnoreError: client.IgnoreAccessDeniedServiceDisabled, | ||
DeleteFilter: client.DeleteAccountRegionFilter, | ||
Options: schema.TableCreationOptions{PrimaryKeys: []string{"arn"}}, | ||
IgnoreInTests: true, // can't be created using terraform. | ||
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: "arn", | ||
Description: "The Amazon Resource Name (ARN) of the database snapshot", | ||
Type: schema.TypeString, | ||
}, | ||
{ | ||
Name: "created_at", | ||
Description: "The timestamp when the database snapshot was created", | ||
Type: schema.TypeTimestamp, | ||
}, | ||
{ | ||
Name: "engine", | ||
Description: "The software of the database snapshot (for example, MySQL)", | ||
Type: schema.TypeString, | ||
}, | ||
{ | ||
Name: "engine_version", | ||
Description: "The database engine version for the database snapshot (for example, 5723)", | ||
Type: schema.TypeString, | ||
}, | ||
{ | ||
Name: "from_relational_database_arn", | ||
Description: "The Amazon Resource Name (ARN) of the database from which the database snapshot was created", | ||
Type: schema.TypeString, | ||
}, | ||
{ | ||
Name: "from_relational_database_blueprint_id", | ||
Description: "The blueprint ID of the database from which the database snapshot was created", | ||
Type: schema.TypeString, | ||
}, | ||
{ | ||
Name: "from_relational_database_bundle_id", | ||
Description: "The bundle ID of the database from which the database snapshot was created", | ||
Type: schema.TypeString, | ||
}, | ||
{ | ||
Name: "from_relational_database_name", | ||
Description: "The name of the source database from which the database snapshot was created", | ||
Type: schema.TypeString, | ||
}, | ||
{ | ||
Name: "availability_zone", | ||
Description: "The Availability Zone", | ||
Type: schema.TypeString, | ||
Resolver: schema.PathResolver("Location.AvailabilityZone"), | ||
}, | ||
{ | ||
Name: "name", | ||
Description: "The name of the database snapshot", | ||
Type: schema.TypeString, | ||
}, | ||
{ | ||
Name: "resource_type", | ||
Description: "The Lightsail resource type", | ||
Type: schema.TypeString, | ||
}, | ||
{ | ||
Name: "size_in_gb", | ||
Description: "The size of the disk in GB (for example, 32) for the database snapshot", | ||
Type: schema.TypeInt, | ||
}, | ||
{ | ||
Name: "state", | ||
Description: "The state of the database snapshot", | ||
Type: schema.TypeString, | ||
}, | ||
{ | ||
Name: "support_code", | ||
Description: "The support code for the database snapshot", | ||
Type: schema.TypeString, | ||
}, | ||
{ | ||
Name: "tags", | ||
Description: "The tag keys and optional values for the resource", | ||
Type: schema.TypeJSON, | ||
Resolver: resolveDatabaseSnapshotsTags, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
// ==================================================================================================================== | ||
// Table Resolver Functions | ||
// ==================================================================================================================== | ||
|
||
func fetchLightsailDatabaseSnapshots(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error { | ||
var input lightsail.GetRelationalDatabaseSnapshotsInput | ||
c := meta.(*client.Client) | ||
svc := c.Services().Lightsail | ||
for { | ||
response, err := svc.GetRelationalDatabaseSnapshots(ctx, &input, func(options *lightsail.Options) { | ||
options.Region = c.Region | ||
}) | ||
if err != nil { | ||
return diag.WrapError(err) | ||
} | ||
res <- response.RelationalDatabaseSnapshots | ||
if aws.ToString(response.NextPageToken) == "" { | ||
break | ||
} | ||
input.PageToken = response.NextPageToken | ||
} | ||
return nil | ||
} | ||
func resolveDatabaseSnapshotsTags(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error { | ||
r := resource.Item.(types.RelationalDatabaseSnapshot) | ||
tags := make(map[string]string) | ||
client.TagsIntoMap(r.Tags, tags) | ||
return diag.WrapError(resource.Set(c.Name, tags)) | ||
} |
32 changes: 32 additions & 0 deletions
32
resources/services/lightsail/database_snapshots_mock_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,32 @@ | ||
package lightsail | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go-v2/service/lightsail" | ||
"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 buildDatabaseSnapshotsMock(t *testing.T, ctrl *gomock.Controller) client.Services { | ||
m := mocks.NewMockLightsailClient(ctrl) | ||
|
||
s := lightsail.GetRelationalDatabaseSnapshotsOutput{} | ||
err := faker.FakeData(&s) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
s.NextPageToken = nil | ||
m.EXPECT().GetRelationalDatabaseSnapshots(gomock.Any(), gomock.Any(), gomock.Any()).Return( | ||
&s, nil) | ||
|
||
return client.Services{ | ||
Lightsail: m, | ||
} | ||
} | ||
|
||
func TestDatabaseSnapshots(t *testing.T) { | ||
client.AwsMockTestHelper(t, DatabaseSnapshots(), buildDatabaseSnapshotsMock, client.TestOptions{}) | ||
} |
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