in aws-cloudformation-stackset/src/main/java/software/amazon/cloudformation/stackset/util/InstancesAnalyzer.java [54:83]
private static Set<StackInstances> groupInstancesByTargets(
final Set<StackInstance> flatStackInstances, final boolean isSelfManaged) {
final Map<List<Object>, StackInstances> groupedStacksMap = new HashMap<>();
for (final StackInstance stackInstance : flatStackInstances) {
final String target = stackInstance.getDeploymentTarget();
final String region = stackInstance.getRegion();
final Set<Parameter> parameterSet = stackInstance.getParameters();
final List<Object> compositeKey = Arrays.asList(target, parameterSet);
if (groupedStacksMap.containsKey(compositeKey)) {
groupedStacksMap.get(compositeKey).getRegions().add(stackInstance.getRegion());
} else {
final DeploymentTargets targets = DeploymentTargets.builder().build();
if (isSelfManaged) {
targets.setAccounts(new HashSet<>(Arrays.asList(target)));
} else {
targets.setOrganizationalUnitIds(new HashSet<>(Arrays.asList(target)));
}
final StackInstances stackInstances = StackInstances.builder()
.regions(new HashSet<>(Arrays.asList(region)))
.deploymentTargets(targets)
.parameterOverrides(parameterSet)
.build();
groupedStacksMap.put(compositeKey, stackInstances);
}
}
return new HashSet<>(groupedStacksMap.values());
}