|
| 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 | +} |
0 commit comments