ROSTemplateFormatVersion: '2015-09-01'
Description:
  zh-cn: 创建一个测试EMR集群，配置了主节点、核心节点数量与磁盘类型容量，采用VPC网络与指定安全组，支持SSD云盘与按需付费。
  en: Create a test EMR (Elastic Map Reduce) cluster configured with specified numbers
    of master and core nodes, disk types, and capacities, utilizing a VPC (Virtual
    Private Cloud) network and a designated security group, supporting SSD cloud disks
    and pay-as-you-go billing.
Parameters:
  ZoneId:
    Type: String
    AssociationProperty: ALIYUN::ECS::Instance::ZoneId
    Label:
      en: VSwitch Availability Zone
      zh-cn: 交换机可用区
    Description:
      zh-cn: </font><a href='https://help.aliyun.com/document_detail/188196.html' target='_blank'><b> 查看可用区信息</b><font color='blue'></a>。
      en: <a href='https://help.aliyun.com/document_detail/188196.html' target='_blank'><b><font color='blue'>View region and zone info</font></b></a>.
  VpcId:
    AssociationProperty: ALIYUN::ECS::VPC::VPCId
    Type: String
    Description:
      en: Please search the ID starting with (vpc-xxx) from console-Virtual Private Cloud
      zh-cn: 现有虚拟专有网络的实例ID
    Label:
      en: VPC ID
      zh-cn: 专有网络VPC实例ID
  VSwitchId:
    AssociationProperty: ALIYUN::ECS::VSwitch::VSwitchId
    AssociationPropertyMetadata:
      VpcId: ${VpcId}
      ZoneId: ${ZoneId}
    Type: String
    Description:
      en: Instance ID of existing business network switches, console-Virtual Private Cloud-VSwitches under query
      zh-cn: 现有业务网络交换机的实例ID
    Label:
      en: VSwitch ID
      zh-cn: 交换机实例ID
  ClusterCoreDiskCapacity:
    Default: 80
    Type: Number
  ClusterCoreNodeCount:
    Default: 2
    Type: Number
  ClusterCoreSysDiskCapacity:
    Default: 120
    Type: Number
  ClusterDiskType:
    Default: CLOUD_SSD
    Type: String
  ClusterEmrVer:
    Default: EMR-3.22.4
    Type: String
  ClusterInstanceType:
    Default: ecs.g5.xlarge
    Type: String
  ClusterMasterDiskCapacity:
    Default: 80
    Type: Number
  ClusterMasterSysDiskCapacity:
    Default: 120
    Type: Number
  ClusterPassword:
    NoEcho: true
    Type: String
  SecurityGroupName:
    Default: mytest
    Type: String
Resources:
  EmrCluster:
    Properties:
      ChargeType: PostPaid
      ClusterType: HADOOP
      EmrVer:
        Ref: ClusterEmrVer
      HostGroup:
      - AutoRenew: false
        ChargeType: PostPaid
        DiskCapacity:
          Ref: ClusterMasterDiskCapacity
        DiskCount: 1
        DiskType:
          Ref: ClusterDiskType
        HostGroupType: MASTER
        InstanceType:
          Ref: ClusterInstanceType
        NodeCount: 1
        Period: 1
        SysDiskCapacity:
          Ref: ClusterMasterSysDiskCapacity
        SysDiskType:
          Ref: ClusterDiskType
        VSwitchId:
          Ref: VSwitchId
      - AutoRenew: false
        ChargeType: PostPaid
        DiskCapacity:
          Ref: ClusterCoreDiskCapacity
        DiskCount: 4
        DiskType:
          Ref: ClusterDiskType
        HostGroupType: CORE
        InstanceType:
          Ref: ClusterInstanceType
        NodeCount:
          Ref: ClusterCoreNodeCount
        Period: 1
        SysDiskCapacity:
          Ref: ClusterCoreSysDiskCapacity
        SysDiskType:
          Ref: ClusterDiskType
        VSwitchId:
          Ref: VSwitchId
      IoOptimized: true
      MasterPwd:
        Ref: ClusterPassword
      Name:
        Fn::Join:
        - '-'
        - - StackId
          - Ref: ALIYUN::StackId
      NetType: vpc
      SecurityGroupId:
        Ref: SecurityGroup
      UseLocalMetaDb: false
      VSwitchId:
        Ref: VSwitchId
      VpcId:
        Ref: VpcId
      ZoneId:
        Ref: ZoneId
    Type: ALIYUN::EMR::Cluster
  SecurityGroup:
    Properties:
      SecurityGroupName:
        Ref: SecurityGroupName
      VpcId:
        Ref: VpcId
    Type: ALIYUN::ECS::SecurityGroup
Outputs:
  ClusterId:
    Description: The ID of the cluster.
    Value:
      Fn::GetAtt:
      - EmrCluster
      - ClusterId