AWSTemplateFormatVersion: 2010-09-09
Description: Valohai Private Workers resources
Parameters:
  KeyPair:
    Type: AWS::EC2::KeyPair::KeyName
    Description: KeyPair that will be used for Valohai instances. You'll need to create
      this under EC2 -> KeyPairs before you can continue.
  QueueAddress:
    Type: String
    Description: Address of the Valohai queue that will be setup.
  Suffix:
    Type: String
    Description: Unique suffix used with some of the resources, you can for example
      use the stack name.
  ValohaiMasterRoleARN:
    Type: String
    Description: Name of the Valohai Master Role used for autoscaling resources.
  VpcId:
    Type: String
    Description: OPTIONAL. Provide an existing VPC ID to use with Valohai resources.
      Leave empty if you want to create a new VPC.
    Default: ''
  Subnet:
    Type: String
    Description: Provide the Subnet ID that should be used for the Valohai Queue instance,
      if you're using an existing VPC. Leave empty if you want the template to create
      a new VPC and Subnet.
    Default: ''
Conditions:
  CreateVPC:
    Fn::Equals:
    - Ref: VpcId
    - ''
Mappings:
  RegionMap:
    af-south-1:
      AZs: 3
      ImageId: ami-08a4b40f2fe1e4b35
    ap-east-1:
      AZs: 3
      ImageId: ami-0b215afe809665ae5
    ap-northeast-1:
      AZs: 3
      ImageId: ami-0df99b3a8349462c6
    ap-northeast-2:
      AZs: 4
      ImageId: ami-04876f29fd3a5e8ba
    ap-northeast-3:
      AZs: 3
      ImageId: ami-0001d1dd884af8872
    ap-south-1:
      AZs: 3
      ImageId: ami-0c1a7f89451184c8b
    ap-southeast-1:
      AZs: 3
      ImageId: ami-0d058fe428540cd89
    ap-southeast-2:
      AZs: 3
      ImageId: ami-0567f647e75c7bc05
    ca-central-1:
      AZs: 3
      ImageId: ami-0801628222e2e96d6
    eu-central-1:
      AZs: 3
      ImageId: ami-05f7491af5eef733a
    eu-south-1:
      AZs: 3
      ImageId: ami-018f430e4f5375e69
    eu-west-1:
      AZs: 3
      ImageId: ami-0a8e758f5e873d1c1
    eu-west-2:
      AZs: 3
      ImageId: ami-0194c3e07668a7e36
    eu-west-3:
      AZs: 3
      ImageId: ami-0f7cd40eac2214b37
    eu-north-1:
      AZs: 3
      ImageId: ami-0ff338189efb7ed37
    me-south-1:
      AZs: 3
      ImageId: ami-0eddb8cfbd6a5f657
    sa-east-1:
      AZs: 3
      ImageId: ami-054a31f1b3bf90920
    us-east-1:
      AZs: 6
      ImageId: ami-09e67e426f25ce0d7
    us-east-2:
      AZs: 3
      ImageId: ami-00399ec92321828f5
    us-west-1:
      AZs: 2
      ImageId: ami-0d382e80be7ffdae5
    us-west-2:
      AZs: 4
      ImageId: ami-03d5c68bab01f3496
Resources:
  Network:
    Type: AWS::CloudFormation::Stack
    Condition: CreateVPC
    DeletionPolicy: Delete
    Properties:
      Parameters:
        AZs:
          Fn::FindInMap:
          - RegionMap
          - Ref: AWS::Region
          - AZs
      Tags:
      - Key: valohai
        Value: '1'
      TemplateURL: https://s3.eu-west-1.amazonaws.com/valohai-cfn-templates-public/7ba8b1198a6675dd407082c7e783e22d.template
  S3Bucket:
    Type: AWS::CloudFormation::Stack
    DeletionPolicy: Retain
    Properties:
      Parameters:
        Suffix:
          Ref: Suffix
        ValohaiMasterRoleARN:
          Ref: ValohaiMasterRoleARN
      Tags:
      - Key: valohai
        Value: '1'
      TemplateURL: https://s3.eu-west-1.amazonaws.com/valohai-cfn-templates-public/2a6016301f94fbf839d7e2ad614f46a7.template
  WorkerSG:
    Type: AWS::CloudFormation::Stack
    Properties:
      Parameters:
        VPC:
          Fn::If:
          - CreateVPC
          - Fn::GetAtt:
            - Network
            - Outputs.VPC
          - Ref: VpcId
      Tags:
      - Key: valohai
        Value: '1'
      TemplateURL: https://s3.eu-west-1.amazonaws.com/valohai-cfn-templates-public/f649276dfe216d2df625686e8d4578fa.template
  WorkerQueue:
    Type: AWS::CloudFormation::Stack
    DeletionPolicy: Delete
    Properties:
      Parameters:
        ImageId:
          Fn::FindInMap:
          - RegionMap
          - Ref: AWS::Region
          - ImageId
        KeyPair:
          Ref: KeyPair
        QueueAddress:
          Ref: QueueAddress
        Subnet:
          Fn::If:
          - CreateVPC
          - Fn::GetAtt:
            - Network
            - Outputs.Subnet1
          - Ref: Subnet
        VPC:
          Fn::If:
          - CreateVPC
          - Fn::GetAtt:
            - Network
            - Outputs.VPC
          - Ref: VpcId
        WorkersSecurityGroup:
          Fn::GetAtt:
          - WorkerSG
          - Outputs.SecurityGroup
      Tags:
      - Key: valohai
        Value: '1'
      TemplateURL: https://s3.eu-west-1.amazonaws.com/valohai-cfn-templates-public/d6b53323d4b55028fd77d247bb188924.template
Outputs:
  KeyPair:
    Value:
      Ref: KeyPair
    Description: Key pair name
  PrivateIp:
    Value:
      Fn::GetAtt:
      - WorkerQueue
      - Outputs.PrivateIp
    Description: Worker Queue instance private IP address
  PublicIp:
    Value:
      Fn::GetAtt:
      - WorkerQueue
      - Outputs.PublicIp
    Description: Worker Queue instance public IP address
  Region:
    Value:
      Ref: AWS::Region
  ValohaiMasterRole:
    Value:
      Ref: ValohaiMasterRoleARN
    Description: ValohaiMasterRole ARN
  ValohaiWorkerSG:
    Value:
      Fn::GetAtt:
      - WorkerSG
      - Outputs.SecurityGroup
    Description: ValohaiWorkerSG
  VPC:
    Value:
      Fn::If:
      - CreateVPC
      - Fn::GetAtt:
        - Network
        - Outputs.VPC
      - Ref: VpcId
    Description: VPC ID
