From f1a6d1302502bcffe3090896ec5c8b12d607eeca Mon Sep 17 00:00:00 2001 From: Cariel C Date: Mon, 15 Oct 2018 18:06:21 -0700 Subject: [PATCH] EC2 Instance Limit: Hotfix Filter out AWS Spot Instances (#142) * Use the actual ec2 instance count and ignore spot instances * Use the actual ec2 instance count and ignore spot instances --- plugins/ec2/instanceLimit.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/plugins/ec2/instanceLimit.js b/plugins/ec2/instanceLimit.js index 17c3a9ad3f..82e4b42bcb 100644 --- a/plugins/ec2/instanceLimit.js +++ b/plugins/ec2/instanceLimit.js @@ -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);