fix(organizations): resolve the resource policy ID in tag operations (#8111)

TagResource, UntagResource and ListTagsForResource answered
TargetNotFoundException for the organization's resource policy, because
resolveTagOwner matched account, root, OU and policy IDs only. The
model's TaggableResourceId pattern accepts rp- IDs, and AWS's own
CloudFormation handler for AWS::Organizations::ResourcePolicy tags the
policy and lists its tags through that ID.

resolveTagOwner now matches the organization's resource policy ID and
saves the organization, as the root branch does. Any other rp- ID still
answers TargetNotFoundException. The code comments that said a resource
policy is not a TagResource target are corrected, and the docs table
lists the resource policy among the tag targets.
This commit is contained in:
soreavis authored and GitHub committed 2026-11-12 10:44:30 -04:00
1 parent 3f1dcc9173
commit b28caac441
5 files changed
+51 -14

No files matched your search

@@ -1253,10 +1253,8 @@ public class OrganizationsService implements ScpProvider, RootAccessOrganization
organization.setResourcePolicyContent(content);
if (tags != null) {
// Put replaces rather than merges: a caller that supplies Tags is stating the full set,
// so a key it no longer lists is dropped. The resource policy is not addressable by
// TagResource/UntagResource the way accounts, OUs, roots and policies are, so this call
// is the only way CloudFormation can converge Tags on an update. Omitting Tags
// entirely (null) leaves the existing ones untouched.
// so a key it no longer lists is dropped. CloudFormation relies on this to converge
// Tags on an update. Omitting Tags entirely (null) leaves the existing ones untouched.
organization.getResourcePolicyTags().clear();
organization.getResourcePolicyTags().putAll(tags);
}
@@ -1806,6 +1804,10 @@ public class OrganizationsService implements ScpProvider, RootAccessOrganization
return new TagOwner(policy.getTags(),
() -> policies.putForAccount(master, resourceId, policy));
}
if (resourceId.equals(organization.getResourcePolicyId())) {
return new TagOwner(organization.getResourcePolicyTags(),
() -> organizations.putForAccount(master, organization.getId(), organization));
}
throw new AwsException("TargetNotFoundException",
"We can't find a resource with the ResourceId " + resourceId + ".", 400);
}