{
    "AWSTemplateFormatVersion": "2010-09-09",
    "Parameters": {
        "OwnerName": {
            "Type": "String"
        },
        "OwnerEmail": {
            "Type": "String"
        },
        "AZIdx": {
            "Type": "Number",
            "Default": 0,
            "MinValue": 0,
            "MaxValue": 2,
            "Description": "Resources from which AZ"
        }
    },
    "Mappings": {
        "ValueMap": {
            "us-west-2": {
                "AMI": "ami-0e730665a8d8eebb5",
                "key": "pe-class-key-oregon",
                "userdata": "#!/bin/bash\nmkdir ~ec2-user/stage/\ncd ~ec2-user/stage/\nrm -rf tidb-course-labs/\nrm -f /home/ec2-user/nohup*\nwget https://pingcap-edu.s3.us-west-2.amazonaws.com/mysql-connector-java-5.1.36.tar.gz\ntar -xzvf mysql-connector-java-5.1.36.tar.gz\ncp mysql-connector-java-5.1.36/mysql-connector-java-5.1.36-bin.jar ~ec2-user/\nchown ec2-user:ec2-user ~ec2-user/mysql-connector-java-5.1.36-bin.jar\nwget https://pingcap-edu.s3.us-west-2.amazonaws.com/tidb-admin-dataset-v2.zip\ngit clone https://github.com/pingcap-inc/tidb-course-labs.git\nREGION_CODE=`curl http://169.254.169.254/latest/meta-data/placement/region`\necho export REGION_CODE=${REGION_CODE} > ~ec2-user/cloud-env.sh\nalias cp='cp'\ncp -R tidb-course-labs/labs/dba_307/* ~ec2-user/\ncp -R tidb-course-labs/setup/tidb-lab-mysql-init-amz2/show-mysql-password.sh ~ec2-user/\ncd ~\nchown -R ec2-user:ec2-user ~ec2-user/*\nchmod +x ~ec2-user/*.sh\necho \"if [ -f /home/ec2-user/hosts-env.sh ]; then\" >> ~ec2-user/.bashrc\necho \"    source /home/ec2-user/hosts-env.sh\" >> ~ec2-user/.bashrc\necho \"fi;\" >> ~ec2-user/.bashrc\nchown ec2-user:ec2-user ~ec2-user/.bashrc\nservice mysqld start\nX=`grep 'temporary password' /var/log/mysqld.log | sed 's/.*: //'`\nmysql -h localhost -P 3306 -uroot -p$X --connect-expired-password << 'EOF'\nALTER USER root@'localhost' identified by 'q1w2e3R4_';\nEOF\nservice mysqld stop\n"
            },
            "ap-southeast-1": {
                "AMI": "ami-0dfb40636949bfea8",
                "key": "pe-class-key-singapore",
                "userdata": "#!/bin/bash\nmkdir ~ec2-user/stage/\ncd ~ec2-user/stage/\nrm -rf tidb-course-labs/\nrm -f /home/ec2-user/nohup*\nwget https://pingcap-edu-apac.s3.ap-southeast-1.amazonaws.com/mysql-connector-java-5.1.36.tar.gz\ntar -xzvf mysql-connector-java-5.1.36.tar.gz\ncp mysql-connector-java-5.1.36/mysql-connector-java-5.1.36-bin.jar ~ec2-user/\nchown ec2-user:ec2-user ~ec2-user/mysql-connector-java-5.1.36-bin.jar\nwget https://pingcap-edu-apac.s3.southeast-1.amazonaws.com/tidb-admin-dataset-v2.zip\ngit clone https://github.com/pingcap-inc/tidb-course-labs.git\nREGION_CODE=`curl http://169.254.169.254/latest/meta-data/placement/region`\necho export REGION_CODE=${REGION_CODE} > ~ec2-user/cloud-env.sh\nalias cp='cp'\ncp -R tidb-course-labs/labs/dba_307/* ~ec2-user/\ncp -R tidb-course-labs/setup/tidb-lab-mysql-init-amz2/show-mysql-password.sh ~ec2-user/\ncd ~\nchown -R ec2-user:ec2-user ~ec2-user/*\nchmod +x ~ec2-user/*.sh\necho \"if [ -f /home/ec2-user/hosts-env.sh ]; then\" >> ~ec2-user/.bashrc\necho \"    source /home/ec2-user/hosts-env.sh\" >> ~ec2-user/.bashrc\necho \"fi;\" >> ~ec2-user/.bashrc\nchown ec2-user:ec2-user ~ec2-user/.bashrc\nservice mysqld start\nX=`grep 'temporary password' /var/log/mysqld.log | sed 's/.*: //'`\nmysql -h localhost -P 3306 -uroot -p$X --connect-expired-password << 'EOF'\nALTER USER root@'localhost' identified by 'q1w2e3R4_';\nEOF\nservice mysqld stop\n"
            },
            "ap-northeast-1": {
                "AMI": "ami-04de4c1fd6ee71a79",
                "key": "pe-class-key-tokyo",
                "userdata": "#!/bin/bash\nmkdir ~ec2-user/stage/\ncd ~ec2-user/stage/\nrm -rf tidb-course-labs/\nrm -f /home/ec2-user/nohup*\nwget https://pingcap-edu-japan.s3.ap-northeast-1.amazonaws.com/mysql-connector-java-5.1.36.tar.gz\ntar -xzvf mysql-connector-java-5.1.36.tar.gz\ncp mysql-connector-java-5.1.36/mysql-connector-java-5.1.36-bin.jar ~ec2-user/\nchown ec2-user:ec2-user ~ec2-user/mysql-connector-java-5.1.36-bin.jar\nwget https://pingcap-edu-japan.s3.northeast-1.amazonaws.com/tidb-admin-dataset-v2.zip\ngit clone https://github.com/pingcap-inc/tidb-course-labs.git\nREGION_CODE=`curl http://169.254.169.254/latest/meta-data/placement/region`\necho export REGION_CODE=${REGION_CODE} > ~ec2-user/cloud-env.sh\nalias cp='cp'\ncp -R tidb-course-labs/labs/dba_307/* ~ec2-user/\ncp -R tidb-course-labs/setup/tidb-lab-mysql-init-amz2/show-mysql-password.sh ~ec2-user/\ncd ~\nchown -R ec2-user:ec2-user ~ec2-user/*\nchmod +x ~ec2-user/*.sh\necho \"if [ -f /home/ec2-user/hosts-env.sh ]; then\" >> ~ec2-user/.bashrc\necho \"    source /home/ec2-user/hosts-env.sh\" >> ~ec2-user/.bashrc\necho \"fi;\" >> ~ec2-user/.bashrc\nchown ec2-user:ec2-user ~ec2-user/.bashrc\nservice mysqld start\nX=`grep 'temporary password' /var/log/mysqld.log | sed 's/.*: //'`\nmysql -h localhost -P 3306 -uroot -p$X --connect-expired-password << 'EOF'\nALTER USER root@'localhost' identified by 'q1w2e3R4_';\nEOF\nservice mysqld stop\n"
            },
            "eu-central-1": {
                "AMI": "ami-01701ef283e1af183",
                "key": "pe-class-key-frankfurt",
                "userdata": "#!/bin/bash\nmkdir ~ec2-user/stage/\ncd ~ec2-user/stage/\nrm -rf tidb-course-labs/\nrm -f /home/ec2-user/nohup*\nwget https://pingcap-edu-frankfurt.s3.eu-central-1.amazonaws.com/mysql-connector-java-5.1.36.tar.gz\ntar -xzvf mysql-connector-java-5.1.36.tar.gz\ncp mysql-connector-java-5.1.36/mysql-connector-java-5.1.36-bin.jar ~ec2-user/\nchown ec2-user:ec2-user ~ec2-user/mysql-connector-java-5.1.36-bin.jar\nwget https://pingcap-edu-frankfrankt.s3.eu-central-1.amazonaws.com/tidb-admin-dataset-v2.zip\ngit clone https://github.com/pingcap-inc/tidb-course-labs.git\nREGION_CODE=`curl http://169.254.169.254/latest/meta-data/placement/region`\necho export REGION_CODE=${REGION_CODE} > ~ec2-user/cloud-env.sh\nalias cp='cp'\ncp -R tidb-course-labs/labs/dba_307/* ~ec2-user/\ncp -R tidb-course-labs/setup/tidb-lab-mysql-init-amz2/show-mysql-password.sh ~ec2-user/\ncd ~\nchown -R ec2-user:ec2-user ~ec2-user/*\nchmod +x ~ec2-user/*.sh\necho \"if [ -f /home/ec2-user/hosts-env.sh ]; then\" >> ~ec2-user/.bashrc\necho \"    source /home/ec2-user/hosts-env.sh\" >> ~ec2-user/.bashrc\necho \"fi;\" >> ~ec2-user/.bashrc\nchown ec2-user:ec2-user ~ec2-user/.bashrc\nservice mysqld start\nX=`grep 'temporary password' /var/log/mysqld.log | sed 's/.*: //'`\nmysql -h localhost -P 3306 -uroot -p$X --connect-expired-password << 'EOF'\nALTER USER root@'localhost' identified by 'q1w2e3R4_';\nEOF\nservice mysqld stop\n"
            }
        }
    },
    "Resources": {
        "DemoIGW": {
            "Type": "AWS::EC2::InternetGateway",
            "Properties": {
                "Tags": [
                    {
                        "Key": "Owner",
                        "Value": {
                            "Ref": "OwnerEmail"
                        }
                    }
                ]
            },
            "DependsOn": [
                "DemoVPC"
            ]
        },
        "DemoVPC": {
            "Type": "AWS::EC2::VPC",
            "Properties": {
                "CidrBlock": "10.90.0.0/16",
                "EnableDnsSupport": "true",
                "EnableDnsHostnames": "true",
                "Tags": [
                    {
                        "Key": "Owner",
                        "Value": {
                            "Ref": "OwnerEmail"
                        }
                    },
                    {
                        "Key": "Name",
                        "Value": {
                            "Ref": "OwnerName"
                        }
                    }
                ]
            }
        },
        "IGWA": {
            "Type": "AWS::EC2::VPCGatewayAttachment",
            "Properties": {
                "InternetGatewayId": {
                    "Ref": "DemoIGW"
                },
                "VpcId": {
                    "Ref": "DemoVPC"
                }
            }
        },
        "PublicRouteTable": {
            "Type": "AWS::EC2::RouteTable",
            "Properties": {
                "VpcId": {
                    "Ref": "DemoVPC"
                },
                "Tags": [
                    {
                        "Key": "Owner",
                        "Value": {
                            "Ref": "OwnerEmail"
                        }
                    },
                    {
                        "Key": "Name",
                        "Value": "PE Quick Demo Public Route"
                    }
                ]
            }
        },
        "PublicRoute": {
            "Type": "AWS::EC2::Route",
            "Properties": {
                "DestinationCidrBlock": "0.0.0.0/0",
                "GatewayId": {
                    "Ref": "DemoIGW"
                },
                "RouteTableId": {
                    "Ref": "PublicRouteTable"
                }
            },
            "DependsOn": [
                "IGWA"
            ]
        },
        "SN1": {
            "Type": "AWS::EC2::Subnet",
            "Properties": {
                "VpcId": {
                    "Ref": "DemoVPC"
                },
                "CidrBlock": "10.90.1.0/24",
                "AvailabilityZone": {
                    "Fn::Select": [
                        {
                            "Ref": "AZIdx"
                        },
                        {
                            "Fn::GetAZs": ""
                        }
                    ]
                },
                "PrivateDnsNameOptionsOnLaunch": {
                    "EnableResourceNameDnsAAAARecord": false,
                    "EnableResourceNameDnsARecord": true,
                    "HostnameType": "ip-name"
                },
                "Tags": [
                    {
                        "Key": "Owner",
                        "Value": {
                            "Ref": "OwnerEmail"
                        }
                    },
                    {
                        "Key": "Name",
                        "Value": {
                            "Fn::Join": [
                                "-",
                                [
                                    {
                                        "Ref": "OwnerName"
                                    },
                                    "subnet",
                                    "1"
                                ]
                            ]
                        }
                    }
                ]
            }
        },
        "SN2": {
            "Type": "AWS::EC2::Subnet",
            "Properties": {
                "VpcId": {
                    "Ref": "DemoVPC"
                },
                "CidrBlock": "10.90.2.0/24",
                "AvailabilityZone": {
                    "Fn::Select": [
                        {
                            "Ref": "AZIdx"
                        },
                        {
                            "Fn::GetAZs": ""
                        }
                    ]
                },
                "PrivateDnsNameOptionsOnLaunch": {
                    "EnableResourceNameDnsAAAARecord": false,
                    "EnableResourceNameDnsARecord": true,
                    "HostnameType": "ip-name"
                },
                "Tags": [
                    {
                        "Key": "Owner",
                        "Value": {
                            "Ref": "OwnerEmail"
                        }
                    },
                    {
                        "Key": "Name",
                        "Value": {
                            "Fn::Join": [
                                "-",
                                [
                                    {
                                        "Ref": "OwnerName"
                                    },
                                    "subnet",
                                    "2"
                                ]
                            ]
                        }
                    }
                ]
            }
        },
        "SN3": {
            "Type": "AWS::EC2::Subnet",
            "Properties": {
                "VpcId": {
                    "Ref": "DemoVPC"
                },
                "CidrBlock": "10.90.3.0/24",
                "AvailabilityZone": {
                    "Fn::Select": [
                        {
                            "Ref": "AZIdx"
                        },
                        {
                            "Fn::GetAZs": ""
                        }
                    ]
                },
                "PrivateDnsNameOptionsOnLaunch": {
                    "EnableResourceNameDnsAAAARecord": false,
                    "EnableResourceNameDnsARecord": true,
                    "HostnameType": "ip-name"
                },
                "Tags": [
                    {
                        "Key": "Owner",
                        "Value": {
                            "Ref": "OwnerEmail"
                        }
                    },
                    {
                        "Key": "Name",
                        "Value": {
                            "Fn::Join": [
                                "-",
                                [
                                    {
                                        "Ref": "OwnerName"
                                    },
                                    "subnet",
                                    "3"
                                ]
                            ]
                        }
                    }
                ]
            }
        },
        "SN4": {
            "Type": "AWS::EC2::Subnet",
            "Properties": {
                "VpcId": {
                    "Ref": "DemoVPC"
                },
                "CidrBlock": "10.90.4.0/24",
                "AvailabilityZone": {
                    "Fn::Select": [
                        {
                            "Ref": "AZIdx"
                        },
                        {
                            "Fn::GetAZs": ""
                        }
                    ]
                },
                "PrivateDnsNameOptionsOnLaunch": {
                    "EnableResourceNameDnsAAAARecord": false,
                    "EnableResourceNameDnsARecord": true,
                    "HostnameType": "ip-name"
                },
                "Tags": [
                    {
                        "Key": "Owner",
                        "Value": {
                            "Ref": "OwnerEmail"
                        }
                    },
                    {
                        "Key": "Name",
                        "Value": {
                            "Fn::Join": [
                                "-",
                                [
                                    {
                                        "Ref": "OwnerName"
                                    },
                                    "subnet",
                                    "4"
                                ]
                            ]
                        }
                    }
                ]
            }
        },
        "SRTA1": {
            "Type": "AWS::EC2::SubnetRouteTableAssociation",
            "Properties": {
                "SubnetId": {
                    "Ref": "SN1"
                },
                "RouteTableId": {
                    "Ref": "PublicRouteTable"
                }
            }
        },
        "SRTA2": {
            "Type": "AWS::EC2::SubnetRouteTableAssociation",
            "Properties": {
                "SubnetId": {
                    "Ref": "SN2"
                },
                "RouteTableId": {
                    "Ref": "PublicRouteTable"
                }
            }
        },
        "SRTA3": {
            "Type": "AWS::EC2::SubnetRouteTableAssociation",
            "Properties": {
                "SubnetId": {
                    "Ref": "SN3"
                },
                "RouteTableId": {
                    "Ref": "PublicRouteTable"
                }
            }
        },
        "SRTA4": {
            "Type": "AWS::EC2::SubnetRouteTableAssociation",
            "Properties": {
                "SubnetId": {
                    "Ref": "SN4"
                },
                "RouteTableId": {
                    "Ref": "PublicRouteTable"
                }
            }
        },
        "DemoSG": {
            "Type": "AWS::EC2::SecurityGroup",
            "Properties": {
                "GroupDescription": "Allow nodes communication.",
                "VpcId": {
                    "Ref": "DemoVPC"
                },
                "SecurityGroupIngress": [
                    {
                        "IpProtocol": "tcp",
                        "FromPort": 22,
                        "ToPort": 22,
                        "CidrIp": "0.0.0.0/0"
                    },
                    {
                        "IpProtocol": "tcp",
                        "FromPort": 2379,
                        "ToPort": 2379,
                        "CidrIp": "0.0.0.0/0"
                    },
                    {
                        "IpProtocol": "tcp",
                        "FromPort": 4000,
                        "ToPort": 4002,
                        "CidrIp": "0.0.0.0/0"
                    },
                    {
                        "IpProtocol": "tcp",
                        "FromPort": 3000,
                        "ToPort": 3000,
                        "CidrIp": "0.0.0.0/0"
                    },
                    {
                        "IpProtocol": "tcp",
                        "FromPort": 3306,
                        "ToPort": 3306,
                        "CidrIp": "0.0.0.0/0"
                    },
                    {
                        "IpProtocol": "icmp",
                        "FromPort": -1,
                        "ToPort": -1,
                        "CidrIp": "0.0.0.0/0"
                    }
                ],
                "SecurityGroupEgress": [
                    {
                        "IpProtocol": "-1",
                        "CidrIp": "0.0.0.0/0"
                    }
                ],
                "Tags": [
                    {
                        "Key": "Owner",
                        "Value": {
                            "Ref": "OwnerEmail"
                        }
                    },
                    {
                        "Key": "Name",
                        "Value": {
                            "Fn::Join": [
                                "-",
                                [
                                    {
                                        "Ref": "OwnerName"
                                    },
                                    "-sg"
                                ]
                            ]
                        }
                    }
                ]
            }
        },
        "IRule": {
            "Type": "AWS::EC2::SecurityGroupIngress",
            "Properties": {
                "IpProtocol": "-1",
                "SourceSecurityGroupId": {
                    "Fn::GetAtt": [
                        "DemoSG",
                        "GroupId"
                    ]
                },
                "GroupId": {
                    "Fn::GetAtt": [
                        "DemoSG",
                        "GroupId"
                    ]
                }
            }
        },
        "KVT": {
            "Type": "AWS::EC2::LaunchTemplate",
            "Properties": {
                "VersionDescription": "v1",
                "LaunchTemplateData": {
                    "Monitoring": {
                        "Enabled": false
                    },
                    "IamInstanceProfile": {
                        "Name": "course-303-node-role"
                    },
                    "BlockDeviceMappings": [
                        {
                            "DeviceName": "/dev/xvda",
                            "Ebs": {
                                "DeleteOnTermination": true,
                                "Encrypted": false,
                                "VolumeSize": 500,
                                "VolumeType": "gp2"
                            }
                        }
                    ],
                    "NetworkInterfaces": [
                        {
                            "DeviceIndex": 0,
                            "AssociatePublicIpAddress": true,
                            "Groups": [
                                {
                                    "Ref": "DemoSG"
                                }
                            ],
                            "DeleteOnTermination": true
                        }
                    ],
                    "ImageId": {
                        "Fn::FindInMap": [
                            "ValueMap",
                            {
                                "Ref": "AWS::Region"
                            },
                            "AMI"
                        ]
                    },
                    "InstanceType": "c5.large",
                    "KeyName": {
                        "Fn::FindInMap": [
                            "ValueMap",
                            {
                                "Ref": "AWS::Region"
                            },
                            "key"
                        ]
                    },
                    "TagSpecifications": [
                        {
                            "ResourceType": "instance",
                            "Tags": [
                                {
                                    "Key": "Owner",
                                    "Value": {
                                        "Ref": "OwnerEmail"
                                    }
                                },
                                {
                                    "Key": "Name",
                                    "Value": "kv"
                                }
                            ]
                        }
                    ],
                    "UserData": {
                        "Fn::Base64": {
                            "Fn::FindInMap": [
                                "ValueMap",
                                {
                                    "Ref": "AWS::Region"
                                },
                                "userdata"
                            ]
                        }
                    }
                }
            }
        },
        "PDT": {
            "Type": "AWS::EC2::LaunchTemplate",
            "Properties": {
                "VersionDescription": "v1",
                "LaunchTemplateData": {
                    "Monitoring": {
                        "Enabled": false
                    },
                    "IamInstanceProfile": {
                        "Name": "course-303-node-role"
                    },
                    "BlockDeviceMappings": [
                        {
                            "DeviceName": "/dev/xvda",
                            "Ebs": {
                                "DeleteOnTermination": true,
                                "Encrypted": false,
                                "VolumeSize": 60,
                                "VolumeType": "gp2"
                            }
                        }
                    ],
                    "NetworkInterfaces": [
                        {
                            "DeviceIndex": 0,
                            "AssociatePublicIpAddress": true,
                            "Groups": [
                                {
                                    "Ref": "DemoSG"
                                }
                            ],
                            "DeleteOnTermination": true
                        }
                    ],
                    "ImageId": {
                        "Fn::FindInMap": [
                            "ValueMap",
                            {
                                "Ref": "AWS::Region"
                            },
                            "AMI"
                        ]
                    },
                    "InstanceType": "c5.large",
                    "KeyName": {
                        "Fn::FindInMap": [
                            "ValueMap",
                            {
                                "Ref": "AWS::Region"
                            },
                            "key"
                        ]
                    },
                    "TagSpecifications": [
                        {
                            "ResourceType": "instance",
                            "Tags": [
                                {
                                    "Key": "Owner",
                                    "Value": {
                                        "Ref": "OwnerEmail"
                                    }
                                },
                                {
                                    "Key": "Name",
                                    "Value": "pd"
                                }
                            ]
                        }
                    ],
                    "UserData": {
                        "Fn::Base64": {
                            "Fn::FindInMap": [
                                "ValueMap",
                                {
                                    "Ref": "AWS::Region"
                                },
                                "userdata"
                            ]
                        }
                    }
                }
            }
        },
        "DBT": {
            "Type": "AWS::EC2::LaunchTemplate",
            "Properties": {
                "VersionDescription": "v1",
                "LaunchTemplateData": {
                    "Monitoring": {
                        "Enabled": false
                    },
                    "IamInstanceProfile": {
                        "Name": "course-303-node-role"
                    },
                    "BlockDeviceMappings": [
                        {
                            "DeviceName": "/dev/xvda",
                            "Ebs": {
                                "DeleteOnTermination": true,
                                "Encrypted": false,
                                "VolumeSize": 60,
                                "VolumeType": "gp2"
                            }
                        }
                    ],
                    "NetworkInterfaces": [
                        {
                            "DeviceIndex": 0,
                            "AssociatePublicIpAddress": true,
                            "Groups": [
                                {
                                    "Ref": "DemoSG"
                                }
                            ],
                            "DeleteOnTermination": true
                        }
                    ],
                    "ImageId": {
                        "Fn::FindInMap": [
                            "ValueMap",
                            {
                                "Ref": "AWS::Region"
                            },
                            "AMI"
                        ]
                    },
                    "InstanceType": "c5.large",
                    "KeyName": {
                        "Fn::FindInMap": [
                            "ValueMap",
                            {
                                "Ref": "AWS::Region"
                            },
                            "key"
                        ]
                    },
                    "TagSpecifications": [
                        {
                            "ResourceType": "instance",
                            "Tags": [
                                {
                                    "Key": "Owner",
                                    "Value": {
                                        "Ref": "OwnerEmail"
                                    }
                                },
                                {
                                    "Key": "Name",
                                    "Value": "db"
                                }
                            ]
                        }
                    ],
                    "UserData": {
                        "Fn::Base64": {
                            "Fn::FindInMap": [
                                "ValueMap",
                                {
                                    "Ref": "AWS::Region"
                                },
                                "userdata"
                            ]
                        }
                    }
                }
            }
        },
        "TFLT": {
            "Type": "AWS::EC2::LaunchTemplate",
            "Properties": {
                "VersionDescription": "v1",
                "LaunchTemplateData": {
                    "IamInstanceProfile": {
                        "Name": "course-303-node-role"
                    },
                    "BlockDeviceMappings": [
                        {
                            "DeviceName": "/dev/xvda",
                            "Ebs": {
                                "DeleteOnTermination": true,
                                "Encrypted": false,
                                "VolumeSize": 100,
                                "VolumeType": "gp2"
                            }
                        }
                    ],
                    "NetworkInterfaces": [
                        {
                            "DeviceIndex": 0,
                            "AssociatePublicIpAddress": true,
                            "Groups": [
                                {
                                    "Ref": "DemoSG"
                                }
                            ],
                            "DeleteOnTermination": true
                        }
                    ],
                    "ImageId": {
                        "Fn::FindInMap": [
                            "ValueMap",
                            {
                                "Ref": "AWS::Region"
                            },
                            "AMI"
                        ]
                    },
                    "InstanceType": "c5.large",
                    "KeyName": {
                        "Fn::FindInMap": [
                            "ValueMap",
                            {
                                "Ref": "AWS::Region"
                            },
                            "key"
                        ]
                    },
                    "TagSpecifications": [
                        {
                            "ResourceType": "instance",
                            "Tags": [
                                {
                                    "Key": "Owner",
                                    "Value": {
                                        "Ref": "OwnerEmail"
                                    }
                                },
                                {
                                    "Key": "Name",
                                    "Value": "tiflash"
                                }
                            ]
                        }
                    ],
                    "UserData": {
                        "Fn::Base64": {
                            "Fn::FindInMap": [
                                "ValueMap",
                                {
                                    "Ref": "AWS::Region"
                                },
                                "userdata"
                            ]
                        }
                    }
                }
            }
        },
        "MLT": {
            "Type": "AWS::EC2::LaunchTemplate",
            "Properties": {
                "VersionDescription": "v1",
                "LaunchTemplateData": {
                    "IamInstanceProfile": {
                        "Name": "course-303-node-role"
                    },
                    "BlockDeviceMappings": [
                        {
                            "DeviceName": "/dev/xvda",
                            "Ebs": {
                                "DeleteOnTermination": true,
                                "Encrypted": false,
                                "VolumeSize": 100,
                                "VolumeType": "gp2"
                            }
                        }
                    ],
                    "NetworkInterfaces": [
                        {
                            "DeviceIndex": 0,
                            "AssociatePublicIpAddress": true,
                            "Groups": [
                                {
                                    "Ref": "DemoSG"
                                }
                            ],
                            "DeleteOnTermination": true
                        }
                    ],
                    "ImageId": {
                        "Fn::FindInMap": [
                            "ValueMap",
                            {
                                "Ref": "AWS::Region"
                            },
                            "AMI"
                        ]
                    },
                    "InstanceType": "c5.large",
                    "KeyName": {
                        "Fn::FindInMap": [
                            "ValueMap",
                            {
                                "Ref": "AWS::Region"
                            },
                            "key"
                        ]
                    },
                    "TagSpecifications": [
                        {
                            "ResourceType": "instance",
                            "Tags": [
                                {
                                    "Key": "Owner",
                                    "Value": {
                                        "Ref": "OwnerEmail"
                                    }
                                },
                                {
                                    "Key": "Name",
                                    "Value": "monitor"
                                }
                            ]
                        }
                    ],
                    "UserData": {
                        "Fn::Base64": {
                            "Fn::Join": [
                                "\n",
                                [
                                    {
                                        "Fn::FindInMap": [
                                            "ValueMap",
                                            {
                                                "Ref": "AWS::Region"
                                            },
                                            "userdata"
                                        ]
                                    },
                                    {
                                        "Fn::Sub": "/usr/bin/cfn-signal -e 0 --stack ${AWS::StackName} --resource MG --region ${AWS::Region} > ~ec2-user/USER_DATA_DONE 2>&1\n"
                                    }
                                ]
                            ]
                        }
                    }
                }
            }
        },
        "KVG": {
            "Type": "AWS::AutoScaling::AutoScalingGroup",
            "Properties": {
                "LaunchTemplate": {
                    "LaunchTemplateId": {
                        "Ref": "KVT"
                    },
                    "Version": {
                        "Fn::GetAtt": [
                            "KVT",
                            "LatestVersionNumber"
                        ]
                    }
                },
                "MaxSize": "3",
                "MinSize": "3",
                "DesiredCapacity": "3",
                "VPCZoneIdentifier": [
                    {
                        "Ref": "SN1"
                    },
                    {
                        "Ref": "SN2"
                    },
                    {
                        "Ref": "SN3"
                    }
                ],
                "Tags": [
                    {
                        "Key": "Owner",
                        "Value": {
                            "Ref": "OwnerEmail"
                        },
                        "PropagateAtLaunch": "true"
                    },
                    {
                        "Key": "trainer",
                        "Value": {
                            "Ref": "OwnerName"
                        },
                        "PropagateAtLaunch": "true"
                    }
                ]
            },
            "DependsOn": [
                "IGWA"
            ]
        },
        "PDG": {
            "Type": "AWS::AutoScaling::AutoScalingGroup",
            "Properties": {
                "LaunchTemplate": {
                    "LaunchTemplateId": {
                        "Ref": "PDT"
                    },
                    "Version": {
                        "Fn::GetAtt": [
                            "PDT",
                            "LatestVersionNumber"
                        ]
                    }
                },
                "MaxSize": "1",
                "MinSize": "1",
                "DesiredCapacity": "1",
                "VPCZoneIdentifier": [
                    {
                        "Ref": "SN1"
                    },
                    {
                        "Ref": "SN2"
                    },
                    {
                        "Ref": "SN3"
                    }
                ],
                "Tags": [
                    {
                        "Key": "Owner",
                        "Value": {
                            "Ref": "OwnerEmail"
                        },
                        "PropagateAtLaunch": "true"
                    },
                    {
                        "Key": "trainer",
                        "Value": {
                            "Ref": "OwnerName"
                        },
                        "PropagateAtLaunch": "true"
                    }
                ]
            },
            "DependsOn": [
                "IGWA"
            ]
        },
        "DBG": {
            "Type": "AWS::AutoScaling::AutoScalingGroup",
            "Properties": {
                "LaunchTemplate": {
                    "LaunchTemplateId": {
                        "Ref": "DBT"
                    },
                    "Version": {
                        "Fn::GetAtt": [
                            "DBT",
                            "LatestVersionNumber"
                        ]
                    }
                },
                "MaxSize": "2",
                "MinSize": "2",
                "DesiredCapacity": "2",
                "VPCZoneIdentifier": [
                    {
                        "Ref": "SN1"
                    },
                    {
                        "Ref": "SN2"
                    }
                ],
                "Tags": [
                    {
                        "Key": "Owner",
                        "Value": {
                            "Ref": "OwnerEmail"
                        },
                        "PropagateAtLaunch": "true"
                    },
                    {
                        "Key": "trainer",
                        "Value": {
                            "Ref": "OwnerName"
                        },
                        "PropagateAtLaunch": "true"
                    }
                ]
            },
            "DependsOn": [
                "IGWA"
            ]
        },
        "TFG": {
            "Type": "AWS::AutoScaling::AutoScalingGroup",
            "Properties": {
                "LaunchTemplate": {
                    "LaunchTemplateId": {
                        "Ref": "TFLT"
                    },
                    "Version": {
                        "Fn::GetAtt": [
                            "TFLT",
                            "LatestVersionNumber"
                        ]
                    }
                },
                "MaxSize": "0",
                "MinSize": "0",
                "DesiredCapacity": "0",
                "VPCZoneIdentifier": [
                    {
                        "Ref": "SN4"
                    }
                ],
                "Tags": [
                    {
                        "Key": "Owner",
                        "Value": {
                            "Ref": "OwnerEmail"
                        },
                        "PropagateAtLaunch": "true"
                    },
                    {
                        "Key": "trainer",
                        "Value": {
                            "Ref": "OwnerName"
                        },
                        "PropagateAtLaunch": "true"
                    }
                ]
            },
            "DependsOn": [
                "IGWA"
            ]
        },
        "MG": {
            "Type": "AWS::AutoScaling::AutoScalingGroup",
            "Properties": {
                "LaunchTemplate": {
                    "LaunchTemplateId": {
                        "Ref": "MLT"
                    },
                    "Version": {
                        "Fn::GetAtt": [
                            "MLT",
                            "LatestVersionNumber"
                        ]
                    }
                },
                "MaxSize": "1",
                "MinSize": "1",
                "DesiredCapacity": "1",
                "VPCZoneIdentifier": [
                    {
                        "Ref": "SN4"
                    }
                ],
                "Tags": [
                    {
                        "Key": "Owner",
                        "Value": {
                            "Ref": "OwnerEmail"
                        },
                        "PropagateAtLaunch": "true"
                    },
                    {
                        "Key": "trainer",
                        "Value": {
                            "Ref": "OwnerName"
                        },
                        "PropagateAtLaunch": "true"
                    }
                ]
            },
            "DependsOn": [
                "IGWA"
            ],
            "CreationPolicy": {
                "ResourceSignal": {
                    "Timeout": "PT10M",
                    "Count": 1
                }
            }
        }
    }
}