AWSTemplateFormatVersion: '2010-09-09'
Description: (qs-1tsaami23)
Metadata:
  cfn-lint:
    config:
      ignore_checks:
        - W9002
        - W9003
        - W9006
        - E9007
Parameters:
  WSFCNodeInstanceType:
    AllowedValues:
      - r4.xlarge
      - r4.2xlarge
      - r4.4xlarge
      - r4.4xlarge
      - r5.large
      - r5.xlarge
      - r5.2xlarge
      - r5.4xlarge
      - r5.12xlarge
    ConstraintDescription: Only EBS Optimized instance types r4.xlarge, r4.2xlarge,
      r4.4xlarge, r4.8xlarge allowed
    Default: r5.2xlarge
    Description: Amazon EC2 instance type for the WSFC Nodes
    Type: String
  AutoPlacement:
    Description: 'Does host allow auto-placement (dedicated) or only allow placement
      by specifying hostid (host) '
    Type: String
    AllowedValues:
      - 'on'
      - 'off'
    Default: 'on'
  AvailabilityZones:
    Description: >-
      List of Availability Zones to use for the subnets in the VPC. Note: The logical
      order is preserved and that 2 AZ's must be provided unless the Third AZ parameter
      is specified, in which case 3 AZ's must me provided.
    Type: List<AWS::EC2::AvailabilityZone::Name>
  3rdAZ:
    Description: create a host in a 3rd AZ
    Type: String
    Default: 'no'
    AllowedValues:
      - 'no'
      - 'yes'
Mappings: {}
Conditions:
  Create3rdHost: !Equals
    - !Ref '3rdAZ'
    - 'yes'
Resources:
  DedicatedHost1:
    Type: AWS::EC2::Host
    Properties:
      AutoPlacement: !Ref 'AutoPlacement'
      AvailabilityZone: !Select
        - 0
        - !Ref 'AvailabilityZones'
      InstanceType: !Ref 'WSFCNodeInstanceType'
  DedicatedHost2:
    Type: AWS::EC2::Host
    Properties:
      AutoPlacement: !Ref 'AutoPlacement'
      AvailabilityZone: !Select
        - 1
        - !Ref 'AvailabilityZones'
      InstanceType: !Ref 'WSFCNodeInstanceType'
  DedicatedHost3:
    Type: AWS::EC2::Host
    Condition: Create3rdHost
    Properties:
      AutoPlacement: !Ref 'AutoPlacement'
      AvailabilityZone: !Select
        - 2
        - !Ref 'AvailabilityZones'
      InstanceType: !Ref 'WSFCNodeInstanceType'
Outputs:
  DedicatedHost1:
    Value: !Ref 'DedicatedHost1'
  DedicatedHost2:
    Value: !Ref 'DedicatedHost2'
  DedicatedHost3:
    Value: !Ref 'DedicatedHost3'
    Condition: Create3rdHost