Conditions:
  IsUsEast1: !Equals [!Ref 'AWS::Region', 'us-east-1']
  NotUsEast1: !Not [!Condition IsUsEast1]
Resources:
  RootRole:
    Type: 'AWS::IAM::Role'
    Properties:
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Effect: Allow
            Principal:
              Service:
                - ec2.amazonaws.com
            Action:
              - 'sts:AssumeRole'
      Path: /
      RoleName: root
      Policies:
        - PolicyName: root
          PolicyDocument:
            Version: "2012-10-17"
            Statement:
              - Effect: Allow
                Action: '*'
                Resource: '*'
  RootRole2:
    Type: 'AWS::IAM::Role'
    Properties:
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Effect: Allow
            Principal:
              Service:
                - ec2.amazonaws.com
            Action:
              - 'sts:AssumeRole'
      Path: /
      RoleName: root
      Policies:
        - PolicyName: root
          PolicyDocument:
            Version: "2012-10-17"
            Statement:
              - Effect: Allow
                Action: '*'
                Resource: '*'
  RootRole3:
    Type: 'AWS::IAM::Role'
    Condition: IsUsEast1
    Properties:
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Effect: Allow
            Principal:
              Service:
                - ec2.amazonaws.com
            Action:
              - 'sts:AssumeRole'
      Path: /
      RoleName: useast1
      Policies:
        - PolicyName: root
          PolicyDocument:
            Version: "2012-10-17"
            Statement:
              - Effect: Allow
                Action: '*'
                Resource: '*'
  RootRole4:
    Type: 'AWS::IAM::Role'
    Condition: NotUsEast1
    Properties:
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Effect: Allow
            Principal:
              Service:
                - ec2.amazonaws.com
            Action:
              - 'sts:AssumeRole'
      Path: /
      RoleName: useast1
      Policies:
        - PolicyName: root
          PolicyDocument:
            Version: "2012-10-17"
            Statement:
              - Effect: Allow
                Action: '*'
                Resource: '*'

  RootRole5:
    Type: 'AWS::IAM::Role'
    Properties:
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Effect: Allow
            Principal:
              Service:
                - ec2.amazonaws.com
            Action:
              - 'sts:AssumeRole'
      Path: /
      RoleName: !If [IsUsEast1, useast1, !Ref 'AWS::NoValue']
      Policies:
        - PolicyName: root
          PolicyDocument:
            Version: "2012-10-17"
            Statement:
              - Effect: Allow
                Action: '*'
                Resource: '*'
  RootRole6:
    Type: 'AWS::IAM::Role'
    Properties:
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Effect: Allow
            Principal:
              Service:
                - ec2.amazonaws.com
            Action:
              - 'sts:AssumeRole'
      Path: /
      RoleName: !If [IsUsEast1, !Ref 'AWS::NoValue', useast1]
      Policies:
        - PolicyName: root
          PolicyDocument:
            Version: "2012-10-17"
            Statement:
              - Effect: Allow
                Action: '*'
                Resource: '*'
  Bucket1:
    Type: 'AWS::S3::Bucket'
    Properties:
      Fn::If:
        - IsUsEast1
        - BucketName: us-east-1
        - !Ref 'AWS::NoValue'
  Bucket2:
    Type: 'AWS::S3::Bucket'
    Properties:
      BucketName:
        Fn::If:
        - IsUsEast1
        - us-east-1
        - !Ref 'AWS::NoValue'
  BadType:
    Type: !Ref AWS::Region
  Module1:
    Type: MyCompany::MODULE
    Properties:
      Attribute1: test
  Module2:
    Type: MyCompany::MODULE
    Properties:
      Attribute2: test
  Project1:
    Type: AWS::CodeBuild::Project
    Properties:
      Name: myProjectName
      ServiceRole: arn
      Artifacts:
        Type: no_artifacts
      Environment:
        Type: LINUX_CONTAINER
        ComputeType: BUILD_GENERAL1_SMALL
        Image: aws/codebuild/java:openjdk-8
        EnvironmentVariables:
        - Name: varName
          Type: varType
          Value: varValue
      Source:
        Location: codebuild-demo-test/0123ab9a371ebf0187b0fe5614fbb72c
        Type: S3
      TimeoutInMinutes: 10

  Project2:
    Type: AWS::CodeBuild::Project
    Properties:
      Name: myProjectName
      ServiceRole: arn
      Artifacts:
        Type: no_artifacts
      Environment:
        Type: LINUX_CONTAINER
        ComputeType: BUILD_GENERAL1_SMALL
        Image: aws/codebuild/java:openjdk-8
        EnvironmentVariables:
        - Name: varName
          Type: varType
          Value: varValue
      Source:
        Location: codebuild-demo-test/0123ab9a371ebf0187b0fe5614fbb72c
        Type: S3
      TimeoutInMinutes: 10
