Iterate over accounts using Foreach
masterThe Foreach attribute allows you to create a resource for every account in a specific selection. The account being iterated over is accessible via the CurrentAccount pseudo-resource.
Note: Foreach supports the same expressiveness as OrganizationBinding but does not support the Region attribute.
Example: Creating a GuardDuty Member in the Master account for every account in the organization:
Resources:
Member:
Type: AWS::GuardDuty::Member
OrganizationBinding:
IncludeMasterAccount: true
Foreach:
Account: '*'
Properties:
DetectorId: !Ref Detector
Email: !GetAtt CurrentAccount.RootEmail
MemberId: !Ref CurrentAccount
Status: Invited
DisableEmailNotification: true