Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add securityGroups, availabilityZones, and hostedZoneId to ELBs #3826

Merged
merged 2 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions providers/aws/resources/aws.lr
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,12 @@ private aws.elb.loadbalancer @defaults("arn name") {
vpcId string
// Date and time when the load balancer was created
createdTime time
// Availability zone where the load balancer runs
availabilityZones []string
// VPC security groups for the load balancer
securityGroups []aws.ec2.securitygroup
// The ID of the Amazon Route 53 hosted zone associated with the load balancer
hostedZoneId string
}

// AWS CodeBuild for building and testing code
Expand Down
36 changes: 36 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.

6 changes: 6 additions & 0 deletions providers/aws/resources/aws.lr.manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1567,12 +1567,18 @@ resources:
fields:
arn: {}
attributes: {}
availabilityZones:
min_mondoo_version: 9.0.0
createdTime:
min_mondoo_version: 9.0.0
dnsName: {}
hostedZoneId:
min_mondoo_version: 9.0.0
listenerDescriptions: {}
name: {}
scheme: {}
securityGroups:
min_mondoo_version: 9.0.0
vpcId:
min_mondoo_version: 9.0.0
is_private: true
Expand Down
34 changes: 28 additions & 6 deletions providers/aws/resources/aws_elb.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"go.mondoo.com/cnquery/v11/providers-sdk/v1/util/convert"
"go.mondoo.com/cnquery/v11/providers-sdk/v1/util/jobpool"
"go.mondoo.com/cnquery/v11/providers/aws/connection"
"go.mondoo.com/cnquery/v11/types"
)

func (a *mqlAwsElb) id() (string, error) {
Expand Down Expand Up @@ -146,14 +147,35 @@ func (a *mqlAwsElb) getLoadBalancers(conn *connection.AwsConnection) []*jobpool.
return nil, err
}
for _, lb := range lbs.LoadBalancers {
availabilityZones := []interface{}{}
for _, zone := range lb.AvailabilityZones {
availabilityZones = append(availabilityZones, convert.ToString(zone.ZoneName))
}

sgs := []interface{}{}
for i := range lb.SecurityGroups {
sg := lb.SecurityGroups[i]
mqlSg, err := NewResource(a.MqlRuntime, "aws.ec2.securitygroup",
map[string]*llx.RawData{
"arn": llx.StringData(fmt.Sprintf(securityGroupArnPattern, regionVal, conn.AccountId(), sg)),
})
if err != nil {
return nil, err
}
sgs = append(sgs, mqlSg)
}

mqlLb, err := CreateResource(a.MqlRuntime, "aws.elb.loadbalancer",
map[string]*llx.RawData{
"arn": llx.StringDataPtr(lb.LoadBalancerArn),
"dnsName": llx.StringDataPtr(lb.DNSName),
"name": llx.StringDataPtr(lb.LoadBalancerName),
"scheme": llx.StringData(string(lb.Scheme)),
"vpcId": llx.StringDataPtr(lb.VpcId),
"createdTime": llx.TimeDataPtr(lb.CreatedTime),
"arn": llx.StringDataPtr(lb.LoadBalancerArn),
"availabilityZones": llx.ArrayData(availabilityZones, types.String),
"createdTime": llx.TimeDataPtr(lb.CreatedTime),
"dnsName": llx.StringDataPtr(lb.DNSName),
"hostedZoneId": llx.StringDataPtr(lb.CanonicalHostedZoneId),
"name": llx.StringDataPtr(lb.LoadBalancerName),
"scheme": llx.StringData(string(lb.Scheme)),
"securityGroups": llx.ArrayData(sgs, types.Resource("aws.ec2.securitygroup")),
"vpcId": llx.StringDataPtr(lb.VpcId),
})
if err != nil {
return nil, err
Expand Down
Loading