templates/clickhouse-arm-entrypoint-new-vpc.template.yaml [812:1172]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  Nlb2NodesStack:
    Condition: 2NodesCondition
    Type: AWS::CloudFormation::Stack
    Properties: 
      TemplateURL:
        Fn::Sub: 
          - https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${QSS3KeyPrefix}templates/nlb.template.yaml
          - S3Region: !If 
              - UsingDefaultBucket
              - !Ref 'AWS::Region'
              - !Ref QSS3BucketRegion
            S3Bucket: !If 
              - UsingDefaultBucket
              - !Sub '${QSS3BucketName}-${AWS::Region}'
              - !Ref QSS3BucketName
      Parameters: 
        VPCID: !GetAtt VPCStack.Outputs.VPCID
        Subnets: !Join
          - ','
          - [ !GetAtt VPCStack.Outputs.PrivateSubnet1AID ]
        NodeCount: !Ref ClickHouseNodeCount
        Port: !Ref Port
        EC2Instance1: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID1
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID1
  Nlb4NodesStack:
    Condition: 4NodesCondition
    Type: AWS::CloudFormation::Stack
    Properties: 
      TemplateURL:
        Fn::Sub: 
          - https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${QSS3KeyPrefix}templates/nlb.template.yaml
          - S3Region: !If 
              - UsingDefaultBucket
              - !Ref 'AWS::Region'
              - !Ref QSS3BucketRegion
            S3Bucket: !If 
              - UsingDefaultBucket
              - !Sub '${QSS3BucketName}-${AWS::Region}'
              - !Ref QSS3BucketName
      Parameters: 
        VPCID: !GetAtt VPCStack.Outputs.VPCID
        Subnets: !Join
          - ','
          - [ !GetAtt VPCStack.Outputs.PrivateSubnet1AID ]
        NodeCount: !Ref ClickHouseNodeCount
        Port: !Ref Port
        EC2Instance1: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID1
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID1
        EC2Instance2: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID3
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID3
  Nlb6NodesStack:
    Condition: 6NodesCondition
    Type: AWS::CloudFormation::Stack
    Properties: 
      TemplateURL:
        Fn::Sub: 
          - https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${QSS3KeyPrefix}templates/nlb.template.yaml
          - S3Region: !If 
              - UsingDefaultBucket
              - !Ref 'AWS::Region'
              - !Ref QSS3BucketRegion
            S3Bucket: !If 
              - UsingDefaultBucket
              - !Sub '${QSS3BucketName}-${AWS::Region}'
              - !Ref QSS3BucketName
      Parameters: 
        VPCID: !GetAtt VPCStack.Outputs.VPCID
        Subnets: !Join
          - ','
          - [ !GetAtt VPCStack.Outputs.PrivateSubnet1AID ]
        NodeCount: !Ref ClickHouseNodeCount
        Port: !Ref Port
        EC2Instance1: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID1
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID1
        EC2Instance2: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID3
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID3
        EC2Instance3: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID5
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID5
  Nlb8NodesStack:
    Condition: 8NodesCondition
    Type: AWS::CloudFormation::Stack
    Properties: 
      TemplateURL:
        Fn::Sub: 
          - https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${QSS3KeyPrefix}templates/nlb.template.yaml
          - S3Region: !If 
              - UsingDefaultBucket
              - !Ref 'AWS::Region'
              - !Ref QSS3BucketRegion
            S3Bucket: !If 
              - UsingDefaultBucket
              - !Sub '${QSS3BucketName}-${AWS::Region}'
              - !Ref QSS3BucketName
      Parameters: 
        VPCID: !GetAtt VPCStack.Outputs.VPCID
        Subnets: !Join
          - ','
          - [ !GetAtt VPCStack.Outputs.PrivateSubnet1AID ]
        NodeCount: !Ref ClickHouseNodeCount
        Port: !Ref Port
        EC2Instance1: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID1
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID1
        EC2Instance2: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID3
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID3
        EC2Instance3: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID5
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID5
        EC2Instance4: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID7
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID7
  CloudWatchDashboard2Nodes:
    Condition: 2NodesCondition
    Type: AWS::CloudFormation::Stack
    Properties: 
      TemplateURL:
        Fn::Sub: 
          - https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${QSS3KeyPrefix}templates/cloudwatch-dashboard.template.yaml
          - S3Region: !If 
              - UsingDefaultBucket
              - !Ref 'AWS::Region'
              - !Ref QSS3BucketRegion
            S3Bucket: !If 
              - UsingDefaultBucket
              - !Sub '${QSS3BucketName}-${AWS::Region}'
              - !Ref QSS3BucketName
      Parameters: 
        DashboardName: !Sub 'ClickHouse-Cluster-Dashboard-${AWS::Region}'
        ClickHouseNodeCount: !Ref ClickHouseNodeCount
        ClickHouseInstanceID1: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID1
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID1
        ClickHouseInstanceID2: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID2
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID2
        ClickHouseImageId: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ImageId
          - !GetAtt ClickHouseClusterArmStack.Outputs.ImageId
        ClickHouseInstanceType: !Ref ClickHouseInstanceType
        ZookeeperInstanceID1: !GetAtt ZookeeperClusterStack.Outputs.ZookeeperInstanceID1
        ZookeeperInstanceID2: !GetAtt ZookeeperClusterStack.Outputs.ZookeeperInstanceID2
        ZookeeperInstanceID3: !GetAtt ZookeeperClusterStack.Outputs.ZookeeperInstanceID3
        ZookeeperImageId: !GetAtt ZookeeperClusterStack.Outputs.ImageId
        ZookeeperInstanceType: !Ref ZookeeperInstanceType
        AlarmEmail: !Ref AlarmEmail
  CloudWatchDashboard4Nodes:
    Condition: 4NodesCondition
    Type: AWS::CloudFormation::Stack
    Properties: 
      TemplateURL:
        Fn::Sub: 
          - https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${QSS3KeyPrefix}templates/cloudwatch-dashboard.template.yaml
          - S3Region: !If 
              - UsingDefaultBucket
              - !Ref 'AWS::Region'
              - !Ref QSS3BucketRegion
            S3Bucket: !If 
              - UsingDefaultBucket
              - !Sub '${QSS3BucketName}-${AWS::Region}'
              - !Ref QSS3BucketName
      Parameters: 
        DashboardName: !Sub 'ClickHouse-Cluster-Dashboard-${AWS::Region}'
        ClickHouseNodeCount: !Ref ClickHouseNodeCount
        ClickHouseInstanceID1: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID1
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID1
        ClickHouseInstanceID2: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID2
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID2
        ClickHouseInstanceID3: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID3
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID3
        ClickHouseInstanceID4: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID4
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID4
        ClickHouseImageId: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ImageId
          - !GetAtt ClickHouseClusterArmStack.Outputs.ImageId
        ClickHouseInstanceType: !Ref ClickHouseInstanceType
        ZookeeperInstanceID1: !GetAtt ZookeeperClusterStack.Outputs.ZookeeperInstanceID1
        ZookeeperInstanceID2: !GetAtt ZookeeperClusterStack.Outputs.ZookeeperInstanceID2
        ZookeeperInstanceID3: !GetAtt ZookeeperClusterStack.Outputs.ZookeeperInstanceID3
        ZookeeperImageId: !GetAtt ZookeeperClusterStack.Outputs.ImageId
        ZookeeperInstanceType: !Ref ZookeeperInstanceType
        AlarmEmail: !Ref AlarmEmail
  CloudWatchDashboard6Nodes:
    Condition: 6NodesCondition
    Type: AWS::CloudFormation::Stack
    Properties: 
      TemplateURL:
        Fn::Sub: 
          - https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${QSS3KeyPrefix}templates/cloudwatch-dashboard.template.yaml
          - S3Region: !If 
              - UsingDefaultBucket
              - !Ref 'AWS::Region'
              - !Ref QSS3BucketRegion
            S3Bucket: !If 
              - UsingDefaultBucket
              - !Sub '${QSS3BucketName}-${AWS::Region}'
              - !Ref QSS3BucketName
      Parameters: 
        DashboardName: !Sub 'ClickHouse-Cluster-Dashboard-${AWS::Region}'
        ClickHouseNodeCount: !Ref ClickHouseNodeCount
        ClickHouseInstanceID1: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID1
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID1
        ClickHouseInstanceID2: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID2
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID2
        ClickHouseInstanceID3: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID3
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID3
        ClickHouseInstanceID4: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID4
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID4
        ClickHouseInstanceID5: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID5
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID5
        ClickHouseInstanceID6: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID6
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID6
        ClickHouseImageId: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ImageId
          - !GetAtt ClickHouseClusterArmStack.Outputs.ImageId
        ClickHouseInstanceType: !Ref ClickHouseInstanceType
        ZookeeperInstanceID1: !GetAtt ZookeeperClusterStack.Outputs.ZookeeperInstanceID1
        ZookeeperInstanceID2: !GetAtt ZookeeperClusterStack.Outputs.ZookeeperInstanceID2
        ZookeeperInstanceID3: !GetAtt ZookeeperClusterStack.Outputs.ZookeeperInstanceID3
        ZookeeperImageId: !GetAtt ZookeeperClusterStack.Outputs.ImageId
        ZookeeperInstanceType: !Ref ZookeeperInstanceType
        AlarmEmail: !Ref AlarmEmail
  CloudWatchDashboard8Nodes:
    Condition: 8NodesCondition
    Type: AWS::CloudFormation::Stack
    Properties: 
      TemplateURL:
        Fn::Sub: 
          - https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${QSS3KeyPrefix}templates/cloudwatch-dashboard.template.yaml
          - S3Region: !If 
              - UsingDefaultBucket
              - !Ref 'AWS::Region'
              - !Ref QSS3BucketRegion
            S3Bucket: !If 
              - UsingDefaultBucket
              - !Sub '${QSS3BucketName}-${AWS::Region}'
              - !Ref QSS3BucketName
      Parameters: 
        DashboardName: !Sub 'ClickHouse-Cluster-Dashboard-${AWS::Region}'
        ClickHouseNodeCount: !Ref ClickHouseNodeCount
        ClickHouseInstanceID1: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID1
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID1
        ClickHouseInstanceID2: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID2
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID2
        ClickHouseInstanceID3: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID3
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID3
        ClickHouseInstanceID4: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID4
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID4
        ClickHouseInstanceID5: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID5
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID5
        ClickHouseInstanceID6: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID6
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID6
        ClickHouseInstanceID7: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID7
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID7
        ClickHouseInstanceID8: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID8
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID8
        ClickHouseImageId: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ImageId
          - !GetAtt ClickHouseClusterArmStack.Outputs.ImageId
        ClickHouseInstanceType: !Ref ClickHouseInstanceType
        ZookeeperInstanceID1: !GetAtt ZookeeperClusterStack.Outputs.ZookeeperInstanceID1
        ZookeeperInstanceID2: !GetAtt ZookeeperClusterStack.Outputs.ZookeeperInstanceID2
        ZookeeperInstanceID3: !GetAtt ZookeeperClusterStack.Outputs.ZookeeperInstanceID3
        ZookeeperImageId: !GetAtt ZookeeperClusterStack.Outputs.ImageId
        ZookeeperInstanceType: !Ref ZookeeperInstanceType
        AlarmEmail: !Ref AlarmEmail
