Skip to content

Commit

Permalink
✨ Add AWS VPC subnet resource
Browse files Browse the repository at this point in the history
  • Loading branch information
mariuskimmina committed Sep 21, 2023
1 parent c345e42 commit 39f3623
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 0 deletions.
10 changes: 10 additions & 0 deletions providers/aws/resources/aws.lr
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ private aws.vpc @defaults("arn isDefault") {
flowLogs() []aws.vpc.flowlog
// List of route tables for the VPC
routeTables() []aws.vpc.routetable
// List of subnets for the VPC
subnets() []aws.vpc.subnet
// Tags on the VPC
tags map[string]string
}
Expand All @@ -62,6 +64,14 @@ private aws.vpc.routetable @defaults("id") {
routes []dict
}

// Amazon Virtual Private Cloud (VPC) Subnet
private aws.vpc.subnet @defaults("id") {
// Unique ID of the subnet
id string
// A list of CIDR descriptions
cidrs string
}

// Amazon Virtual Private Cloud (VPC) Flow Log
private aws.vpc.flowlog @defaults("id region status") {
// Unique ID of the flow log
Expand Down
107 changes: 107 additions & 0 deletions providers/aws/resources/aws.lr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions providers/aws/resources/aws.lr.manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,7 @@ resources:
region: {}
routeTables: {}
state: {}
subnets: {}
tags: {}
is_private: true
min_mondoo_version: latest
Expand Down Expand Up @@ -1450,3 +1451,12 @@ resources:
platform:
name:
- aws
aws.vpc.subnet:
fields:
cidrs: {}
id: {}
is_private: true
min_mondoo_version: latest
platform:
name:
- aws
36 changes: 36 additions & 0 deletions providers/aws/resources/aws_vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,42 @@ func (a *mqlAwsVpc) routeTables() ([]interface{}, error) {
return res, nil
}

func (a *mqlAwsVpc) subnets() ([]interface{}, error) {
conn := a.MqlRuntime.Connection.(*connection.AwsConnection)
vpcVal := a.Id.Data

svc := conn.Ec2(a.Region.Data)
ctx := context.Background()
res := []interface{}{}

nextToken := aws.String("no_token_to_start_with")
filterName := "vpc-id"
params := &ec2.DescribeSubnetsInput{Filters: []vpctypes.Filter{{Name: &filterName, Values: []string{vpcVal}}}}
for nextToken != nil {
subnets, err := svc.DescribeSubnets(ctx, params)
if err != nil {
return nil, err
}
nextToken = subnets.NextToken
if subnets.NextToken != nil {
params.NextToken = nextToken
}

for _, subnet := range subnets.Subnets {
subnetResource, err := CreateResource(a.MqlRuntime, "aws.vpc.subnet",
map[string]*llx.RawData{
"id": llx.StringData(convert.ToString(subnet.SubnetId)),
"cidrs": llx.StringData(*subnet.CidrBlock),
})
if err != nil {
return nil, err
}
res = append(res, subnetResource)
}
}
return res, nil
}

func initAwsVpc(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) {
if len(args) > 2 {
return args, nil, nil
Expand Down

0 comments on commit 39f3623

Please sign in to comment.