in aws-cloudformation-stackset/src/main/java/software/amazon/cloudformation/stackset/util/InstancesAnalyzer.java [140:176]
private static Set<StackInstance> flattenStackInstancesGroup(
final Collection<StackInstances> stackInstancesGroup, final boolean isSelfManaged) {
final Set<StackInstance> flatStacks = new HashSet<>();
if (CollectionUtils.isNullOrEmpty(stackInstancesGroup)) return flatStacks;
for (final StackInstances stackInstances : stackInstancesGroup) {
for (final String region : stackInstances.getRegions()) {
final Set<String> targets = isSelfManaged ? stackInstances.getDeploymentTargets().getAccounts()
: stackInstances.getDeploymentTargets().getOrganizationalUnitIds();
// Validates expected DeploymentTargets exist in the template
if (CollectionUtils.isNullOrEmpty(targets)) {
throw new CfnInvalidRequestException(
String.format("%s should be specified in DeploymentTargets in [%s] model",
isSelfManaged ? "Accounts" : "OrganizationalUnitIds",
isSelfManaged ? "SELF_MANAGED" : "SERVICE_MANAGED"));
}
for (final String target : targets) {
final StackInstance stackInstance = StackInstance.builder()
.region(region).deploymentTarget(target).parameters(stackInstances.getParameterOverrides())
.build();
// Validates no duplicated stack instance is specified
if (flatStacks.contains(stackInstance)) {
throw new CfnInvalidRequestException(
String.format("Stack instance [%s,%s] is duplicated", target, region));
}
flatStacks.add(stackInstance);
}
}
}
return flatStacks;
}