{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Parameters": {
    "OwnerName": {
      "Type": "String"
    },
    "OwnerEmail": {
      "Type": "String"
    }
  },
  "Mappings": {
    "UserDataMap": {
      "ap-northeast-1": {
        "common": "#!/bin/bash\necho LANG=en_US.utf-8 >> /etc/environment\necho LC_ALL=en_US.utf-8 >> /etc/environment\nmkdir ~ec2-user/stage/\ncd ~ec2-user/stage/\nrm -rf tidb-course-201-lab/\nyum -y update\nyum -y install git numactl awscli\nyum -y install java-11-amazon-corretto\nrpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022\nwget https://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm\nyum -y install mysql57-community-release-el7-10.noarch.rpm\nyum -y install mysql-community-client\ngit clone https://github.com/pingcap/tidb-course-201-lab.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-201-lab/setup/tidb-quick-demo-aws-9-nodes-tiproxy-amz2/* ~ec2-user/\ncp tidb-course-201-lab/tidb-quick-demo/005-online-upgrade-by-real-cluster/setup/register_tiproxy_to_nlb.sh ~ec2-user/\ncp -R tidb-course-201-lab/setup/tidb-lab-mysql-init-amz2/show-mysql-password.sh ~ec2-user/\ncp -R tidb-course-201-lab/scripts/ ~ec2-user/\ncd ~\nchown -R ec2-user:ec2-user ~ec2-user/*\nchmod +x ~ec2-user/*.sh\nchmod +x ~ec2-user/scripts/*.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\nsu ec2-user -c \"pip3 install boto3\"\n",
        "tiproxy": "#!/bin/bash\ncd ~ec2-user\nyum -y update\nyum -y install git numactl awscli\ngit clone https://github.com/pingcap/TiProxy.git\ngit clone https://github.com/pingcap/tidb-course-201-lab.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-201-lab/setup/tidb-quick-demo-aws-9-nodes-tiproxy-amz2/* ~ec2-user/\ncp -R tidb-course-201-lab/scripts/ ~ec2-user/\nchown -R ec2-user:ec2-user ~ec2-user/*\ncd ~\nwget https://pingcap-edu-japan.s3.ap-northeast-1.amazonaws.com/go1.20.4.linux-amd64.tar.gz\nrm -rf /usr/local/go && tar -C /usr/local -xzf go1.20.4.linux-amd64.tar.gz\necho \"export PATH=$PATH:/usr/local/go/bin\" >> ~ec2-user/.bashrc\nsu - ec2-user -c \"pip3 install boto3\"\nsu - ec2-user -c \"cd TiProxy/; make;\"\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": "demo-vpc"
          }
        ]
      }
    },
    "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": "ap-northeast-1a",
        "PrivateDnsNameOptionsOnLaunch": {
          "EnableResourceNameDnsAAAARecord": false,
          "EnableResourceNameDnsARecord": true,
          "HostnameType": "ip-name"
        },
        "Tags": [
          {
            "Key": "owner",
            "Value": {
              "Ref": "OwnerEmail"
            }
          },
          {
            "Key": "Name",
            "Value": "demo-subnet-1"
          }
        ]
      }
    },
    "SN2": {
      "Type": "AWS::EC2::Subnet",
      "Properties": {
        "VpcId": {
          "Ref": "DemoVPC"
        },
        "CidrBlock": "10.90.2.0/24",
        "AvailabilityZone": "ap-northeast-1c",
        "PrivateDnsNameOptionsOnLaunch": {
          "EnableResourceNameDnsAAAARecord": false,
          "EnableResourceNameDnsARecord": true,
          "HostnameType": "ip-name"
        },
        "Tags": [
          {
            "Key": "owner",
            "Value": {
              "Ref": "OwnerEmail"
            }
          },
          {
            "Key": "Name",
            "Value": "demo-subnet-2"
          }
        ]
      }
    },
    "SN3": {
      "Type": "AWS::EC2::Subnet",
      "Properties": {
        "VpcId": {
          "Ref": "DemoVPC"
        },
        "CidrBlock": "10.90.3.0/24",
        "AvailabilityZone": "ap-northeast-1d",
        "PrivateDnsNameOptionsOnLaunch": {
          "EnableResourceNameDnsAAAARecord": false,
          "EnableResourceNameDnsARecord": true,
          "HostnameType": "ip-name"
        },
        "Tags": [
          {
            "Key": "owner",
            "Value": {
              "Ref": "OwnerEmail"
            }
          },
          {
            "Key": "Name",
            "Value": "demo-subnet-3"
          }
        ]
      }
    },
    "SN4": {
      "Type": "AWS::EC2::Subnet",
      "Properties": {
        "VpcId": {
          "Ref": "DemoVPC"
        },
        "CidrBlock": "10.90.4.0/24",
        "AvailabilityZone": "ap-northeast-1d",
        "PrivateDnsNameOptionsOnLaunch": {
          "EnableResourceNameDnsAAAARecord": false,
          "EnableResourceNameDnsARecord": true,
          "HostnameType": "ip-name"
        },
        "Tags": [
          {
            "Key": "owner",
            "Value": {
              "Ref": "OwnerEmail"
            }
          },
          {
            "Key": "Name",
            "Value": "demo-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": 6000,
            "ToPort": 6000,
            "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": "quick-demo-sg"
          }
        ]
      }
    },
    "IRule": {
      "Type": "AWS::EC2::SecurityGroupIngress",
      "Properties": {
        "IpProtocol": "-1",
        "SourceSecurityGroupId": {
          "Fn::GetAtt": [
            "DemoSG",
            "GroupId"
          ]
        },
        "GroupId": {
          "Fn::GetAtt": [
            "DemoSG",
            "GroupId"
          ]
        }
      }
    },
    "TG": {
      "Type": "AWS::ElasticLoadBalancingV2::TargetGroup",
      "Properties": {
        "HealthCheckEnabled": "True",
        "HealthCheckIntervalSeconds": 5,
        "HealthCheckPort": "6000",
        "HealthCheckProtocol": "TCP",
        "HealthCheckTimeoutSeconds": 5,
        "HealthyThresholdCount": 2,
        "Name": "demo-target-group",
        "Port": 6000,
        "Protocol": "TCP",
        "TargetType": "ip",
        "VpcId": {
          "Ref": "DemoVPC"
        }
      }
    },
    "NLB": {
      "Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
      "Properties": {
        "Type": "network",
        "Name": "demo-nlb",
        "Scheme": "internal",
        "Subnets": [
          {
            "Ref": "SN1"
          },
          {
            "Ref": "SN2"
          },
          {
            "Ref": "SN3"
          }
        ]
      }
    },
    "LSNR": {
      "Type": "AWS::ElasticLoadBalancingV2::Listener",
      "Properties": {
        "DefaultActions": [
          {
            "Type": "forward",
            "ForwardConfig": {
              "TargetGroups": [
                {
                  "TargetGroupArn": {
                    "Ref": "TG"
                  }
                }
              ]
            }
          }
        ],
        "LoadBalancerArn": {
          "Ref": "NLB"
        },
        "Port": 6000,
        "Protocol": "TCP"
      }
    },
    "KVT": {
      "Type": "AWS::EC2::LaunchTemplate",
      "Properties": {
        "VersionDescription": "v1",
        "LaunchTemplateName": {
          "Fn::Sub": "${AWS::StackName}-quick-demo-tikv-lt"
        },
        "LaunchTemplateData": {
          "Monitoring": {
            "Enabled": false
          },
          "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": "ami-072bfb8ae2c884cc4",
          "InstanceType": "c5.large",
          "KeyName": "pe-class-key-tokyo",
          "TagSpecifications": [
            {
              "ResourceType": "instance",
              "Tags": [
                {
                  "Key": "owner",
                  "Value": {
                    "Ref": "OwnerEmail"
                  }
                },
                {
                  "Key": "Name",
                  "Value": "kv"
                },
                {
                  "Key": "environment",
                  "Value": "education"
                },
                {
                  "Key": "servicetype",
                  "Value": "education"
                },
                {
                  "Key": "usedby",
                  "Value": "education"
                },
                {
                  "Key": "component",
                  "Value": "education"
                },
                {
                  "Key": "tenant",
                  "Value": {
                    "Ref": "OwnerEmail"
                  }
                },
                {
                  "Key": "project",
                  "Value": {
                    "Ref": "OwnerEmail"
                  }
                },
                {
                  "Key": "cluster",
                  "Value": {
                    "Ref": "OwnerEmail"
                  }
                }
              ]
            }
          ],
          "UserData": {
            "Fn::Base64": {
              "Fn::FindInMap": [
                "UserDataMap",
                {
                  "Ref": "AWS::Region"
                },
                "common"
              ]
            }
          }
        }
      }
    },
    "PDT": {
      "Type": "AWS::EC2::LaunchTemplate",
      "Properties": {
        "VersionDescription": "v1",
        "LaunchTemplateName": {
          "Fn::Sub": "${AWS::StackName}-quick-demo-pd-lt"
        },
        "LaunchTemplateData": {
          "Monitoring": {
            "Enabled": true
          },
          "IamInstanceProfile": {
            "Name": "course-303-node-role"
          },
          "BlockDeviceMappings": [
            {
              "DeviceName": "/dev/xvda",
              "Ebs": {
                "DeleteOnTermination": true,
                "Encrypted": false,
                "VolumeSize": 30,
                "VolumeType": "gp2"
              }
            }
          ],
          "NetworkInterfaces": [
            {
              "DeviceIndex": 0,
              "AssociatePublicIpAddress": true,
              "Groups": [
                {
                  "Ref": "DemoSG"
                }
              ],
              "DeleteOnTermination": true
            }
          ],
          "ImageId": "ami-072bfb8ae2c884cc4",
          "InstanceType": "c5.large",
          "KeyName": "pe-class-key-tokyo",
          "TagSpecifications": [
            {
              "ResourceType": "instance",
              "Tags": [
                {
                  "Key": "owner",
                  "Value": {
                    "Ref": "OwnerEmail"
                  }
                },
                {
                  "Key": "Name",
                  "Value": "pd"
                },
                {
                  "Key": "environment",
                  "Value": "education"
                },
                {
                  "Key": "servicetype",
                  "Value": "education"
                },
                {
                  "Key": "usedby",
                  "Value": "education"
                },
                {
                  "Key": "component",
                  "Value": "education"
                },
                {
                  "Key": "tenant",
                  "Value": {
                    "Ref": "OwnerEmail"
                  }
                },
                {
                  "Key": "project",
                  "Value": {
                    "Ref": "OwnerEmail"
                  }
                },
                {
                  "Key": "cluster",
                  "Value": {
                    "Ref": "OwnerEmail"
                  }
                }
              ]
            }
          ],
          "UserData": {
            "Fn::Base64": {
              "Fn::FindInMap": [
                "UserDataMap",
                {
                  "Ref": "AWS::Region"
                },
                "common"
              ]
            }
          }
        }
      }
    },
    "DBT": {
      "Type": "AWS::EC2::LaunchTemplate",
      "Properties": {
        "VersionDescription": "v1",
        "LaunchTemplateName": {
          "Fn::Sub": "${AWS::StackName}-quick-demo-tidb-lt"
        },
        "LaunchTemplateData": {
          "Monitoring": {
            "Enabled": true
          },
          "IamInstanceProfile": {
            "Name": "course-303-node-role"
          },
          "BlockDeviceMappings": [
            {
              "DeviceName": "/dev/xvda",
              "Ebs": {
                "DeleteOnTermination": true,
                "Encrypted": false,
                "VolumeSize": 30,
                "VolumeType": "gp2"
              }
            }
          ],
          "NetworkInterfaces": [
            {
              "DeviceIndex": 0,
              "AssociatePublicIpAddress": true,
              "Groups": [
                {
                  "Ref": "DemoSG"
                }
              ],
              "DeleteOnTermination": true
            }
          ],
          "ImageId": "ami-072bfb8ae2c884cc4",
          "InstanceType": "c5.large",
          "KeyName": "pe-class-key-tokyo",
          "TagSpecifications": [
            {
              "ResourceType": "instance",
              "Tags": [
                {
                  "Key": "owner",
                  "Value": {
                    "Ref": "OwnerEmail"
                  }
                },
                {
                  "Key": "Name",
                  "Value": "db"
                },
                {
                  "Key": "environment",
                  "Value": "education"
                },
                {
                  "Key": "servicetype",
                  "Value": "education"
                },
                {
                  "Key": "usedby",
                  "Value": "education"
                },
                {
                  "Key": "component",
                  "Value": "education"
                },
                {
                  "Key": "tenant",
                  "Value": {
                    "Ref": "OwnerEmail"
                  }
                },
                {
                  "Key": "project",
                  "Value": {
                    "Ref": "OwnerEmail"
                  }
                },
                {
                  "Key": "cluster",
                  "Value": {
                    "Ref": "OwnerEmail"
                  }
                }
              ]
            }
          ],
          "UserData": {
            "Fn::Base64": {
              "Fn::FindInMap": [
                "UserDataMap",
                {
                  "Ref": "AWS::Region"
                },
                "common"
              ]
            }
          }
        }
      }
    },
    "MLT": {
      "Type": "AWS::EC2::LaunchTemplate",
      "Properties": {
        "VersionDescription": "v1",
        "LaunchTemplateName": {
          "Fn::Sub": "${AWS::StackName}-quick-demo-monitor-lt"
        },
        "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": "ami-072bfb8ae2c884cc4",
          "InstanceType": "c5.large",
          "KeyName": "pe-class-key-tokyo",
          "TagSpecifications": [
            {
              "ResourceType": "instance",
              "Tags": [
                {
                  "Key": "owner",
                  "Value": {
                    "Ref": "OwnerEmail"
                  }
                },
                {
                  "Key": "Name",
                  "Value": "monitor"
                },
                {
                  "Key": "environment",
                  "Value": "education"
                },
                {
                  "Key": "servicetype",
                  "Value": "education"
                },
                {
                  "Key": "usedby",
                  "Value": "education"
                },
                {
                  "Key": "component",
                  "Value": "education"
                },
                {
                  "Key": "tenant",
                  "Value": {
                    "Ref": "OwnerEmail"
                  }
                },
                {
                  "Key": "project",
                  "Value": {
                    "Ref": "OwnerEmail"
                  }
                },
                {
                  "Key": "cluster",
                  "Value": {
                    "Ref": "OwnerEmail"
                  }
                }
              ]
            }
          ],
          "UserData": {
            "Fn::Base64": {
              "Fn::FindInMap": [
                "UserDataMap",
                {
                  "Ref": "AWS::Region"
                },
                "common"
              ]
            }
          }
        }
      }
    },
    "TPLT": {
      "Type": "AWS::EC2::LaunchTemplate",
      "Properties": {
        "VersionDescription": "v1",
        "LaunchTemplateName": {
          "Fn::Sub": "${AWS::StackName}-quick-demo-proxy-lt"
        },
        "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": "ami-072bfb8ae2c884cc4",
          "InstanceType": "c5.large",
          "KeyName": "pe-class-key-tokyo",
          "TagSpecifications": [
            {
              "ResourceType": "instance",
              "Tags": [
                {
                  "Key": "owner",
                  "Value": {
                    "Ref": "OwnerEmail"
                  }
                },
                {
                  "Key": "Name",
                  "Value": "tiproxy"
                },
                {
                  "Key": "environment",
                  "Value": "education"
                },
                {
                  "Key": "servicetype",
                  "Value": "education"
                },
                {
                  "Key": "usedby",
                  "Value": "education"
                },
                {
                  "Key": "component",
                  "Value": "education"
                },
                {
                  "Key": "tenant",
                  "Value": {
                    "Ref": "OwnerEmail"
                  }
                },
                {
                  "Key": "project",
                  "Value": {
                    "Ref": "OwnerEmail"
                  }
                },
                {
                  "Key": "cluster",
                  "Value": {
                    "Ref": "OwnerEmail"
                  }
                }
              ]
            }
          ],
          "UserData": {
            "Fn::Base64": {
              "Fn::FindInMap": [
                "UserDataMap",
                {
                  "Ref": "AWS::Region"
                },
                "tiproxy"
              ]
            }
          }
        }
      }
    },
    "KVG": {
      "Type": "AWS::AutoScaling::AutoScalingGroup",
      "Properties": {
        "AutoScalingGroupName": "TiKV",
        "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": {
        "AutoScalingGroupName": "PD",
        "LaunchTemplate": {
          "LaunchTemplateId": {
            "Ref": "PDT"
          },
          "Version": {
            "Fn::GetAtt": [
              "PDT",
              "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"
      ]
    },
    "DBG": {
      "Type": "AWS::AutoScaling::AutoScalingGroup",
      "Properties": {
        "AutoScalingGroupName": "TiDB",
        "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"
      ]
    },
    "MG": {
      "Type": "AWS::AutoScaling::AutoScalingGroup",
      "Properties": {
        "AutoScalingGroupName": "Monitor",
        "LaunchTemplate": {
          "LaunchTemplateId": {
            "Ref": "MLT"
          },
          "Version": {
            "Fn::GetAtt": [
              "DBT",
              "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"
      ]
    },
    "TPG": {
      "Type": "AWS::AutoScaling::AutoScalingGroup",
      "Properties": {
        "AutoScalingGroupName": "TiProxy",
        "LaunchTemplate": {
          "LaunchTemplateId": {
            "Ref": "TPLT"
          },
          "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"
      ]
    }
  }
}