Skip to content

Commit 87347f9

Browse files
authored
fix: Generate EC2 resources that were not being generated (#2124)
And some cleanup
1 parent 5039788 commit 87347f9

File tree

10 files changed

+86
-141
lines changed

10 files changed

+86
-141
lines changed

plugins/source/aws/codegen/recipes/ec2.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package recipes
22

33
import (
44
"github.com/aws/aws-sdk-go-v2/service/ec2/types"
5+
"github.com/cloudquery/cloudquery/plugins/source/aws/resources/services/ec2/models"
56
"github.com/cloudquery/plugin-sdk/codegen"
67
"github.com/cloudquery/plugin-sdk/schema"
78
)
@@ -256,6 +257,24 @@ func EC2Resources() []*Resource {
256257
},
257258
}...),
258259
},
260+
{
261+
SubService: "regional_config",
262+
Struct: &models.RegionalConfig{},
263+
ExtraColumns: []codegen.ColumnDefinition{
264+
{
265+
Name: "account_id",
266+
Type: schema.TypeString,
267+
Resolver: `client.ResolveAWSAccount`,
268+
Options: schema.ColumnCreationOptions{PrimaryKey: true},
269+
},
270+
{
271+
Name: "region",
272+
Type: schema.TypeString,
273+
Resolver: `client.ResolveAWSRegion`,
274+
Options: schema.ColumnCreationOptions{PrimaryKey: true},
275+
},
276+
},
277+
},
259278
{
260279
SubService: "route_tables",
261280
Struct: &types.RouteTable{},

plugins/source/aws/docs/tables/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
|aws_ec2_nat_gateways||
6464
|aws_ec2_network_acls||
6565
|aws_ec2_network_interfaces||
66-
|aws_ec2_regional_config|Ec2 Regional Config defines common default configuration for ec2 service|
66+
|aws_ec2_regional_config||
6767
|aws_regions|Describes a Region.|
6868
|aws_ec2_route_tables||
6969
|aws_ec2_security_groups||

plugins/source/aws/docs/tables/aws_ec2_regional_config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Table: aws_ec2_regional_config
2-
Ec2 Regional Config defines common default configuration for ec2 service
2+
33

44
The composite primary key for this table is (**account_id**, **region**).
55

plugins/source/aws/resources/plugin/tables.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func tables() []*schema.Table {
134134
ec2.NatGateways(),
135135
ec2.NetworkAcls(),
136136
ec2.NetworkInterfaces(),
137-
ec2.Ec2RegionalConfig(),
137+
ec2.RegionalConfig(),
138138
ec2.AwsRegions(),
139139
ec2.RouteTables(),
140140
ec2.SecurityGroups(),
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package models
2+
3+
type RegionalConfig struct {
4+
EbsEncryptionEnabledByDefault bool
5+
EbsDefaultKmsKeyId *string
6+
}

plugins/source/aws/resources/services/ec2/regional_config.go

Lines changed: 24 additions & 51 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package ec2
2+
3+
import (
4+
"context"
5+
"github.com/aws/aws-sdk-go-v2/service/ec2"
6+
"github.com/cloudquery/cloudquery/plugins/source/aws/client"
7+
"github.com/cloudquery/cloudquery/plugins/source/aws/resources/services/ec2/models"
8+
"github.com/cloudquery/plugin-sdk/schema"
9+
)
10+
11+
func fetchEc2RegionalConfig(ctx context.Context, meta schema.ClientMeta, _ *schema.Resource, res chan<- interface{}) error {
12+
c := meta.(*client.Client)
13+
14+
svc := c.Services().EC2
15+
var regionalConfig models.RegionalConfig
16+
resp, err := svc.GetEbsDefaultKmsKeyId(ctx, &ec2.GetEbsDefaultKmsKeyIdInput{})
17+
if err != nil {
18+
return err
19+
}
20+
regionalConfig.EbsDefaultKmsKeyId = resp.KmsKeyId
21+
22+
ebsResp, err := svc.GetEbsEncryptionByDefault(ctx, &ec2.GetEbsEncryptionByDefaultInput{})
23+
if err != nil {
24+
return err
25+
}
26+
27+
if ebsResp.EbsEncryptionByDefault != nil {
28+
regionalConfig.EbsEncryptionEnabledByDefault = *ebsResp.EbsEncryptionByDefault
29+
}
30+
res <- regionalConfig
31+
return nil
32+
}

plugins/source/aws/resources/services/ec2/regional_config_mock_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ func buildEc2RegionalConfig(t *testing.T, ctrl *gomock.Controller) client.Servic
2121
}
2222

2323
func TestEc2RegionalConfig(t *testing.T) {
24-
client.AwsMockTestHelper(t, Ec2RegionalConfig(), buildEc2RegionalConfig, client.TestOptions{})
24+
client.AwsMockTestHelper(t, RegionalConfig(), buildEc2RegionalConfig, client.TestOptions{})
2525
}

plugins/source/aws/resources/services/ec2/security_groups_fetch.go

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -11,91 +11,6 @@ import (
1111
"github.com/cloudquery/plugin-sdk/schema"
1212
)
1313

14-
func Ec2SecurityGroups() *schema.Table {
15-
return &schema.Table{
16-
Name: "aws_ec2_security_groups",
17-
Description: "Describes a security group .",
18-
Resolver: fetchEc2SecurityGroups,
19-
Multiplex: client.ServiceAccountRegionMultiplexer("ec2"),
20-
Columns: []schema.Column{
21-
{
22-
Name: "account_id",
23-
Description: "The AWS Account ID of the resource.",
24-
Type: schema.TypeString,
25-
Resolver: client.ResolveAWSAccount,
26-
CreationOptions: schema.ColumnCreationOptions{PrimaryKey: true},
27-
},
28-
{
29-
Name: "region",
30-
Description: "The AWS Region of the resource.",
31-
Type: schema.TypeString,
32-
Resolver: client.ResolveAWSRegion,
33-
},
34-
{
35-
Name: "arn",
36-
Description: "The Amazon Resource Name (ARN) for the resource.",
37-
Type: schema.TypeString,
38-
Resolver: client.ResolveARN(client.EC2Service, func(resource *schema.Resource) ([]string, error) {
39-
return []string{"security-group", *resource.Item.(types.SecurityGroup).GroupId}, nil
40-
}),
41-
},
42-
{
43-
Name: "description",
44-
Description: "A description of the security group.",
45-
Type: schema.TypeString,
46-
},
47-
{
48-
Name: "id",
49-
Description: "The ID of the security group.",
50-
Type: schema.TypeString,
51-
Resolver: schema.PathResolver("GroupId"),
52-
CreationOptions: schema.ColumnCreationOptions{PrimaryKey: true},
53-
},
54-
{
55-
Name: "group_name",
56-
Description: "The name of the security group.",
57-
Type: schema.TypeString,
58-
IgnoreInTests: true,
59-
},
60-
{
61-
Name: "owner_id",
62-
Description: "The AWS account ID of the owner of the security group.",
63-
Type: schema.TypeString,
64-
Resolver: schema.PathResolver("OwnerId"),
65-
},
66-
{
67-
Name: "tags",
68-
Description: "Any tags assigned to the security group.",
69-
Type: schema.TypeJSON,
70-
Resolver: client.ResolveTags,
71-
},
72-
{
73-
Name: "vpc_id",
74-
Description: "The ID of the VPC for the security group.",
75-
Type: schema.TypeString,
76-
IgnoreInTests: true,
77-
},
78-
{
79-
Name: "ip_permissions",
80-
Description: "Describes a set of permissions for a security group rule.",
81-
Type: schema.TypeJSON,
82-
Resolver: schema.PathResolver("IpPermissions"),
83-
},
84-
{
85-
Name: "ip_permissions_egress",
86-
Description: "Describes a set of egress permissions for a security group rule.",
87-
Type: schema.TypeJSON,
88-
Resolver: schema.PathResolver("IpPermissionsEgress"),
89-
},
90-
},
91-
}
92-
}
93-
94-
// ====================================================================================================================
95-
//
96-
// Table Resolver Functions
97-
//
98-
// ====================================================================================================================
9914
func fetchEc2SecurityGroups(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error {
10015
var config ec2.DescribeSecurityGroupsInput
10116
c := meta.(*client.Client)

plugins/source/aws/resources/services/ec2/security_groups_mock_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ func buildEc2SecurityGroups(t *testing.T, ctrl *gomock.Controller) client.Servic
2828
}
2929

3030
func TestEc2SecurityGroups(t *testing.T) {
31-
client.AwsMockTestHelper(t, Ec2SecurityGroups(), buildEc2SecurityGroups, client.TestOptions{})
31+
client.AwsMockTestHelper(t, SecurityGroups(), buildEc2SecurityGroups, client.TestOptions{})
3232
}

0 commit comments

Comments
 (0)