templates/clickhouse-arm-entrypoint-new-vpc.template.yaml [513:809]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Conditions:
  UsingDefaultBucket: !Equals [!Ref QSS3BucketName, 'aws-quickstart']
  UsingSingleAZ: !Equals [!Ref SingleAvailableZone, '1az']
  IsX86: !Equals [!Ref Architecture, 'X86']
  IsArm: !Equals [!Ref Architecture, 'ARM']
  IsChinaRegion: !Or 
      - !Equals 
        - !Ref 'AWS::Region'
        - cn-north-1
      - !Equals 
        - !Ref 'AWS::Region'
        - cn-northwest-1
  2NodesCondition: !Equals [!Ref 'ClickHouseNodeCount', '2']
  4NodesCondition: !Equals [!Ref 'ClickHouseNodeCount', '4'] 
  6NodesCondition: !Equals [!Ref 'ClickHouseNodeCount', '6'] 
  8NodesCondition: !Equals [!Ref 'ClickHouseNodeCount', '8']
Resources:
  VPCStack:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: 
        Fn::Sub:
            - https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${QSS3KeyPrefix}submodules/quickstart-aws-vpc/templates/aws-vpc.template.yaml
            - S3Region: !If 
                - UsingDefaultBucket
                - !Ref 'AWS::Region'
                - !Ref QSS3BucketRegion
              S3Bucket: !If 
                - UsingDefaultBucket
                - !Sub '${QSS3BucketName}-${AWS::Region}'
                - !Ref QSS3BucketName
      Parameters:
        AvailabilityZones:
          !Join
          - ','
          - !Ref AvailabilityZones
        NumberOfAZs: '2'
        CreateNATGateways: 'true'
        PrivateSubnet1ACIDR: !Ref PrivateSubnet1CIDR
        PrivateSubnet2ACIDR: !Ref PrivateSubnet2CIDR
        PublicSubnet1CIDR: !Ref PublicSubnet1CIDR
        PublicSubnet2CIDR: !Ref PublicSubnet2CIDR
        VPCCIDR: !Ref VPCCIDR
        CreateAdditionalPrivateSubnets: 'false'
        CreatePublicSubnets: 'true'
        CreatePrivateSubnets: 'true'
        CreateVPCFlowLogsToCloudWatch: 'false'
        PrivateSubnet1BCIDR: 10.0.192.0/21
        PrivateSubnet2BCIDR: 10.0.200.0/21
        PrivateSubnet3ACIDR: 10.0.64.0/19
        PrivateSubnet3BCIDR: 10.0.208.0/21
        PrivateSubnet4ACIDR: 10.0.96.0/19
        PrivateSubnet4BCIDR: 10.0.216.0/21
        PrivateSubnetATag1: Network=Private
        PrivateSubnetATag2: ''
        PrivateSubnetATag3: ''
        PrivateSubnetBTag1: Network=Private
        PrivateSubnetBTag2: ''
        PrivateSubnetBTag3: ''
        PublicSubnet3CIDR: 10.0.160.0/20
        PublicSubnet4CIDR: 10.0.176.0/20
        PublicSubnetTag1: Network=Public
        PublicSubnetTag2: ''
        PublicSubnetTag3: ''
        VPCFlowLogsCloudWatchKMSKey: ''
        VPCFlowLogsLogGroupRetention: 14
        VPCFlowLogsMaxAggregationInterval: 600
        VPCFlowLogsTrafficType: REJECT
        VPCTenancy: default
  BastionStack:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: !Sub
        - 'https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${QSS3KeyPrefix}submodules/quickstart-linux-bastion/templates/linux-bastion.template'
        - S3Region: !If [UsingDefaultBucket, !Ref 'AWS::Region', !Ref QSS3BucketRegion]
          S3Bucket: !If [UsingDefaultBucket, !Sub '${QSS3BucketName}-${AWS::Region}', !Ref QSS3BucketName]
      Parameters:
        BastionAMIOS: !Ref BastionAMIOS
        BastionInstanceType: !Ref BastionInstanceType
        # For PVRE compliance
        OSImageOverride: !Ref LatestAmiId
        NumBastionHosts: !Ref NumBastionHosts
        KeyPairName: !Ref KeyPairName
        EnableTCPForwarding: 'true'
        PublicSubnet1ID: !GetAtt VPCStack.Outputs.PublicSubnet1ID
        PublicSubnet2ID: !GetAtt VPCStack.Outputs.PublicSubnet2ID
        RemoteAccessCIDR: !Ref RemoteAccessCIDR
        VPCID: !GetAtt VPCStack.Outputs.VPCID
        QSS3BucketName: !Ref QSS3BucketName
        QSS3BucketRegion: !Ref QSS3BucketRegion
        QSS3KeyPrefix: !Sub '${QSS3KeyPrefix}submodules/quickstart-linux-bastion/'
  SecurityGroupStack:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: 
        Fn::Sub:
          - https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${QSS3KeyPrefix}templates/securitygroups.template.yaml
          - S3Region: !If 
              - UsingDefaultBucket
              - !Ref 'AWS::Region'
              - !Ref QSS3BucketRegion
            S3Bucket: !If 
              - UsingDefaultBucket
              - !Sub '${QSS3BucketName}-${AWS::Region}'
              - !Ref QSS3BucketName
      Parameters:
        AccessCIDR: !Ref AccessCIDR
        VPCID: !GetAtt VPCStack.Outputs.VPCID
        VPCCIDR: !GetAtt VPCStack.Outputs.VPCCIDR
        BastionSecurityGroupID: !GetAtt BastionStack.Outputs.BastionSecurityGroupID
  ClickHouseSecret:
    Type: 'AWS::SecretsManager::Secret'
    Properties:
      Name: !Join ['-',['ClickHouseSecret',!GetAtt BastionStack.Outputs.BastionSecurityGroupID]]
      Description: "This secret has a dynamically generated secret password."
      GenerateSecretString:
        SecretStringTemplate: '{}'
        GenerateStringKey: "password"
        PasswordLength: 20
        ExcludeCharacters: '"@/\|.,;!#$%^&*()_`[]{}<>=-+?~:'
        ExcludePunctuation: true
      Tags:
        -
          Key: AppName
          Value: !Join ['-',['ClickHouseSecret',!GetAtt BastionStack.Outputs.BastionSecurityGroupID]]
  ZookeeperClusterStack: 
    Type: AWS::CloudFormation::Stack
    Properties: 
      TemplateURL:
        Fn::Sub: 
          - https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${QSS3KeyPrefix}templates/zookeeper.template.yaml
          - S3Region: !If 
              - UsingDefaultBucket
              - !Ref 'AWS::Region'
              - !Ref QSS3BucketRegion
            S3Bucket: !If 
              - UsingDefaultBucket
              - !Sub '${QSS3BucketName}-${AWS::Region}'
              - !Ref QSS3BucketName
      Parameters: 
        RootStackName: !GetAtt BastionStack.Outputs.BastionSecurityGroupID
        PrivateSubnetID1:
          Fn::GetAtt: 
            - VPCStack
            - Outputs.PrivateSubnet1AID
        PrivateSubnetID2:
          Fn::GetAtt: 
            - VPCStack
            - Outputs.PrivateSubnet2AID
        KeyPairName: !Ref KeyPairName
        ZookeeperInstanceType: !Ref ZookeeperInstanceType
        ZookeeperVersion: !Ref ZookeeperVersion
        ZookeeperServerSecurityGroupID: !GetAtt SecurityGroupStack.Outputs.ClickHouseServerSecurityGroup
        ZookeeperNodeName1: ZookeeperNode1
        ZookeeperNodeName2: ZookeeperNode2
        ZookeeperNodeName3: ZookeeperNode3
        ZookeeperNodeCount: !Ref ZookeeperNodeCount
        DeviceName: !Ref ZookeeperDeviceName
        VolumeType: !Ref ZookeeperVolumeType
        VolumeSize: !Ref ZookeeperVolumeSize
        Iops: !Ref ZookeeperIops
        CloudWatchAgentURL: !If [IsChinaRegion, 'https://s3.cn-north-1.amazonaws.com.cn/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm', 'https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm']
        InstanceRoleArn: !If [IsChinaRegion, 'aws-cn', 'aws']
        QSS3BucketName: !Ref QSS3BucketName
        QSS3KeyPrefix: !Ref QSS3KeyPrefix
  ClickHouseBucket:
    Type: AWS::S3::Bucket
    DeletionPolicy: Retain
    UpdateReplacePolicy: Retain
    Properties:
      BucketName: 
        !Join 
          - '-' 
          - ['clickhouse-data',!GetAtt VPCStack.Outputs.VPCID]
      VersioningConfiguration:
        Status: Enabled
      IntelligentTieringConfigurations:
        - Id: clickhouse-data-tier1
          Status: Enabled
          Tierings:
            - AccessTier: ARCHIVE_ACCESS
              Days: 180
  ClickHouseClusterStack: 
    Condition: IsX86
    Type: AWS::CloudFormation::Stack
    Properties: 
      TemplateURL:
        Fn::Sub: 
          - https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${QSS3KeyPrefix}templates/clickhouse.template.yaml
          - S3Region: !If 
              - UsingDefaultBucket
              - !Ref 'AWS::Region'
              - !Ref QSS3BucketRegion
            S3Bucket: !If 
              - UsingDefaultBucket
              - !Sub '${QSS3BucketName}-${AWS::Region}'
              - !Ref QSS3BucketName
      Parameters: 
        RootStackName: !GetAtt BastionStack.Outputs.BastionSecurityGroupID
        PrivateSubnetID1:
          Fn::GetAtt: 
            - VPCStack
            - Outputs.PrivateSubnet1AID
        PrivateSubnetID2: !If
          - UsingSingleAZ 
          - Fn::GetAtt: 
            - VPCStack
            - Outputs.PrivateSubnet1AID
          - Fn::GetAtt: 
            - VPCStack
            - Outputs.PrivateSubnet2AID
        ClickHouseServerSecurityGroup: !GetAtt SecurityGroupStack.Outputs.ClickHouseServerSecurityGroup
        AdminServerSecurityGroup: !GetAtt SecurityGroupStack.Outputs.AdminServerSecurityGroup
        KeyPairName: !Ref KeyPairName
        ClickHouseInstanceType: !Ref ClickHouseInstanceType
        ClickHouseVersion: !Ref ClickHouseVersion
        ClickHouseTimezone: !Ref ClickHouseTimezone
        ClickHouseNodeCount: !Ref ClickHouseNodeCount
        ClickHouseBucketName: !Ref ClickHouseBucket
        DeviceName: !Ref ClickHouseDeviceName
        VolumeType: !Ref ClickHouseVolumeType
        VolumeSize: !Ref ClickHouseVolumeSize
        Iops: !Ref ClickHouseIops
        MaxThreads: !Ref MaxThreads
        MaxMemoryUsage: !Ref MaxMemoryUsage
        MaxInsertThreads: !Ref MaxInsertThreads
        DistributedProductMode: !Ref DistributedProductMode
        LoadBalancing: !Ref LoadBalancing
        MaxDataPartSize: !Ref MaxDataPartSize
        MoveFactor: !Ref MoveFactor
        GrafanaVersion: !Ref GrafanaVersion
        DemoDataSize: !Ref DemoDataSize
        ZookeeperPrivateIp1: !GetAtt ZookeeperClusterStack.Outputs.ZookeeperPrivateIp1
        ZookeeperPrivateIp2: !GetAtt ZookeeperClusterStack.Outputs.ZookeeperPrivateIp2
        ZookeeperPrivateIp3: !GetAtt ZookeeperClusterStack.Outputs.ZookeeperPrivateIp3
        CloudWatchAgentURL: !If [IsChinaRegion, 'https://s3.cn-north-1.amazonaws.com.cn/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm', 'https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm']
        InstanceRoleArn: !If [IsChinaRegion, 'aws-cn', 'aws']
        QSS3BucketName: !Ref QSS3BucketName
        QSS3KeyPrefix: !Ref QSS3KeyPrefix
        SecretId: !Ref ClickHouseSecret
  ClickHouseClusterArmStack: 
    Condition: IsArm
    Type: AWS::CloudFormation::Stack
    Properties: 
      TemplateURL:
        Fn::Sub: 
          - https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${QSS3KeyPrefix}templates/clickhouse.arm.template.yaml
          - S3Region: !If 
              - UsingDefaultBucket
              - !Ref 'AWS::Region'
              - !Ref QSS3BucketRegion
            S3Bucket: !If 
              - UsingDefaultBucket
              - !Sub '${QSS3BucketName}-${AWS::Region}'
              - !Ref QSS3BucketName
      Parameters: 
        RootStackName: !GetAtt BastionStack.Outputs.BastionSecurityGroupID
        PrivateSubnetID1:
          Fn::GetAtt: 
            - VPCStack
            - Outputs.PrivateSubnet1AID
        PrivateSubnetID2: !If
          - UsingSingleAZ 
          - Fn::GetAtt: 
            - VPCStack
            - Outputs.PrivateSubnet1AID
          - Fn::GetAtt: 
            - VPCStack
            - Outputs.PrivateSubnet2AID
        ClickHouseServerSecurityGroup: !GetAtt SecurityGroupStack.Outputs.ClickHouseServerSecurityGroup
        AdminServerSecurityGroup: !GetAtt SecurityGroupStack.Outputs.AdminServerSecurityGroup
        KeyPairName: !Ref KeyPairName
        ClickHouseInstanceType: !Ref ClickHouseInstanceType
        ClickHouseVersion: !Ref ClickHouseVersion
        ClickHouseTimezone: !Ref ClickHouseTimezone
        ClickHouseNodeCount: !Ref ClickHouseNodeCount
        ClickHouseBucketName: !Ref ClickHouseBucket
        DeviceName: !Ref ClickHouseDeviceName
        VolumeType: !Ref ClickHouseVolumeType
        VolumeSize: !Ref ClickHouseVolumeSize
        Iops: !Ref ClickHouseIops
        MaxThreads: !Ref MaxThreads
        MaxMemoryUsage: !Ref MaxMemoryUsage
        MaxInsertThreads: !Ref MaxInsertThreads
        DistributedProductMode: !Ref DistributedProductMode
        LoadBalancing: !Ref LoadBalancing
        MaxDataPartSize: !Ref MaxDataPartSize
        MoveFactor: !Ref MoveFactor
        GrafanaVersion: !Ref GrafanaVersion
        DemoDataSize: !Ref DemoDataSize
        ZookeeperPrivateIp1: !GetAtt ZookeeperClusterStack.Outputs.ZookeeperPrivateIp1
        ZookeeperPrivateIp2: !GetAtt ZookeeperClusterStack.Outputs.ZookeeperPrivateIp2
        ZookeeperPrivateIp3: !GetAtt ZookeeperClusterStack.Outputs.ZookeeperPrivateIp3
        CloudWatchAgentURL: !If [IsChinaRegion, 'https://s3.cn-north-1.amazonaws.com.cn/amazoncloudwatch-agent/ubuntu/arm64/latest/amazon-cloudwatch-agent.deb', 'https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/arm64/latest/amazon-cloudwatch-agent.deb']
        InstanceRoleArn: !If [IsChinaRegion, 'aws-cn', 'aws']
        QSS3BucketName: !Ref QSS3BucketName
        QSS3KeyPrefix: !Ref QSS3KeyPrefix
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



