@@ -22,18 +22,21 @@ if [ -z "${instance_id}" ]; then
2222 exit $UNKNOWN
2323fi
2424
25- instance_launch_template=$( curl --max-time 3 --silent --fail \
26- -H " X-aws-ec2-metadata-token: $TOKEN " \
27- " http://169.254.169.254/latest/meta-data/tags/instance/aws:ec2launchtemplate:id" )
25+ instances=" $( aws autoscaling describe-auto-scaling-instances --instance-ids " ${instance_id} " 2> /dev/null) "
2826
29- instance_asg= $( curl --max-time 3 --silent --fail \
30- -H " X-aws-ec2-metadata-token: $TOKEN " \
31- " http://169.254.169.254/latest/meta-data/tags/instance/aws:autoscaling:groupName " )
27+ if [ -z " ${instances} " ] || ! echo " ${instances} " | jq empty 2> /dev/null ; then
28+ exit $UNKNOWN
29+ fi
3230
33- if [ -z " ${instance_asg } " ] || [ -z " ${instance_launch_template} " ]; then
31+ if [ " $( echo " ${instances } " | jq ' .AutoScalingInstances | length ' ) " -eq " 0 " ]; then
3432 exit $UNKNOWN
3533fi
3634
35+ instance=" $( echo " ${instances} " | jq ' .AutoScalingInstances[0]' ) "
36+ instance_launch_template_id=" $( echo " ${instance} " | jq -r .LaunchTemplate.LaunchTemplateId) "
37+ instance_launch_template_version=" $( echo " ${instance} " | jq -r .LaunchTemplate.Version) "
38+ instance_asg=" $( echo " ${instance} " | jq -r .AutoScalingGroupName) "
39+
3740# Get ASG's current launch template (still requires AWS API)
3841asgs=" $( aws autoscaling describe-auto-scaling-groups --auto-scaling-group-names " ${instance_asg} " 2> /dev/null) "
3942
@@ -45,9 +48,11 @@ if [ "$(echo "${asgs}" | jq '.AutoScalingGroups | length')" -eq "0" ]; then
4548 exit $UNKNOWN
4649fi
4750
48- asg_launch_template=" $( echo " ${asgs} " | jq -r ' .AutoScalingGroups[0].MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification.LaunchTemplateId' ) "
51+ asg=" $( echo " ${asgs} " | jq ' .AutoScalingGroups[0].MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification' ) "
52+ asg_launch_template_id=" $( echo " ${asg} " | jq -r ' .LaunchTemplateId' ) "
53+ asg_launch_template_version=" $( echo " ${asg} " | jq -r ' .Version' ) "
4954
50- if [ " ${instance_launch_template } " = " ${asg_launch_template } " ]; then
55+ if [ " ${instance_launch_template_id } " = " ${asg_launch_template_id} " ] && [ " ${instance_launch_template_version} " = " ${asg_launch_template_version }" ]; then
5156 exit $OK
5257else
5358 exit $NONOK
0 commit comments