AWSTemplateFormatVersion: 2010-09-09
Description: >-
  Master template to create the Migration Immersion Day workshop. Also, you are
  solely responsible for complying with the license terms for the software
  downloaded and installed by this template. By creating a stack from this
  template, you are agreeing to such terms.
Parameters:
  EEEventId:
    Description: Unique ID of this Event
    Type: String
  EETeamId:
    Description: Unique ID of this Team
    Type: String
  EEModuleId:
    Description: Unique ID of this module
    Type: String
  EEModuleVersion:
    Description: Version of this module
    Type: String
  EEMasterAccountId:
    Description: AWS Account Id of the Master account
    Type: String
  EETeamRoleArn:
    Description: ARN of the Team Role
    Type: String
  DomainName:
    Description: >-
      The fully qualified name for the source VPC, such as onpremsim.env. The
      name doesn't need to be publicly resolvable; it will resolve inside your
      VPC only.
    Type: String
    MinLength: '5'
    MaxLength: '16'
    Default: onpremsim.env
  AdminPassword:
    Description: The password for the Bastion Administrator
    Default: 't9Dz8W#k'
    NoEcho: 'true'
    Type: String
    MinLength: '8'
    MaxLength: '18'
    AllowedPattern: '^(?=[a-zA-Z0-9#@$?]{8,}$)(?=.*?[a-z])(?=.*?[A-Z])(?=.*?[0-9]).*'
    ConstraintDescription: must contain alphanumeric+special characters.
  RootPassword:
    Default: AWSmid21
    NoEcho: 'true'
    Description: >-
      SSH password for user 'user'. This user has sudo power. Use an
      alphanumeric password
    Type: String
    MinLength: '8'
    MaxLength: '12'
    AllowedPattern: '[a-zA-Z0-9]*'
    ConstraintDescription: must contain only alphanumeric characters.
  SourceS3Bucket:
    Description: S3 Bucket with CFN stack files
    Type: String
    Default: awsmigrationfactory
  SourceS3Path:
    Description: S3 Path with CFN stack files
    Type: String
    Default: workshop/mgn
  EC2ModelWindows:
    Description: Model of EC2 Servers in the source environment - Windows
    Type: String
    AllowedValues:
      - t3.nano
      - t3.micro
      - t3.small
      - t3.medium
    Default: t3.small
  EC2ModelLinux:
    Description: Model of EC2 Servers in the source environment - Linux
    Type: String
    AllowedValues:
      - t3.nano
      - t3.micro
      - t3.small
      - t3.medium
    Default: t3.small
  EC2ModelBastion:
    Description: Model of EC2 Servers in the source environment - Windows Bastion
    Type: String
    AllowedValues:
      - t3.micro
      - t3.small
      - t3.medium
    Default: t3.medium
  SourceCidrForRDP:
    Description: >-
      IP Cidr from which you are likely to RDP into the instances. You can add
      rules later by modifying the created security groups e.g. 54.32.98.160/32
    Type: String
    MinLength: '9'
    MaxLength: '18'
    Default: 0.0.0.0/0
    AllowedPattern: '^([0-9]+\.){3}[0-9]+\/[0-9]+$'
  LaunchBastion:
    Description: Launch Bastion Server
    Default: 'TRUE'
    Type: String
    AllowedValues:
      - 'TRUE'
      - 'FALSE'
  LaunchWordpress:
    Description: Launch Wordpress App
    Default: 'TRUE'
    Type: String
    AllowedValues:
      - 'TRUE'
      - 'FALSE'
  LaunchOFBiz:
    Description: Launch OFBiz App
    Default: 'TRUE'
    Type: String
    AllowedValues:
      - 'TRUE'
      - 'FALSE'
  LaunchWindows:
    Description: Launch Windows SVR
    Default: 'TRUE'
    Type: String
    AllowedValues:
      - 'TRUE'
      - 'FALSE'
  LaunchFactory:
    Description: Launch Migration Factory
    Default: 'TRUE'
    Type: String
    AllowedValues:
      - 'TRUE'
      - 'FALSE'
  Application:
    Type: String
    Description: Application name is used to name all AWS resources.
    Default: migration-factory
    AllowedPattern: "[-a-z0-9]*"
    ConstraintDescription: Application parameter must be all lower case characters
  Environment:
    Type: String
    Description: Environment name is used to name all AWS resources (.i.e dev, test, prod)
    Default: lab
    AllowedPattern: "[-a-z0-9]*"
    ConstraintDescription: Application parameter must be all lower case characters
