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.
* draft * Added ec2.ebs_volumes argument to fetch EBS volumes * Added Attachments, mocks and tests Co-authored-by: Daniils Kostornijs <[email protected]>
- Loading branch information
Showing
8 changed files
with
211 additions
and
21 deletions.
There are no files selected for viewing
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
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
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,167 @@ | ||
package resources | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go-v2/service/ec2" | ||
"github.com/aws/aws-sdk-go-v2/service/ec2/types" | ||
"github.com/cloudquery/cq-provider-aws/client" | ||
"github.com/cloudquery/cq-provider-sdk/provider/schema" | ||
) | ||
|
||
func Ec2EbsVolumes() *schema.Table { | ||
return &schema.Table{ | ||
Name: "aws_ec2_ebs_volumes", | ||
Resolver: fetchEc2EbsVolumes, | ||
Multiplex: client.AccountRegionMultiplex, | ||
IgnoreError: client.IgnoreAccessDeniedServiceDisabled, | ||
DeleteFilter: client.DeleteAccountRegionFilter, | ||
Columns: []schema.Column{ | ||
{ | ||
Name: "account_id", | ||
Type: schema.TypeString, | ||
Resolver: client.ResolveAWSAccount, | ||
}, | ||
{ | ||
Name: "region", | ||
Type: schema.TypeString, | ||
Resolver: client.ResolveAWSRegion, | ||
}, | ||
{ | ||
Name: "volume_id", | ||
Type: schema.TypeString, | ||
}, | ||
{ | ||
Name: "availability_zone", | ||
Type: schema.TypeString, | ||
}, | ||
{ | ||
Name: "create_time", | ||
Type: schema.TypeTimestamp, | ||
}, | ||
{ | ||
Name: "encrypted", | ||
Type: schema.TypeBool, | ||
}, | ||
{ | ||
Name: "fast_restored", | ||
Type: schema.TypeBool, | ||
}, | ||
{ | ||
Name: "iops", | ||
Type: schema.TypeInt, | ||
}, | ||
{ | ||
Name: "kms_key_id", | ||
Type: schema.TypeString, | ||
}, | ||
{ | ||
Name: "multi_attach_enabled", | ||
Type: schema.TypeBool, | ||
}, | ||
{ | ||
Name: "outpost_arn", | ||
Type: schema.TypeString, | ||
}, | ||
{ | ||
Name: "size", | ||
Type: schema.TypeInt, | ||
}, | ||
{ | ||
Name: "snapshot_id", | ||
Type: schema.TypeString, | ||
}, | ||
{ | ||
Name: "state", | ||
Type: schema.TypeString, | ||
}, | ||
{ | ||
Name: "tags", | ||
Type: schema.TypeJSON, | ||
Resolver: resolveEc2EbsVolumeTags, | ||
}, | ||
{ | ||
Name: "throughput", | ||
Type: schema.TypeInt, | ||
}, | ||
{ | ||
Name: "volume_type", | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
Relations: []*schema.Table{ | ||
{ | ||
Name: "aws_ec2_ebs_volume_attachments", | ||
Resolver: fetchEc2EbsVolumeAttachments, | ||
Columns: []schema.Column{ | ||
{ | ||
Name: "ebs_volume_id", | ||
Type: schema.TypeUUID, | ||
Resolver: schema.ParentIdResolver, | ||
}, | ||
{ | ||
Name: "attach_time", | ||
Type: schema.TypeTimestamp, | ||
}, | ||
{ | ||
Name: "delete_on_termination", | ||
Type: schema.TypeBool, | ||
}, | ||
{ | ||
Name: "device", | ||
Type: schema.TypeString, | ||
}, | ||
{ | ||
Name: "instance_id", | ||
Type: schema.TypeString, | ||
}, | ||
{ | ||
Name: "state", | ||
Type: schema.TypeString, | ||
}, | ||
{ | ||
Name: "volume_id", | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
// ==================================================================================================================== | ||
// Table Resolver Functions | ||
// ==================================================================================================================== | ||
func fetchEc2EbsVolumes(ctx context.Context, meta schema.ClientMeta, _ *schema.Resource, res chan interface{}) error { | ||
c := meta.(*client.Client) | ||
svc := c.Services().EC2 | ||
|
||
response, err := svc.DescribeVolumes(ctx, &ec2.DescribeVolumesInput{}, func(o *ec2.Options) { | ||
o.Region = c.Region | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
for _, volume := range response.Volumes { | ||
res <- volume | ||
} | ||
return nil | ||
} | ||
func resolveEc2EbsVolumeTags(_ context.Context, _ schema.ClientMeta, resource *schema.Resource, _ schema.Column) error { | ||
r := resource.Item.(types.Volume) | ||
tags := map[string]*string{} | ||
for _, t := range r.Tags { | ||
tags[*t.Key] = t.Value | ||
} | ||
resource.Set("tags", tags) | ||
return nil | ||
} | ||
func fetchEc2EbsVolumeAttachments(_ context.Context, _ schema.ClientMeta, parent *schema.Resource, res chan interface{}) error { | ||
volume, ok := parent.Item.(types.Volume) | ||
if !ok { | ||
return fmt.Errorf("not ec2 ebs volume") | ||
} | ||
res <- volume.Attachments | ||
return nil | ||
} |
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