Skip to content

Commit

Permalink
🧹 re-enable ec2 & ssm instances api discovery (#2833)
Browse files Browse the repository at this point in the history
  • Loading branch information
vjeffrey authored Dec 14, 2023
1 parent f741e4d commit bc39c2a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
2 changes: 2 additions & 0 deletions providers/aws/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ var Config = plugin.Provider{
resources.DiscoveryAuto,

resources.DiscoveryInstances,
resources.DiscoveryEC2InstanceAPI,
resources.DiscoverySSMInstances,
resources.DiscoverySSMInstanceAPI,
resources.DiscoveryECR,
resources.DiscoveryECS,

Expand Down
55 changes: 53 additions & 2 deletions providers/aws/resources/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,59 @@ func discover(runtime *plugin.Runtime, awsAccount *mqlAwsAccount, target string,
}
// case DiscoveryECSContainersAPI:
// case DiscoveryECRImageAPI:
// case DiscoveryEC2InstanceAPI:
// case DiscoverySSMInstanceAPI:
case DiscoveryEC2InstanceAPI:
res, err := NewResource(runtime, "aws.ec2", map[string]*llx.RawData{})
if err != nil {
return nil, err
}

ec2 := res.(*mqlAwsEc2)

ins := ec2.GetInstances()
if ins == nil {
return assetList, nil
}

for i := range ins.Data {
instance := ins.Data[i].(*mqlAwsEc2Instance)
if !instanceMatchesFilters(instance, filters) {
continue
}
l := mapStringInterfaceToStringString(instance.Tags.Data)
assetList = append(assetList, MqlObjectToAsset(accountId,
mqlObject{
name: getInstanceName(instance.InstanceId.Data, l), labels: l,
awsObject: awsObject{
account: accountId, region: instance.Region.Data, arn: instance.Arn.Data,
id: instance.InstanceId.Data, service: "ec2", objectType: "instance",
},
}, conn))
}
case DiscoverySSMInstanceAPI:
res, err := NewResource(runtime, "aws.ssm", map[string]*llx.RawData{})
if err != nil {
return nil, err
}

ssm := res.(*mqlAwsSsm)

ins := ssm.GetInstances()
if ins == nil {
return assetList, nil
}

for i := range ins.Data {
instance := ins.Data[i].(*mqlAwsSsmInstance)
l := mapStringInterfaceToStringString(instance.Tags.Data)
assetList = append(assetList, MqlObjectToAsset(accountId,
mqlObject{
name: getInstanceName(instance.InstanceId.Data, l), labels: l,
awsObject: awsObject{
account: accountId, region: instance.Region.Data, arn: instance.Arn.Data,
id: instance.InstanceId.Data, service: "ssm", objectType: "instance",
},
}, conn))
}
case DiscoveryS3Buckets:
res, err := NewResource(runtime, "aws.s3", map[string]*llx.RawData{})
if err != nil {
Expand Down

0 comments on commit bc39c2a

Please sign in to comment.