templates/clickhouse-entrypoint-new-vpc.template.yaml [535:830]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Conditions:
  UsingDefaultBucket: !Equals [!Ref QSS3BucketName, 'aws-quickstart']
  UsingSingleAZ: !Equals [!Ref SingleAvailableZone, '1az']
  IsX86: !Equals [!Ref Architecture, 'X86']
  IsArm: !Equals [!Ref Architecture, 'ARM']
  IsChinaRegion: !Or 
      - !Equals 
        - !Ref 'AWS::Region'
        - cn-north-1
      - !Equals 
        - !Ref 'AWS::Region'
        - cn-northwest-1
  2NodesCondition: !Equals [!Ref 'ClickHouseNodeCount', '2']
  4NodesCondition: !Equals [!Ref 'ClickHouseNodeCount', '4'] 
  6NodesCondition: !Equals [!Ref 'ClickHouseNodeCount', '6'] 
  8NodesCondition: !Equals [!Ref 'ClickHouseNodeCount', '8']
Resources:
  VPCStack:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: 
        Fn::Sub:
            - https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${QSS3KeyPrefix}submodules/quickstart-aws-vpc/templates/aws-vpc.template.yaml
            - S3Region: !If 
                - UsingDefaultBucket
                - !Ref 'AWS::Region'
                - !Ref QSS3BucketRegion
              S3Bucket: !If 
                - UsingDefaultBucket
                - !Sub '${QSS3BucketName}-${AWS::Region}'
                - !Ref QSS3BucketName
      Parameters:
        AvailabilityZones:
          !Join
          - ','
          - !Ref AvailabilityZones
        NumberOfAZs: '2'
        CreateNATGateways: 'true'
        PrivateSubnet1ACIDR: !Ref PrivateSubnet1CIDR
        PrivateSubnet2ACIDR: !Ref PrivateSubnet2CIDR
        PublicSubnet1CIDR: !Ref PublicSubnet1CIDR
        PublicSubnet2CIDR: !Ref PublicSubnet2CIDR
        VPCCIDR: !Ref VPCCIDR
        CreateAdditionalPrivateSubnets: 'false'
        CreatePublicSubnets: 'true'
        CreatePrivateSubnets: 'true'
        CreateVPCFlowLogsToCloudWatch: 'false'
        PrivateSubnet1BCIDR: 10.0.192.0/21
        PrivateSubnet2BCIDR: 10.0.200.0/21
        PrivateSubnet3ACIDR: 10.0.64.0/19
        PrivateSubnet3BCIDR: 10.0.208.0/21
        PrivateSubnet4ACIDR: 10.0.96.0/19
        PrivateSubnet4BCIDR: 10.0.216.0/21
        PrivateSubnetATag1: Network=Private
        PrivateSubnetATag2: ''
        PrivateSubnetATag3: ''
        PrivateSubnetBTag1: Network=Private
        PrivateSubnetBTag2: ''
        PrivateSubnetBTag3: ''
        PublicSubnet3CIDR: 10.0.160.0/20
        PublicSubnet4CIDR: 10.0.176.0/20
        PublicSubnetTag1: Network=Public
        PublicSubnetTag2: ''
        PublicSubnetTag3: ''
        VPCFlowLogsCloudWatchKMSKey: ''
        VPCFlowLogsLogGroupRetention: 14
        VPCFlowLogsMaxAggregationInterval: 600
        VPCFlowLogsTrafficType: REJECT
        VPCTenancy: default
  BastionStack:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: !Sub
        - 'https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${QSS3KeyPrefix}submodules/quickstart-linux-bastion/templates/linux-bastion.template'
        - S3Region: !If [UsingDefaultBucket, !Ref 'AWS::Region', !Ref QSS3BucketRegion]
          S3Bucket: !If [UsingDefaultBucket, !Sub '${QSS3BucketName}-${AWS::Region}', !Ref QSS3BucketName]
      Parameters:
        BastionAMIOS: !Ref BastionAMIOS
        BastionInstanceType: !Ref BastionInstanceType
        OSImageOverride: !Ref LatestAmiId
        NumBastionHosts: !Ref NumBastionHosts
        KeyPairName: !Ref KeyPairName
        EnableTCPForwarding: 'true'
        PublicSubnet1ID: !GetAtt VPCStack.Outputs.PublicSubnet1ID
        PublicSubnet2ID: !GetAtt VPCStack.Outputs.PublicSubnet2ID
        RemoteAccessCIDR: !Ref RemoteAccessCIDR
        VPCID: !GetAtt VPCStack.Outputs.VPCID
        QSS3BucketName: !Ref QSS3BucketName
        QSS3BucketRegion: !Ref QSS3BucketRegion
        QSS3KeyPrefix: !Sub '${QSS3KeyPrefix}submodules/quickstart-linux-bastion/'
  SecurityGroupStack:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: 
        Fn::Sub:
          - https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${QSS3KeyPrefix}templates/securitygroups.template.yaml
          - S3Region: !If 
              - UsingDefaultBucket
              - !Ref 'AWS::Region'
              - !Ref QSS3BucketRegion
            S3Bucket: !If 
              - UsingDefaultBucket
              - !Sub '${QSS3BucketName}-${AWS::Region}'
              - !Ref QSS3BucketName
      Parameters:
        AccessCIDR: !Ref AccessCIDR
        VPCID: !GetAtt VPCStack.Outputs.VPCID
        VPCCIDR: !GetAtt VPCStack.Outputs.VPCCIDR
        BastionSecurityGroupID: !GetAtt BastionStack.Outputs.BastionSecurityGroupID
  ClickHouseSecret:
    Type: 'AWS::SecretsManager::Secret'
    Properties:
      Name: !Join ['-',['ClickHouseSecret',!GetAtt BastionStack.Outputs.BastionSecurityGroupID]]
      Description: "This secret has a dynamically generated secret password."
      GenerateSecretString:
        SecretStringTemplate: '{}'
        GenerateStringKey: "password"
        PasswordLength: 20
        ExcludeCharacters: '"@/\|.,;!#$%^&*()_`[]{}<>=-+?~:'
        ExcludePunctuation: true
      Tags:
        -
          Key: AppName
          Value: !Join ['-',['ClickHouseSecret',!GetAtt BastionStack.Outputs.BastionSecurityGroupID]]
  ZookeeperClusterStack: 
    Type: AWS::CloudFormation::Stack
    Properties: 
      TemplateURL:
        Fn::Sub: 
          - https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${QSS3KeyPrefix}templates/zookeeper.template.yaml
          - S3Region: !If 
              - UsingDefaultBucket
              - !Ref 'AWS::Region'
              - !Ref QSS3BucketRegion
            S3Bucket: !If 
              - UsingDefaultBucket
              - !Sub '${QSS3BucketName}-${AWS::Region}'
              - !Ref QSS3BucketName
      Parameters: 
        RootStackName: !GetAtt BastionStack.Outputs.BastionSecurityGroupID
        PrivateSubnetID1:
          Fn::GetAtt: 
            - VPCStack
            - Outputs.PrivateSubnet1AID
        PrivateSubnetID2:
          Fn::GetAtt: 
            - VPCStack
            - Outputs.PrivateSubnet2AID
        KeyPairName: !Ref KeyPairName
        ZookeeperInstanceType: !Ref ZookeeperInstanceType
        ZookeeperVersion: !Ref ZookeeperVersion
        ZookeeperServerSecurityGroupID: !GetAtt SecurityGroupStack.Outputs.ClickHouseServerSecurityGroup
        ZookeeperNodeName1: ZookeeperNode1
        ZookeeperNodeName2: ZookeeperNode2
        ZookeeperNodeName3: ZookeeperNode3
        ZookeeperNodeCount: !Ref ZookeeperNodeCount
        DeviceName: !Ref ZookeeperDeviceName
        VolumeType: !Ref ZookeeperVolumeType
        VolumeSize: !Ref ZookeeperVolumeSize
        Iops: !Ref ZookeeperIops
        CloudWatchAgentURL: !If [IsChinaRegion, 'https://s3.cn-north-1.amazonaws.com.cn/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm', 'https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm']
        InstanceRoleArn: !If [IsChinaRegion, 'aws-cn', 'aws']
        QSS3BucketName: !Ref QSS3BucketName
        QSS3KeyPrefix: !Ref QSS3KeyPrefix
  ClickHouseBucket:
    Type: AWS::S3::Bucket
    DeletionPolicy: Retain
    UpdateReplacePolicy: Retain
    Properties:
      BucketName: 
        !Join 
          - '-' 
          - ['clickhouse-data',!GetAtt VPCStack.Outputs.VPCID]
      VersioningConfiguration:
        Status: Enabled
      IntelligentTieringConfigurations:
        - Id: clickhouse-data-tier1
          Status: Enabled
          Tierings:
            - AccessTier: ARCHIVE_ACCESS
              Days: 180
  ClickHouseClusterStack: 
    Condition: IsX86
    Type: AWS::CloudFormation::Stack
    Properties: 
      TemplateURL:
        Fn::Sub: 
          - https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${QSS3KeyPrefix}templates/clickhouse.template.yaml
          - S3Region: !If 
              - UsingDefaultBucket
              - !Ref 'AWS::Region'
              - !Ref QSS3BucketRegion
            S3Bucket: !If 
              - UsingDefaultBucket
              - !Sub '${QSS3BucketName}-${AWS::Region}'
              - !Ref QSS3BucketName
      Parameters: 
        RootStackName: !GetAtt BastionStack.Outputs.BastionSecurityGroupID
        PrivateSubnetID1:
          Fn::GetAtt: 
            - VPCStack
            - Outputs.PrivateSubnet1AID
        PrivateSubnetID2: !If
          - UsingSingleAZ 
          - Fn::GetAtt: 
            - VPCStack
            - Outputs.PrivateSubnet1AID
          - Fn::GetAtt: 
            - VPCStack
            - Outputs.PrivateSubnet2AID
        ClickHouseServerSecurityGroup: !GetAtt SecurityGroupStack.Outputs.ClickHouseServerSecurityGroup
        AdminServerSecurityGroup: !GetAtt SecurityGroupStack.Outputs.AdminServerSecurityGroup
        KeyPairName: !Ref KeyPairName
        ClickHouseInstanceType: !Ref ClickHouseInstanceType
        ClickHouseVersion: !Ref ClickHouseVersion
        ClickHouseTimezone: !Ref ClickHouseTimezone
        ClickHouseNodeCount: !Ref ClickHouseNodeCount
        ClickHouseBucketName: !Ref ClickHouseBucket
        DeviceName: !Ref ClickHouseDeviceName
        VolumeType: !Ref ClickHouseVolumeType
        VolumeSize: !Ref ClickHouseVolumeSize
        Iops: !Ref ClickHouseIops
        MaxThreads: !Ref MaxThreads
        MaxMemoryUsage: !Ref MaxMemoryUsage
        MaxInsertThreads: !Ref MaxInsertThreads
        DistributedProductMode: !Ref DistributedProductMode
        LoadBalancing: !Ref LoadBalancing
        MaxDataPartSize: !Ref MaxDataPartSize
        MoveFactor: !Ref MoveFactor
        GrafanaVersion: !Ref GrafanaVersion
        DemoDataSize: !Ref DemoDataSize
        ZookeeperPrivateIp1: !GetAtt ZookeeperClusterStack.Outputs.ZookeeperPrivateIp1
        ZookeeperPrivateIp2: !GetAtt ZookeeperClusterStack.Outputs.ZookeeperPrivateIp2
        ZookeeperPrivateIp3: !GetAtt ZookeeperClusterStack.Outputs.ZookeeperPrivateIp3
        CloudWatchAgentURL: !If [IsChinaRegion, 'https://s3.cn-north-1.amazonaws.com.cn/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm', 'https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm']
        InstanceRoleArn: !If [IsChinaRegion, 'aws-cn', 'aws']
        QSS3BucketName: !Ref QSS3BucketName
        QSS3KeyPrefix: !Ref QSS3KeyPrefix
        SecretId: !Ref ClickHouseSecret
  ClickHouseClusterArmStack: 
    Condition: IsArm
    Type: AWS::CloudFormation::Stack
    Properties: 
      TemplateURL:
        Fn::Sub: 
          - https://${S3Bucket}.s3.${S3Region}.${AWS::URLSuffix}/${QSS3KeyPrefix}templates/clickhouse.arm.template.yaml
          - S3Region: !If 
              - UsingDefaultBucket
              - !Ref 'AWS::Region'
              - !Ref QSS3BucketRegion
            S3Bucket: !If 
              - UsingDefaultBucket
              - !Sub '${QSS3BucketName}-${AWS::Region}'
              - !Ref QSS3BucketName
      Parameters: 
        RootStackName: !GetAtt BastionStack.Outputs.BastionSecurityGroupID
        PrivateSubnetID1:
          Fn::GetAtt: 
            - VPCStack
            - Outputs.PrivateSubnet1AID
        PrivateSubnetID2: !If
          - UsingSingleAZ 
          - Fn::GetAtt: 
            - VPCStack
            - Outputs.PrivateSubnet1AID
          - Fn::GetAtt: 
            - VPCStack
            - Outputs.PrivateSubnet2AID
        ClickHouseServerSecurityGroup: !GetAtt SecurityGroupStack.Outputs.ClickHouseServerSecurityGroup
        AdminServerSecurityGroup: !GetAtt SecurityGroupStack.Outputs.AdminServerSecurityGroup
        KeyPairName: !Ref KeyPairName
        ClickHouseInstanceType: !Ref ClickHouseInstanceType
        ClickHouseVersion: !Ref ClickHouseVersion
        ClickHouseTimezone: !Ref ClickHouseTimezone
        ClickHouseNodeCount: !Ref ClickHouseNodeCount
        ClickHouseBucketName: !Ref ClickHouseBucket
        DeviceName: !Ref ClickHouseDeviceName
        VolumeType: !Ref ClickHouseVolumeType
        VolumeSize: !Ref ClickHouseVolumeSize
        Iops: !Ref ClickHouseIops
        MaxThreads: !Ref MaxThreads
        MaxMemoryUsage: !Ref MaxMemoryUsage
        MaxInsertThreads: !Ref MaxInsertThreads
        DistributedProductMode: !Ref DistributedProductMode
        LoadBalancing: !Ref LoadBalancing
        MaxDataPartSize: !Ref MaxDataPartSize
        MoveFactor: !Ref MoveFactor
        GrafanaVersion: !Ref GrafanaVersion
        DemoDataSize: !Ref DemoDataSize
        ZookeeperPrivateIp1: !GetAtt ZookeeperClusterStack.Outputs.ZookeeperPrivateIp1
        ZookeeperPrivateIp2: !GetAtt ZookeeperClusterStack.Outputs.ZookeeperPrivateIp2
        ZookeeperPrivateIp3: !GetAtt ZookeeperClusterStack.Outputs.ZookeeperPrivateIp3
        CloudWatchAgentURL: !If [IsChinaRegion, 'https://s3.cn-north-1.amazonaws.com.cn/amazoncloudwatch-agent/ubuntu/arm64/latest/amazon-cloudwatch-agent.deb', 'https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/arm64/latest/amazon-cloudwatch-agent.deb']
        InstanceRoleArn: !If [IsChinaRegion, 'aws-cn', 'aws']
        QSS3BucketName: !Ref QSS3BucketName
        QSS3KeyPrefix: !Ref QSS3KeyPrefix
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