Outputs:
  VPCCIDR:
    Description: The VPCCIDR for DW vpc
    Value: !GetAtt VPCStack.Outputs.VPCCIDR
  S3VPCEndpoint:
    Description: The S3VPCEndpoint for ClickHouse nodes
    Value: !GetAtt VPCStack.Outputs.S3VPCEndpoint
  CloudWatchLogs:
    Description: CloudWatch Logs GroupName. Your SSH logs will be stored here.
    Value: !GetAtt BastionStack.Outputs.CloudWatchLogs
  BastionEIP1:
    Description: Elastic IP 1 for Bastion
    Value: !GetAtt BastionStack.Outputs.EIP1
  NetworkLoadBalancer2Nodes:
    Condition: 2NodesCondition
    Description: Network Load Balancer with port 8123 in private subnet 1
    Value: !GetAtt Nlb2NodesStack.Outputs.ElbDNSName
  NetworkLoadBalancer4Nodes:
    Condition: 4NodesCondition
    Description: Network Load Balancer with port 8123 in private subnet 1
    Value: !GetAtt Nlb4NodesStack.Outputs.ElbDNSName
  NetworkLoadBalancer6Nodes:
    Condition: 6NodesCondition
    Description: Network Load Balancer with port 8123 in private subnet 1
    Value: !GetAtt Nlb6NodesStack.Outputs.ElbDNSName
  NetworkLoadBalancer8Nodes:
    Condition: 8NodesCondition
    Description: Network Load Balancer with port 8123 in private subnet 1
    Value: !GetAtt Nlb8NodesStack.Outputs.ElbDNSName
  CloudWatchDashboard:
    Description: CloudWatch Dashboard of ClickHouse cluster
    Value: !If [IsChinaRegion, !Sub 'https://console.amazonaws.cn/cloudwatch/home?region=${AWS::Region}#dashboards:name=ClickHouse-Cluster-Dashboard-${AWS::Region}', !Sub 'https://${AWS::Region}.console.aws.amazon.com/cloudwatch/home?region=${AWS::Region}#dashboards:name=ClickHouse-Cluster-Dashboard-${AWS::Region}']
  DBPassword:
    Description: Dynamically generate a random text string stored in SecretsManager to use as a password
    Value: !If [IsChinaRegion, 
      !Join ['', [!Sub 'https://console.amazonaws.cn/secretsmanager/home?region=${AWS::Region}#!/secret?name=', !Ref ClickHouseSecret]], 
      !Join ['', [!Sub 'https://console.aws.amazon.com/secretsmanager/home?region=${AWS::Region}#!/secret?name=', !Ref ClickHouseSecret]]]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