Conditions:
  CreateBastion: !Equals
    - !Ref LaunchBastion
    - 'TRUE'
  CreateWordpress: !Equals
    - !Ref LaunchWordpress
    - 'TRUE'
  CreateOFBiz: !Equals
    - !Ref LaunchOFBiz
    - 'TRUE'
  CreateWindows: !Equals
    - !Ref LaunchWindows
    - 'TRUE'
  CreateFactory: !Equals
    - !Ref LaunchFactory
    - 'TRUE'
Resources:
  SOURCENETWORK:
    Type: 'AWS::CloudFormation::Stack'
    Properties:
      TemplateURL: !Join
        - ''
        - - 'https://'
          - !Ref SourceS3Bucket
          - .s3.amazonaws.com/
          - !Ref SourceS3Path
          - /SOURCE_NETWORK.yml
      Tags:
        - Key: Env
          Value: MID-SOURCE
        - Key: Stack
          Value: SOURCENETWORK
      Parameters:
        DomainName: !Ref DomainName
  SOURCEBASTION:
    Type: 'AWS::CloudFormation::Stack'
    Condition: CreateBastion
    Properties:
      TemplateURL: !Join
        - ''
        - - 'https://'
          - !Ref SourceS3Bucket
          - .s3.amazonaws.com/
          - !Ref SourceS3Path
          - /SOURCE_BASTION.yml
      Tags:
        - Key: Env
          Value: MID-SOURCE
        - Key: Stack
          Value: SOURCENETWORK
      Parameters:
        AdminPassword: !Ref AdminPassword
        bastionSize: !Ref EC2ModelBastion
        InstanceProfile: !GetAtt
          - FACTORY
          - Outputs.ExecutionServerInstanceProfile
        VPCCloud: !GetAtt
          - SOURCENETWORK
          - Outputs.VPCSource
        SubnetCloudPublic: !GetAtt
          - SOURCENETWORK
          - Outputs.SubnetSourcePublic
        SourceCidrForRDP: !Ref SourceCidrForRDP
  SOURCEWORDPRESS:
    Type: 'AWS::CloudFormation::Stack'
    Condition: CreateWordpress
    Properties:
      TemplateURL: !Join
        - ''
        - - 'https://'
          - !Ref SourceS3Bucket
          - .s3.amazonaws.com/
          - !Ref SourceS3Path
          - /SOURCE_WORDPRESS.yml
      Tags:
        - Key: Env
          Value: MID-SOURCE
        - Key: Stack
          Value: SOURCENETWORK
      Parameters:
        DomainName: !Ref DomainName
        OnPremSimVPC: !GetAtt
          - SOURCENETWORK
          - Outputs.VPCSource
        OnPremSimSubnet1: !GetAtt
          - SOURCENETWORK
          - Outputs.SubnetSourcePrivate
        WEBInstanceType: !Ref EC2ModelLinux
        DBPassword: !Ref RootPassword
        RootPassword: !Ref RootPassword
  SOURCEOFBIZ:
    Type: 'AWS::CloudFormation::Stack'
    Condition: CreateOFBiz
    Properties:
      TemplateURL: !Join
        - ''
        - - 'https://'
          - !Ref SourceS3Bucket
          - .s3.amazonaws.com/
          - !Ref SourceS3Path
          - /SOURCE_OFBiz.yml
      Tags:
        - Key: Env
          Value: MID-SOURCE
        - Key: Stack
          Value: SOURCENETWORK
      Parameters:
        DomainName: !Ref DomainName
        OnPremSimVPC: !GetAtt
          - SOURCENETWORK
          - Outputs.VPCSource
        OnPremSimSubnet1: !GetAtt
          - SOURCENETWORK
          - Outputs.SubnetSourcePrivate
        WEBInstanceType: !Ref EC2ModelLinux
        RootPassword: !Ref RootPassword
  SOURCEWINDOWS:
    Type: 'AWS::CloudFormation::Stack'
    Condition: CreateWindows
    Properties:
      TemplateURL: !Join
        - ''
        - - 'https://'
          - !Ref SourceS3Bucket
          - .s3.amazonaws.com/
          - !Ref SourceS3Path
          - /SOURCE_WINDOWS.yml
      Tags:
        - Key: Env
          Value: MID-SOURCE
        - Key: Stack
          Value: SOURCENETWORK
      Parameters:
        OnPremSimVPC: !GetAtt
          - SOURCENETWORK
          - Outputs.VPCSource
        OnPremSimSubnet1: !GetAtt
          - SOURCENETWORK
          - Outputs.SubnetSourcePrivate
        opWindowsSize: !Ref EC2ModelWindows
        AdminPassword: !Ref RootPassword
  TARGETACCT:
    Type: 'AWS::CloudFormation::Stack'
    Properties:
      TemplateURL: !Join
        - ''
        - - 'https://'
          - !Ref SourceS3Bucket
          - .s3.amazonaws.com/
          - !Ref SourceS3Path
          - /TARGET_ACCOUNT_Config.yml
      Tags:
        - Key: Env
          Value: MID-MGN-Config
        - Key: Stack
          Value: TargetAccountConfig
      Parameters:
        FactoryAWSAccountId: !Ref AWS::AccountId
  FACTORY:
    Type: 'AWS::CloudFormation::Stack'
    Condition: CreateFactory
    Properties:
      TemplateURL: !Join
        - ''
        - - 'https://'
          - !Ref SourceS3Bucket
          - .s3.amazonaws.com/
          - !Ref SourceS3Path
          - /aws-cloudendure-migration-factory-solution_lab.template
      Tags:
        - Key: Env
          Value: MID-SOURCE
        - Key: Stack
          Value: FACTORY
      Parameters:
        Application: !Ref Application
        Environment: !Ref Environment
  Tracker:
    Type: 'AWS::CloudFormation::Stack'
    Properties:
      TemplateURL: >-
        https://s3.amazonaws.com/ee-assets-prod-us-east-1/modules/migration-baseinfra/v4/TRACKER.yaml
      Tags:
        - Key: Env
          Value: MID-SOURCE
        - Key: Stack
          Value: MIDTrack
      Parameters:
        Source: EventEngineCEMF
