fix(organizations): start a new root with no policy types enabled (#4756)

CreateOrganization (and EnableAllFeatures) seeded the root with
SERVICE_CONTROL_POLICY already ENABLED, so the first EnablePolicyType a
caller issues was rejected with PolicyTypeAlreadyEnabledException. That
is exactly what Terraform's aws_organizations_organization does with
enabled_policy_types right after CreateOrganization, so the common
"create the org and turn on SCPs" configuration failed at its first
resource.

On AWS a new root has an empty PolicyTypes list: the provider's
acceptance test for a plain organization asserts roots.0.policy_types
is empty, and its enabled_policy_types test enables SCPs on a fresh
organization successfully.

DescribeOrganization's AvailablePolicyTypes used to read the root's
list, which is what the seed was standing in for. It is now reported
separately and, as AWS documents for the deprecated field, lists only
SERVICE_CONTROL_POLICY for an ALL organization.

Tests that relied on the seed now call EnablePolicyType first, as a
real caller must. The CloudFormation test creates the stack without its
SCP, enables the type, then adds the SCP by UpdateStack, because no
CloudFormation resource enables a policy type.
This commit is contained in:
Allen Sanborn authored and GitHub committed 2026-09-30 18:12:38 -04:00
1 parent b5c428319f
commit 18128b432a
9 files changed
+92 -18

No files matched your search

@@ -630,8 +630,12 @@ public class OrganizationsJsonHandler {
node.put("MasterAccountArn", organization.getMasterAccountArn());
node.put("MasterAccountId", organization.getMasterAccountId());
node.put("MasterAccountEmail", organization.getMasterAccountEmail());
// Deprecated in AWS and distinct from the root's enabled types (ListRoots): it reports SCPs as
// available for an all-features organization and never includes any other policy type.
ArrayNode policyTypes = node.putArray("AvailablePolicyTypes");
organization.getRoot().getPolicyTypes().forEach(summary -> policyTypes.add(policyTypeNode(summary)));
if ("ALL".equals(organization.getFeatureSet())) {
policyTypes.add(policyTypeNode(new PolicyTypeSummary("SERVICE_CONTROL_POLICY", "ENABLED")));
}
return node;
}
@@ -274,9 +274,9 @@ public class OrganizationsService implements ScpProvider {
root.setId(rootId);
root.setArn(arn(callerAccountId, "root/" + organizationId + "/" + rootId));
root.setName("Root");
if (FEATURE_SET_ALL.equals(resolvedFeatureSet)) {
root.getPolicyTypes().add(new PolicyTypeSummary(SERVICE_CONTROL_POLICY, "ENABLED"));
}
// A new root has no policy types enabled, whatever the feature set: callers enable SCPs with
// EnablePolicyType, and Terraform's enabled_policy_types does exactly that right after
// CreateOrganization, so a pre-enabled root fails it with PolicyTypeAlreadyEnabledException.
organization.setRoot(root);
organizations.putForAccount(callerAccountId, organizationId, organization);
@@ -1727,9 +1727,6 @@ public class OrganizationsService implements ScpProvider {
private void applyEnableAllFeatures(Organization organization) {
organization.setFeatureSet(FEATURE_SET_ALL);
if (findPolicyType(organization.getRoot(), SERVICE_CONTROL_POLICY).isEmpty()) {
organization.getRoot().getPolicyTypes().add(new PolicyTypeSummary(SERVICE_CONTROL_POLICY, "ENABLED"));
}
organizations.putForAccount(organization.getMasterAccountId(), organization.getId(), organization);
}