templates/clickhouse-entrypoint-new-vpc.template.yaml [831:1191]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  Nlb2NodesStack:
    Condition: 2NodesCondition
    Type: AWS::CloudFormation::Stack
    Properties: 
      TemplateURL:
        Fn::Sub: 
          - https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${QSS3KeyPrefix}templates/nlb.template.yaml
          - S3Region: !If 
              - UsingDefaultBucket
              - !Ref 'AWS::Region'
              - !Ref QSS3BucketRegion
            S3Bucket: !If 
              - UsingDefaultBucket
              - !Sub '${QSS3BucketName}-${AWS::Region}'
              - !Ref QSS3BucketName
      Parameters: 
        VPCID: !GetAtt VPCStack.Outputs.VPCID
        Subnets: !Join
          - ','
          - [ !GetAtt VPCStack.Outputs.PrivateSubnet1AID ]
        NodeCount: !Ref ClickHouseNodeCount
        Port: !Ref Port
        EC2Instance1: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID1
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID1
  Nlb4NodesStack:
    Condition: 4NodesCondition
    Type: AWS::CloudFormation::Stack
    Properties: 
      TemplateURL:
        Fn::Sub: 
          - https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${QSS3KeyPrefix}templates/nlb.template.yaml
          - S3Region: !If 
              - UsingDefaultBucket
              - !Ref 'AWS::Region'
              - !Ref QSS3BucketRegion
            S3Bucket: !If 
              - UsingDefaultBucket
              - !Sub '${QSS3BucketName}-${AWS::Region}'
              - !Ref QSS3BucketName
      Parameters: 
        VPCID: !GetAtt VPCStack.Outputs.VPCID
        Subnets: !Join
          - ','
          - [ !GetAtt VPCStack.Outputs.PrivateSubnet1AID ]
        NodeCount: !Ref ClickHouseNodeCount
        Port: !Ref Port
        EC2Instance1: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID1
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID1
        EC2Instance2: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID3
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID3
  Nlb6NodesStack:
    Condition: 6NodesCondition
    Type: AWS::CloudFormation::Stack
    Properties: 
      TemplateURL:
        Fn::Sub: 
          - https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${QSS3KeyPrefix}templates/nlb.template.yaml
          - S3Region: !If 
              - UsingDefaultBucket
              - !Ref 'AWS::Region'
              - !Ref QSS3BucketRegion
            S3Bucket: !If 
              - UsingDefaultBucket
              - !Sub '${QSS3BucketName}-${AWS::Region}'
              - !Ref QSS3BucketName
      Parameters: 
        VPCID: !GetAtt VPCStack.Outputs.VPCID
        Subnets: !Join
          - ','
          - [ !GetAtt VPCStack.Outputs.PrivateSubnet1AID ]
        NodeCount: !Ref ClickHouseNodeCount
        Port: !Ref Port
        EC2Instance1: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID1
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID1
        EC2Instance2: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID3
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID3
        EC2Instance3: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID5
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID5
  Nlb8NodesStack:
    Condition: 8NodesCondition
    Type: AWS::CloudFormation::Stack
    Properties: 
      TemplateURL:
        Fn::Sub: 
          - https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${QSS3KeyPrefix}templates/nlb.template.yaml
          - S3Region: !If 
              - UsingDefaultBucket
              - !Ref 'AWS::Region'
              - !Ref QSS3BucketRegion
            S3Bucket: !If 
              - UsingDefaultBucket
              - !Sub '${QSS3BucketName}-${AWS::Region}'
              - !Ref QSS3BucketName
      Parameters: 
        VPCID: !GetAtt VPCStack.Outputs.VPCID
        Subnets: !Join
          - ','
          - [ !GetAtt VPCStack.Outputs.PrivateSubnet1AID ]
        NodeCount: !Ref ClickHouseNodeCount
        Port: !Ref Port
        EC2Instance1: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID1
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID1
        EC2Instance2: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID3
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID3
        EC2Instance3: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID5
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID5
        EC2Instance4: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID7
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID7
  CloudWatchDashboard2Nodes:
    Condition: 2NodesCondition
    Type: AWS::CloudFormation::Stack
    Properties: 
      TemplateURL:
        Fn::Sub: 
          - https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${QSS3KeyPrefix}templates/cloudwatch-dashboard.template.yaml
          - S3Region: !If 
              - UsingDefaultBucket
              - !Ref 'AWS::Region'
              - !Ref QSS3BucketRegion
            S3Bucket: !If 
              - UsingDefaultBucket
              - !Sub '${QSS3BucketName}-${AWS::Region}'
              - !Ref QSS3BucketName
      Parameters: 
        DashboardName: !Sub 'ClickHouse-Cluster-Dashboard-${AWS::Region}'
        ClickHouseNodeCount: !Ref ClickHouseNodeCount
        ClickHouseInstanceID1: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID1
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID1
        ClickHouseInstanceID2: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID2
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID2
        ClickHouseImageId: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ImageId
          - !GetAtt ClickHouseClusterArmStack.Outputs.ImageId
        ClickHouseInstanceType: !Ref ClickHouseInstanceType
        ZookeeperInstanceID1: !GetAtt ZookeeperClusterStack.Outputs.ZookeeperInstanceID1
        ZookeeperInstanceID2: !GetAtt ZookeeperClusterStack.Outputs.ZookeeperInstanceID2
        ZookeeperInstanceID3: !GetAtt ZookeeperClusterStack.Outputs.ZookeeperInstanceID3
        ZookeeperImageId: !GetAtt ZookeeperClusterStack.Outputs.ImageId
        ZookeeperInstanceType: !Ref ZookeeperInstanceType
        AlarmEmail: !Ref AlarmEmail
  CloudWatchDashboard4Nodes:
    Condition: 4NodesCondition
    Type: AWS::CloudFormation::Stack
    Properties: 
      TemplateURL:
        Fn::Sub: 
          - https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${QSS3KeyPrefix}templates/cloudwatch-dashboard.template.yaml
          - S3Region: !If 
              - UsingDefaultBucket
              - !Ref 'AWS::Region'
              - !Ref QSS3BucketRegion
            S3Bucket: !If 
              - UsingDefaultBucket
              - !Sub '${QSS3BucketName}-${AWS::Region}'
              - !Ref QSS3BucketName
      Parameters: 
        DashboardName: !Sub 'ClickHouse-Cluster-Dashboard-${AWS::Region}'
        ClickHouseNodeCount: !Ref ClickHouseNodeCount
        ClickHouseInstanceID1: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID1
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID1
        ClickHouseInstanceID2: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID2
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID2
        ClickHouseInstanceID3: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID3
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID3
        ClickHouseInstanceID4: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID4
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID4
        ClickHouseImageId: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ImageId
          - !GetAtt ClickHouseClusterArmStack.Outputs.ImageId
        ClickHouseInstanceType: !Ref ClickHouseInstanceType
        ZookeeperInstanceID1: !GetAtt ZookeeperClusterStack.Outputs.ZookeeperInstanceID1
        ZookeeperInstanceID2: !GetAtt ZookeeperClusterStack.Outputs.ZookeeperInstanceID2
        ZookeeperInstanceID3: !GetAtt ZookeeperClusterStack.Outputs.ZookeeperInstanceID3
        ZookeeperImageId: !GetAtt ZookeeperClusterStack.Outputs.ImageId
        ZookeeperInstanceType: !Ref ZookeeperInstanceType
        AlarmEmail: !Ref AlarmEmail
  CloudWatchDashboard6Nodes:
    Condition: 6NodesCondition
    Type: AWS::CloudFormation::Stack
    Properties: 
      TemplateURL:
        Fn::Sub: 
          - https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${QSS3KeyPrefix}templates/cloudwatch-dashboard.template.yaml
          - S3Region: !If 
              - UsingDefaultBucket
              - !Ref 'AWS::Region'
              - !Ref QSS3BucketRegion
            S3Bucket: !If 
              - UsingDefaultBucket
              - !Sub '${QSS3BucketName}-${AWS::Region}'
              - !Ref QSS3BucketName
      Parameters: 
        DashboardName: !Sub 'ClickHouse-Cluster-Dashboard-${AWS::Region}'
        ClickHouseNodeCount: !Ref ClickHouseNodeCount
        ClickHouseInstanceID1: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID1
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID1
        ClickHouseInstanceID2: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID2
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID2
        ClickHouseInstanceID3: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID3
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID3
        ClickHouseInstanceID4: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID4
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID4
        ClickHouseInstanceID5: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID5
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID5
        ClickHouseInstanceID6: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID6
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID6
        ClickHouseImageId: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ImageId
          - !GetAtt ClickHouseClusterArmStack.Outputs.ImageId
        ClickHouseInstanceType: !Ref ClickHouseInstanceType
        ZookeeperInstanceID1: !GetAtt ZookeeperClusterStack.Outputs.ZookeeperInstanceID1
        ZookeeperInstanceID2: !GetAtt ZookeeperClusterStack.Outputs.ZookeeperInstanceID2
        ZookeeperInstanceID3: !GetAtt ZookeeperClusterStack.Outputs.ZookeeperInstanceID3
        ZookeeperImageId: !GetAtt ZookeeperClusterStack.Outputs.ImageId
        ZookeeperInstanceType: !Ref ZookeeperInstanceType
        AlarmEmail: !Ref AlarmEmail
  CloudWatchDashboard8Nodes:
    Condition: 8NodesCondition
    Type: AWS::CloudFormation::Stack
    Properties: 
      TemplateURL:
        Fn::Sub: 
          - https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${QSS3KeyPrefix}templates/cloudwatch-dashboard.template.yaml
          - S3Region: !If 
              - UsingDefaultBucket
              - !Ref 'AWS::Region'
              - !Ref QSS3BucketRegion
            S3Bucket: !If 
              - UsingDefaultBucket
              - !Sub '${QSS3BucketName}-${AWS::Region}'
              - !Ref QSS3BucketName
      Parameters: 
        DashboardName: !Sub 'ClickHouse-Cluster-Dashboard-${AWS::Region}'
        ClickHouseNodeCount: !Ref ClickHouseNodeCount
        ClickHouseInstanceID1: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID1
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID1
        ClickHouseInstanceID2: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID2
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID2
        ClickHouseInstanceID3: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID3
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID3
        ClickHouseInstanceID4: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID4
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID4
        ClickHouseInstanceID5: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID5
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID5
        ClickHouseInstanceID6: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID6
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID6
        ClickHouseInstanceID7: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID7
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID7
        ClickHouseInstanceID8: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ClickHouseInstanceID8
          - !GetAtt ClickHouseClusterArmStack.Outputs.ClickHouseInstanceID8
        ClickHouseImageId: !If 
          - IsX86 
          - !GetAtt ClickHouseClusterStack.Outputs.ImageId
          - !GetAtt ClickHouseClusterArmStack.Outputs.ImageId
        ClickHouseInstanceType: !Ref ClickHouseInstanceType
        ZookeeperInstanceID1: !GetAtt ZookeeperClusterStack.Outputs.ZookeeperInstanceID1
        ZookeeperInstanceID2: !GetAtt ZookeeperClusterStack.Outputs.ZookeeperInstanceID2
        ZookeeperInstanceID3: !GetAtt ZookeeperClusterStack.Outputs.ZookeeperInstanceID3
        ZookeeperImageId: !GetAtt ZookeeperClusterStack.Outputs.ImageId
        ZookeeperInstanceType: !Ref ZookeeperInstanceType
        AlarmEmail: !Ref AlarmEmail
