Skip to content

EC2 describe-instances filter within instance_for_port() function returning multiple instance IDs rather than one #43

@alyoamz

Description

@alyoamz

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 following describe-instances example 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:

master...alyoamz:cluster-glue:patch-1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions