Summary
Use AWS CloudFormation StackSets to deploy a reusable IAM Role for testing across multiple AWS accounts and regions. This is useful for validating cross-account access, centralised permission distribution, and IAM auditing strategies.
This hands-on project will demonstrate:
- Creating and deploying StackSets for IAM resources
- Using AWS Organisations and delegated admin
- Safely testing IAM role propagation in real accounts
- Managing StackSet updates and drift detection
Goals
- Define a CloudFormation template that creates a test IAM role
- Deploy it across multiple accounts and regions via StackSets
- Use service-managed permissions with AWS Organisations
- Validate role creation, trust policies, and permissions
- Monitor status, detect drift, and apply future updates
Phase 1: Prepare IAM Role Template
Tasks
Resources:
TestIAMRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub "StackSetTestRole-${AWS::Region}"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
AWS: "arn:aws:iam::123456789012:root" # update with trusted account ID
Action: sts:AssumeRole
Policies:
- PolicyName: InlinePermissions
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- s3:ListAllMyBuckets
- ec2:DescribeInstances
Resource: "*"
Outputs:
RoleArn:
Value: !GetAtt TestIAMRole.Arn
Phase 2: Define StackSet
Tasks
Phase 3: Target Configuration
Tasks
Phase 4: Post-deployment Testing
Tasks
Phase 5: Maintenance and Drift
Tasks
Notes
- Avoid hardcoding ARNs; use parameters or
!Sub
- Use tags for auditability and cost tracking
- Set log retention for CloudTrail to monitor role usage post-deployment
- Store templates under
templates/iam/ for organisation
Optional Enhancements
Audit Automation
Resources
Summary
Use AWS CloudFormation StackSets to deploy a reusable IAM Role for testing across multiple AWS accounts and regions. This is useful for validating cross-account access, centralised permission distribution, and IAM auditing strategies.
This hands-on project will demonstrate:
Goals
Phase 1: Prepare IAM Role Template
Tasks
iam-test-role.yaml)TestCrossAccountRole)Phase 2: Define StackSet
Tasks
AWS::CloudFormation::StackSetwith:PermissionModel: SERVICE_MANAGEDCapabilities: [ CAPABILITY_NAMED_IAM ]Phase 3: Target Configuration
Tasks
Root,Dev,Sandbox)ap-southeast-2,us-west-2)101aws cloudformation create-stack-instancesPhase 4: Post-deployment Testing
Tasks
sts:assume-role)aws sts assume-role --role-arn ...to verifyPhase 5: Maintenance and Drift
Tasks
aws cloudformation detect-stack-set-driftNotes
!Subtemplates/iam/for organisationOptional Enhancements
Audit Automation
Resources