Outputs:
  BastionRDP:
    Value: !GetAtt
      - SOURCEBASTION
      - Outputs.BastionRDP
  SubnetTargetPublic:
    Value: !GetAtt
      - SOURCENETWORK
      - Outputs.SubnetTargetPublic
  SubnetTargetPrivate:
    Value: !GetAtt
      - SOURCENETWORK
      - Outputs.SubnetTargetPrivate
  TargetSecurityGroup:
    Value: !GetAtt
      - SOURCENETWORK
      - Outputs.TargetSecurityGroup
  TargetSecurityGroupTest:
    Value: !GetAtt
      - SOURCENETWORK
      - Outputs.TargetSecurityGroupTest
  LoginAPI:
    Value: !GetAtt
      - FACTORY
      - Outputs.LoginAPI
  UserAPI:
    Value: !GetAtt
      - FACTORY
      - Outputs.UserAPI
  UserPoolId:
    Value: !GetAtt
      - FACTORY
      - Outputs.UserPoolId
  Region:
    Value: !GetAtt
      - FACTORY
      - Outputs.Region
  MigrationFactoryURL:
    Value: !GetAtt
      - FACTORY
      - Outputs.MigrationFactoryURL
  FactoryUserName:
    Value: !GetAtt
      - FACTORY
      - Outputs.FactoryUserName
  FactoryPassword:
    Value: !GetAtt
      - FACTORY
      - Outputs.FactoryPassword

