in src/getTargetNode.ts [18:42]
await getASGsByTag(event.autoScalingGroupDiscoveryTagKey, "true")
).map(asg => asg.AutoScalingGroupName);
const eligibleInstances = (
// TODO it would be nice to not need the Tags on the instances as well, but currently used in the ElasticsearchAdminSsmPolicy IAM policy in cloudformation.yaml
await getInstancesByTag(event.autoScalingGroupDiscoveryTagKey, "true")
).filter(i => eligibleASGs.includes(i.autoScalingGroupName));
// We can manually run rotation against a particular instance if needed
if(event.targetInstanceId) {
const targetInstance = eligibleInstances.find(i => i.id === event.targetInstanceId);
if(!targetInstance){
throw Error(
`The specified 'targetInstanceId' doesn't belong to an ASG with the
'${event.autoScalingGroupDiscoveryTagKey}' Tag set to 'true',
or the instance itself doesn't have that tag set to true.`
);
}
const asgName = targetInstance.autoScalingGroupName;
const targetInstanceId = targetInstance.id;
const elasticsearchClient = new Elasticsearch(targetInstanceId);
const targetElasticSearchNode = await elasticsearchClient.getElasticsearchNode(targetInstance);
console.log(`Instance ${targetInstanceId} (ASG: ${asgName}) specified as input. Moving on...`);
return { asgName, targetElasticSearchNode, skipRotation: false };
}