-
Notifications
You must be signed in to change notification settings - Fork 31
Description
I have seen an issue result of function instance_for_port() returning multiple instances while my understanding is that it is expected to return a single instance. So, I observed a condition that will return both nodes instead of one due to the filters being used below:
instance=`aws ec2 describe-instances $options --filters "Name=tag-value,Values=${port}" "Name=tag-key,Values=${ec2_tag}" --query 'Reservations[*].Instances[*].InstanceId'`
Imagine a two-node cluster, each with the following set of tags respectively:
node1:
tag-key=pacemaker / tag-value=node1
node2:
tag-key=pacemaker / tag-value=node2
tag-key=whatever / tag-value=node1
I believe the intent with the filter above is to collect a single instance ID that meets the condition ${ec2_tag} = ${port}. However, this is not what is happening in this case because it's returning all instances that has a tag-key ${ec2_tag} regardless of its value AND tag-value ${port} regardless of its tag-key. Hence, the scenario above will return both EC2 instances.
This is mentioned in the AWS CLI documentation for describe-instances [1] operation.
[1] https://awscli.amazonaws.com/v2/documentation/api/2.9.6/reference/ec2/describe-instances.html
tag-key- The key of a tag assigned to the resource. Use this filter to find all resources that have a tag with a specific key, regardless of the tag value.
Example 6: To filter for instances with the specified my-team tag value
The followingdescribe-instancesexample uses tag filters to scope the results to instances that have a tag with the specified tag value (my-team), regardless of the tag key.
I'm logging this issue suggesting the following filter if the intent above is indeed the expected condition:
instance=`aws ec2 describe-instances $options --filters "Name=tag:${ec2_tag},Values=${port}" --query 'Reservations[*].Instances[*].InstanceId'`
Looking forward to seeing your comments.
Pull request: