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/add support for ebs encryption (#76)
* add support for ebs encryption
- Loading branch information
Showing
5 changed files
with
140 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,71 @@ | ||
package resources | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/aws-sdk-go-v2/service/ec2" | ||
"github.com/cloudquery/cq-provider-aws/client" | ||
"github.com/cloudquery/cq-provider-sdk/provider/schema" | ||
) | ||
|
||
func Ec2RegionalConfig() *schema.Table { | ||
return &schema.Table{ | ||
Name: "aws_ec2_regional_config", | ||
Description: "Ec2 Regional Config defines common default configuration for ec2 service", | ||
Resolver: fetchEc2RegionalConfig, | ||
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: "ebs_encryption_enabled_by_default", | ||
Type: schema.TypeBool, | ||
Description: "Indicates whether EBS encryption by default is enabled for your account in the current Region.", | ||
}, | ||
{ | ||
Name: "ebs_default_kms_key_id", | ||
Type: schema.TypeString, | ||
Description: "The Amazon Resource Name (ARN) of the default CMK for encryption by default.", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func fetchEc2RegionalConfig(ctx context.Context, meta schema.ClientMeta, _ *schema.Resource, res chan interface{}) error { | ||
c := meta.(*client.Client) | ||
|
||
svc := c.Services().EC2 | ||
var regionalConfig ec2RegionalConfig | ||
resp, err := svc.GetEbsDefaultKmsKeyId(ctx, &ec2.GetEbsDefaultKmsKeyIdInput{}, func(options *ec2.Options) { | ||
options.Region = c.Region | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
regionalConfig.EbsDefaultKmsKeyId = resp.KmsKeyId | ||
|
||
ebsResp, err := svc.GetEbsEncryptionByDefault(ctx, &ec2.GetEbsEncryptionByDefaultInput{}, func(options *ec2.Options) { | ||
options.Region = c.Region | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
regionalConfig.EbsEncryptionEnabledByDefault = ebsResp.EbsEncryptionByDefault | ||
res <- regionalConfig | ||
return nil | ||
} | ||
|
||
type ec2RegionalConfig struct { | ||
EbsEncryptionEnabledByDefault bool | ||
EbsDefaultKmsKeyId *string | ||
} |
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,26 @@ | ||
package resources | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/service/ec2" | ||
|
||
"github.com/cloudquery/cq-provider-aws/client" | ||
"github.com/cloudquery/cq-provider-aws/client/mocks" | ||
"github.com/golang/mock/gomock" | ||
) | ||
|
||
func buildEc2RegionalConfig(t *testing.T, ctrl *gomock.Controller) client.Services { | ||
m := mocks.NewMockEc2Client(ctrl) | ||
m.EXPECT().GetEbsDefaultKmsKeyId(gomock.Any(), gomock.Any(), gomock.Any()).Return(&ec2.GetEbsDefaultKmsKeyIdOutput{KmsKeyId: aws.String("some/key/id")}, nil) | ||
m.EXPECT().GetEbsEncryptionByDefault(gomock.Any(), gomock.Any(), gomock.Any()).Return(&ec2.GetEbsEncryptionByDefaultOutput{EbsEncryptionByDefault: true}, nil) | ||
|
||
return client.Services{ | ||
EC2: m, | ||
} | ||
} | ||
|
||
func TestEc2RegionalConfig(t *testing.T) { | ||
awsTestHelper(t, Ec2RegionalConfig(), buildEc2RegionalConfig) | ||
} |
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