AWSTemplateFormatVersion: '2010-09-09'
Description: O11y iam role for dataplane

Parameters:
  Region:
    Type: String
  LogicalRegionName:
    Type: String
  O11yControlPlaneRoleArns:
    Type: CommaDelimitedList

Resources:
  DataplaneForO11yRoleDev:
    Type: AWS::IAM::Role
    Properties:
      RoleName: !Sub "dev-${LogicalRegionName}-dp4o11yrs"
      Policies:
        - PolicyName: !Sub "dev-${Region}-dp4o11yrs-policy"
          PolicyDocument:
            Version: "2012-10-17"
            Statement:
              - Effect: Allow
                Resource: "*"
                Action:
                  - "route53:*"
                  - "elasticloadbalancing:*"
                  - "iam:*"
                  - "ec2:*"
                  - "tag:*"
      AssumeRolePolicyDocument:
        Version: '2012-10-17'
        Statement:
          - Effect: Allow
            Principal:
              AWS: !Ref O11yControlPlaneRoleArns
            Action:
              - sts:AssumeRole
  DataplaneForO11yRoleStaging:
    Type: AWS::IAM::Role
    Properties:
      RoleName: !Sub "staging-${LogicalRegionName}-dp4o11yrs"
      Policies:
        - PolicyName: !Sub "staging-${Region}-dp4o11yrs-policy"
          PolicyDocument:
            Version: "2012-10-17"
            Statement:
              - Effect: Allow
                Resource: "*"
                Action:
                  - "route53:*"
                  - "elasticloadbalancing:*"
                  - "iam:*"
                  - "ec2:*"
                  - "tag:*"
      AssumeRolePolicyDocument:
        Version: '2012-10-17'
        Statement:
          - Effect: Allow
            Principal:
              AWS: !Ref O11yControlPlaneRoleArns
            Action:
              - sts:AssumeRole
  DataplaneForO11yRoleProd:
    Type: AWS::IAM::Role
    Properties:
      RoleName: !Sub "prod-${LogicalRegionName}-dp4o11yrs"
      Policies:
        - PolicyName: !Sub "prod-${Region}-dp4o11yrs-policy"
          PolicyDocument:
            Version: "2012-10-17"
            Statement:
              - Effect: Allow
                Resource: "*"
                Action:
                  - "route53:*"
                  - "elasticloadbalancing:*"
                  - "iam:*"
                  - "ec2:*"
                  - "tag:*"
      AssumeRolePolicyDocument:
        Version: '2012-10-17'
        Statement:
          - Effect: Allow
            Principal:
              AWS: !Ref O11yControlPlaneRoleArns
            Action:
              - sts:AssumeRole
