Skip to content

Commit 750d878

Browse files
authored
feat: Add fsx snapshots (#1278)
1 parent 4d42f0e commit 750d878

7 files changed

Lines changed: 237 additions & 0 deletions

File tree

plugins/source/aws/client/mocks/fsx.go

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/source/aws/client/services.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ type FirehoseClient interface {
441441
type FsxClient interface {
442442
DescribeBackups(ctx context.Context, params *fsx.DescribeBackupsInput, optFns ...func(*fsx.Options)) (*fsx.DescribeBackupsOutput, error)
443443
DescribeFileSystems(ctx context.Context, params *fsx.DescribeFileSystemsInput, optFns ...func(*fsx.Options)) (*fsx.DescribeFileSystemsOutput, error)
444+
DescribeSnapshots(ctx context.Context, params *fsx.DescribeSnapshotsInput, optFns ...func(*fsx.Options)) (*fsx.DescribeSnapshotsOutput, error)
444445
}
445446

446447
//go:generate mockgen -package=mocks -destination=./mocks/glue.go . GlueClient
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
# Table: aws_fsx_snapshots
3+
A snapshot of an Amazon FSx for OpenZFS volume
4+
## Columns
5+
| Name | Type | Description |
6+
| ------------- | ------------- | ----- |
7+
|account_id|text|The AWS Account ID of the resource.|
8+
|region|text|The AWS Region of the resource.|
9+
|creation_time|timestamp without time zone|The time that the resource was created, in seconds (since 1970-01-01T00:00:00Z), also known as Unix time|
10+
|lifecycle|text|The lifecycle status of the snapshot * PENDING - Amazon FSx hasn't started creating the snapshot * CREATING - Amazon FSx is creating the snapshot * DELETING - Amazon FSx is deleting the snapshot * AVAILABLE - The snapshot is fully available|
11+
|lifecycle_transition_reason_message|text|A detailed error message|
12+
|name|text|The name of the snapshot|
13+
|arn|text|The Amazon Resource Name (ARN) for a given resource|
14+
|snapshot_id|text|The ID of the snapshot|
15+
|tags|jsonb|A list of Tag values, with a maximum of 50 elements|
16+
|volume_id|text|The ID of the volume that the snapshot is of|

plugins/source/aws/resources/provider/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ func Provider() *provider.Provider {
192192
"eventbridge.event_buses": eventbridge.EventBuses(),
193193
"fsx.backups": fsx.Backups(),
194194
"fsx.filesystems": fsx.Filesystems(),
195+
"fsx.snapshots": fsx.Snapshots(),
195196
"glue.classifiers": glue.Classifiers(),
196197
"glue.connections": glue.Connections(),
197198
"glue.crawlers": glue.Crawlers(),
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package fsx
2+
3+
import (
4+
"context"
5+
6+
"github.com/aws/aws-sdk-go-v2/aws"
7+
"github.com/aws/aws-sdk-go-v2/service/fsx"
8+
"github.com/aws/aws-sdk-go-v2/service/fsx/types"
9+
"github.com/cloudquery/cloudquery/plugins/source/aws/client"
10+
"github.com/cloudquery/cq-provider-sdk/provider/diag"
11+
"github.com/cloudquery/cq-provider-sdk/provider/schema"
12+
)
13+
14+
//go:generate cq-gen --resource snapshots --config snapshots.hcl --output .
15+
func Snapshots() *schema.Table {
16+
return &schema.Table{
17+
Name: "aws_fsx_snapshots",
18+
Description: "A snapshot of an Amazon FSx for OpenZFS volume",
19+
Resolver: fetchFsxSnapshots,
20+
Multiplex: client.ServiceAccountRegionMultiplexer("fsx"),
21+
IgnoreError: client.IgnoreAccessDeniedServiceDisabled,
22+
DeleteFilter: client.DeleteAccountRegionFilter,
23+
Options: schema.TableCreationOptions{PrimaryKeys: []string{"arn"}},
24+
Columns: []schema.Column{
25+
{
26+
Name: "account_id",
27+
Description: "The AWS Account ID of the resource.",
28+
Type: schema.TypeString,
29+
Resolver: client.ResolveAWSAccount,
30+
},
31+
{
32+
Name: "region",
33+
Description: "The AWS Region of the resource.",
34+
Type: schema.TypeString,
35+
Resolver: client.ResolveAWSRegion,
36+
},
37+
{
38+
Name: "creation_time",
39+
Description: "The time that the resource was created, in seconds (since 1970-01-01T00:00:00Z), also known as Unix time",
40+
Type: schema.TypeTimestamp,
41+
},
42+
{
43+
Name: "lifecycle",
44+
Description: "The lifecycle status of the snapshot * PENDING - Amazon FSx hasn't started creating the snapshot * CREATING - Amazon FSx is creating the snapshot * DELETING - Amazon FSx is deleting the snapshot * AVAILABLE - The snapshot is fully available",
45+
Type: schema.TypeString,
46+
},
47+
{
48+
Name: "lifecycle_transition_reason_message",
49+
Description: "A detailed error message",
50+
Type: schema.TypeString,
51+
Resolver: schema.PathResolver("LifecycleTransitionReason.Message"),
52+
},
53+
{
54+
Name: "name",
55+
Description: "The name of the snapshot",
56+
Type: schema.TypeString,
57+
},
58+
{
59+
Name: "arn",
60+
Description: "The Amazon Resource Name (ARN) for a given resource",
61+
Type: schema.TypeString,
62+
Resolver: schema.PathResolver("ResourceARN"),
63+
},
64+
{
65+
Name: "snapshot_id",
66+
Description: "The ID of the snapshot",
67+
Type: schema.TypeString,
68+
},
69+
{
70+
Name: "tags",
71+
Description: "A list of Tag values, with a maximum of 50 elements",
72+
Type: schema.TypeJSON,
73+
Resolver: resolveSnapshotsTags,
74+
},
75+
{
76+
Name: "volume_id",
77+
Description: "The ID of the volume that the snapshot is of",
78+
Type: schema.TypeString,
79+
},
80+
},
81+
}
82+
}
83+
84+
// ====================================================================================================================
85+
// Table Resolver Functions
86+
// ====================================================================================================================
87+
88+
func fetchFsxSnapshots(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error {
89+
cl := meta.(*client.Client)
90+
svc := cl.Services().FSX
91+
input := fsx.DescribeSnapshotsInput{MaxResults: aws.Int32(1000)}
92+
for {
93+
result, err := svc.DescribeSnapshots(ctx, &input)
94+
if err != nil {
95+
return diag.WrapError(err)
96+
}
97+
res <- result.Snapshots
98+
if aws.ToString(result.NextToken) == "" {
99+
break
100+
}
101+
input.NextToken = result.NextToken
102+
}
103+
return nil
104+
}
105+
func resolveSnapshotsTags(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error {
106+
return diag.WrapError(resource.Set(c.Name, client.TagsToMap(resource.Item.(types.Snapshot).Tags)))
107+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//check-for-changes
2+
service = "aws"
3+
output_directory = "."
4+
add_generate = true
5+
6+
description_modifier "remove_read_only" {
7+
words = [" This member is required."]
8+
}
9+
10+
resource "aws" "fsx" "snapshots" {
11+
path = "github.com/aws/aws-sdk-go-v2/service/fsx/types.Snapshot"
12+
ignoreError "IgnoreAccessDenied" {
13+
path = "github.com/cloudquery/cloudquery/plugins/source/aws/client.IgnoreAccessDeniedServiceDisabled"
14+
}
15+
deleteFilter "AccountRegionFilter" {
16+
path = "github.com/cloudquery/cloudquery/plugins/source/aws/client.DeleteAccountRegionFilter"
17+
}
18+
multiplex "AwsAccountRegion" {
19+
path = "github.com/cloudquery/cloudquery/plugins/source/aws/client.ServiceAccountRegionMultiplexer"
20+
params = ["fsx"]
21+
}
22+
options {
23+
primary_keys = ["arn"]
24+
}
25+
userDefinedColumn "account_id" {
26+
description = "The AWS Account ID of the resource."
27+
type = "string"
28+
resolver "resolveAWSAccount" {
29+
path = "github.com/cloudquery/cloudquery/plugins/source/aws/client.ResolveAWSAccount"
30+
}
31+
}
32+
userDefinedColumn "region" {
33+
type = "string"
34+
description = "The AWS Region of the resource."
35+
resolver "resolveAWSRegion" {
36+
path = "github.com/cloudquery/cloudquery/plugins/source/aws/client.ResolveAWSRegion"
37+
}
38+
}
39+
40+
column "resource_arn" {
41+
rename = "arn"
42+
}
43+
44+
column "administrative_actions" {
45+
skip = true
46+
}
47+
48+
column "tags" {
49+
type = "json"
50+
generate_resolver = true
51+
}
52+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package fsx
2+
3+
import (
4+
"testing"
5+
6+
"github.com/aws/aws-sdk-go-v2/aws"
7+
"github.com/aws/aws-sdk-go-v2/service/fsx"
8+
"github.com/aws/aws-sdk-go-v2/service/fsx/types"
9+
"github.com/cloudquery/cloudquery/plugins/source/aws/client"
10+
"github.com/cloudquery/cloudquery/plugins/source/aws/client/mocks"
11+
"github.com/cloudquery/faker/v3"
12+
"github.com/golang/mock/gomock"
13+
"github.com/stretchr/testify/require"
14+
)
15+
16+
func buildSnapshotsMock(t *testing.T, ctrl *gomock.Controller) client.Services {
17+
m := mocks.NewMockFsxClient(ctrl)
18+
19+
var s types.Snapshot
20+
require.NoError(t, faker.FakeDataSkipFields(&s, []string{
21+
"AdministrativeActions",
22+
"Lifecycle",
23+
}))
24+
s.Lifecycle = types.SnapshotLifecycleAvailable
25+
m.EXPECT().DescribeSnapshots(
26+
gomock.Any(),
27+
&fsx.DescribeSnapshotsInput{MaxResults: aws.Int32(1000)},
28+
).Return(
29+
&fsx.DescribeSnapshotsOutput{Snapshots: []types.Snapshot{s}},
30+
nil,
31+
)
32+
33+
return client.Services{
34+
FSX: m,
35+
}
36+
}
37+
38+
func TestSnapshots(t *testing.T) {
39+
client.AwsMockTestHelper(t, Snapshots(), buildSnapshotsMock, client.TestOptions{})
40+
}

0 commit comments

Comments
 (0)