Outputs:
  VPCCIDR:
    Description: The VPCCIDR for DW vpc
    Value: !GetAtt VPCStack.Outputs.VPCCIDR
  S3VPCEndpoint:
    Description: The S3VPCEndpoint for ClickHouse nodes
    Value: !GetAtt VPCStack.Outputs.S3VPCEndpoint
  CloudWatchLogs:
    Description: CloudWatch Logs GroupName. Your SSH logs will be stored here.
    Value: !GetAtt BastionStack.Outputs.CloudWatchLogs
  BastionEIP1:
    Description: Elastic IP 1 for Bastion
    Value: !GetAtt BastionStack.Outputs.EIP1
  NetworkLoadBalancer2Nodes:
    Condition: 2NodesCondition
    Description: Network Load Balancer with port 8123 in private subnet 1
    Value: !GetAtt Nlb2NodesStack.Outputs.ElbDNSName
  NetworkLoadBalancer4Nodes:
    Condition: 4NodesCondition
    Description: Network Load Balancer with port 8123 in private subnet 1
    Value: !GetAtt Nlb4NodesStack.Outputs.ElbDNSName
  NetworkLoadBalancer6Nodes:
    Condition: 6NodesCondition
    Description: Network Load Balancer with port 8123 in private subnet 1
    Value: !GetAtt Nlb6NodesStack.Outputs.ElbDNSName
  NetworkLoadBalancer8Nodes:
    Condition: 8NodesCondition
    Description: Network Load Balancer with port 8123 in private subnet 1
    Value: !GetAtt Nlb8NodesStack.Outputs.ElbDNSName
  CloudWatchDashboard:
    Description: CloudWatch Dashboard of ClickHouse cluster
    Value: !If [IsChinaRegion, !Sub 'https://console.amazonaws.cn/cloudwatch/home?region=${AWS::Region}#dashboards:name=ClickHouse-Cluster-Dashboard-${AWS::Region}', !Sub 'https://${AWS::Region}.console.aws.amazon.com/cloudwatch/home?region=${AWS::Region}#dashboards:name=ClickHouse-Cluster-Dashboard-${AWS::Region}']
  DBPassword:
    Description: Dynamically generate a random text string stored in SecretsManager to use as a password
    Value: !If [IsChinaRegion, 
      !Join ['', [!Sub 'https://console.amazonaws.cn/secretsmanager/home?region=${AWS::Region}#!/secret?name=', !Ref ClickHouseSecret]], 
      !Join ['', [!Sub 'https://console.aws.amazon.com/secretsmanager/home?region=${AWS::Region}#!/secret?name=', !Ref ClickHouseSecret]]]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



