Skip to content

Commit bbb0644

Browse files
committed
Support group id in addition to group names
Based on issue #43, we want to support both notations: * group name first * group id if it does not work with group name Closes #49.
1 parent 0e848c1 commit bbb0644

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ ec2 discovery allows to use the ec2 APIs to perform automatic discovery (similar
5757

5858
The following are a list of settings (prefixed with `discovery.ec2`) that can further control the discovery:
5959

60-
* `groups`: Either a comma separated list or array based list of (security) groups. Only instances with the provided security groups will be used in the cluster discovery. (NOTE: You should provide the group NAME, not the group ID.)
60+
* `groups`: Either a comma separated list or array based list of (security) groups. Only instances with the provided security groups will be used in the cluster discovery. (NOTE: You could provide either group NAME or group ID.)
6161
* `host_type`: The type of host type to use to communicate with other instances. Can be one of `private_ip`, `public_ip`, `private_dns`, `public_dns`. Defaults to `private_ip`.
6262
* `availability_zones`: Either a comma separated list or array based list of availability zones. Only instances within the provided availability zones will be used in the cluster discovery.
6363
* `any_group`: If set to `false`, will require all security groups to be present for the instance to be used for the discovery. Defaults to `true`.

src/main/java/org/elasticsearch/discovery/ec2/AwsEc2UnicastHostsProvider.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,22 @@ public List<DiscoveryNode> buildDynamicNodes() {
118118
if (!groups.isEmpty()) {
119119
List<GroupIdentifier> instanceSecurityGroups = instance.getSecurityGroups();
120120
ArrayList<String> securityGroupNames = new ArrayList<String>();
121+
ArrayList<String> securityGroupIds = new ArrayList<String>();
121122
for (GroupIdentifier sg : instanceSecurityGroups) {
122123
securityGroupNames.add(sg.getGroupName());
124+
securityGroupIds.add(sg.getGroupId());
123125
}
124126
if (bindAnyGroup) {
125-
if (Collections.disjoint(securityGroupNames, groups)) {
127+
// We check if we can find at least one group name or one group id in groups.
128+
if (Collections.disjoint(securityGroupNames, groups)
129+
&& Collections.disjoint(securityGroupIds, groups)) {
126130
logger.trace("filtering out instance {} based on groups {}, not part of {}", instance.getInstanceId(), instanceSecurityGroups, groups);
127131
// continue to the next instance
128132
continue;
129133
}
130134
} else {
131-
if (!securityGroupNames.containsAll(groups)) {
135+
// We need tp match all group names or group ids, otherwise we ignore this instance
136+
if (!(securityGroupNames.containsAll(groups) || securityGroupIds.containsAll(groups))) {
132137
logger.trace("filtering out instance {} based on groups {}, does not include all of {}", instance.getInstanceId(), instanceSecurityGroups, groups);
133138
// continue to the next instance
134139
continue;

0 commit comments

Comments
 (0)