AWSTemplateFormatVersion: "2010-09-09"
Description: >
  Broken Labs - IAM Lab 03.
  An IAM role needs to read objects from an S3 bucket, but its requests are denied.
  Licensed under CC BY-NC-SA 4.0: https://creativecommons.org/licenses/by-nc-sa/4.0/
  Developed by: Mark Schoonover <mark.schoonover@gmail.com>

Resources:

  LabBucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: !Sub "brokenlabs-iam-lab-03-${AWS::Region}-${AWS::AccountId}"

  LabRole:
    Type: AWS::IAM::Role
    Properties:
      RoleName: !Sub "brokenlabs-iam-lab-03-role-${AWS::Region}-${AWS::AccountId}"
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Effect: Allow
            Principal:
              Service: ec2.amazonaws.com
            Action: sts:AssumeRole
      Policies:
        - PolicyName: LabRolePolicy
          PolicyDocument:
            Version: "2012-10-17"
            Statement:
              - Sid: AllowGetObject
                Effect: Allow
                Action: s3:GetObject
                Resource: !GetAtt LabBucket.Arn

Outputs:

  RoleName:
    Description: Name of the IAM role to test in the Policy Simulator
    Value: !Ref LabRole

  TestResourceArn:
    Description: Resource ARN to simulate s3:GetObject against
    Value: !Sub "${LabBucket.Arn}/example.txt"

  BucketName:
    Description: Name of the S3 bucket
    Value: !Ref LabBucket
