AWSTemplateFormatVersion: '2010-09-09'
Description: Cross-account role for Prilog to read CloudWatch Logs

Parameters:
  ExternalId:
    Type: String
    Description: ExternalId provided by Prilog (e.g., prilog-onboarding-<orgId>)
  RoleName:
    Type: String
    Default: PrilogCloudWatchReader
    Description: Name for the IAM role

Resources:
  PrilogCloudWatchRole:
    Type: AWS::IAM::Role
    Properties:
      RoleName: !Ref RoleName
      AssumeRolePolicyDocument:
        Version: '2012-10-17'
        Statement:
          - Effect: Allow
            Principal:
              AWS: "arn:aws:iam::632473407750:root"
            Action: sts:AssumeRole
            Condition:
              StringEquals:
                sts:ExternalId: !Ref ExternalId
      ManagedPolicyArns:
        - arn:aws:iam::aws:policy/CloudWatchLogsReadOnlyAccess
      Policies:
        - PolicyName: PrilogCloudWatchList
          PolicyDocument:
            Version: '2012-10-17'
            Statement:
              - Effect: Allow
                Action:
                  - logs:DescribeLogGroups
                  - logs:DescribeLogStreams
                  - logs:FilterLogEvents
                Resource: "*"

Outputs:
  RoleArn:
    Value: !GetAtt PrilogCloudWatchRole.Arn
    Description: IAM role ARN to paste into Prilog
