Skip to content

Commit

Permalink
EC2 Instance Limit: Hotfix Filter out AWS Spot Instances (aquasecurit…
Browse files Browse the repository at this point in the history
…y#142)

* Use the actual ec2 instance count and ignore spot instances

* Use the actual ec2 instance count and ignore spot instances
  • Loading branch information
Mav55 authored and matthewdfuller committed Oct 16, 2018
1 parent 4f33e6e commit f1a6d13
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions plugins/ec2/instanceLimit.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,28 @@ module.exports = {
'Unable to query for instances: ' + helpers.addError(describeInstances), region);
return rcb();
}


var ec2Instances = 0;
var spotInstances = 0;

if (!describeInstances.data.length) {
helpers.addResult(results, 0, 'No instances found', region);
return rcb();
} else {
for (instances in describeInstances.data){
for (instance in describeInstances.data[instances].Instances){
if (describeInstances.data[instances].Instances[instance].SpotInstanceRequestId){
spotInstances+=1;
} else {
ec2Instances+=1;
}

}
}
}

var percentage = Math.ceil((describeInstances.data.length / limits['max-instances'])*100);
var returnMsg = 'Account contains ' + describeInstances.data.length + ' of ' + limits['max-instances'] + ' (' + percentage + '%) available instances';
var percentage = Math.ceil((ec2Instances / limits['max-instances'])*100);
var returnMsg = 'Account contains ' + ec2Instances + ' of ' + limits['max-instances'] + ' (' + percentage + '%) available instances';

if (percentage >= config.instance_limit_percentage_fail) {
helpers.addResult(results, 2, returnMsg, region, null, custom);
Expand Down

0 comments on commit f1a6d13

Please sign in to comment.