submodules/quickstart-microsoft-sharepoint/submodules/quickstart-microsoft-sql/templates/AWSQuickstart-MSSQL.yml [1:1101]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
---
schemaVersion: "0.3"
description: Deploy MSSQL with SSM Automation
# Role that is utilized to perform the steps within the Automation Document.
assumeRole: "{{AutomationAssumeRole}}"
# Gathering parameters needed to configure DCs in the Quick Start
parameters:
  SQLServerVersion:
    default: "2017"
    description: "Version of SQL Server to install on Failover Cluster Nodes"
    type: "String"
  SQLLicenseProvided:
    default: "yes"
    description: "License SQL Server from AWS Marketplace"
    type: "String"
  WSFCNode1NetBIOSName:
    default: "WSFCNode1"
    description: "NetBIOS name of the first WSFC Node (up to 15 characters)"
    type: "String"
  WSFCNode1PrivateIP2:
    default: "10.0.0.101"
    description: "Secondary private IP for WSFC cluster on first WSFC Node"
    type: "String"
  WSFCNode1PrivateIP3:
    default: "10.0.0.102"
    description: "Third private IP for Availability Group Listener on first WSFC Node"
    type: "String"
  WSFCNode2NetBIOSName:
    default: "WSFCNode2"
    description: "NetBIOS name of the second WSFC Node (up to 15 characters)"
    type: "String"
  WSFCNode2PrivateIP2:
    default: "10.0.32.101"
    description: "Secondary private IP for WSFC cluster on first WSFC Node"
    type: "String"
  WSFCNode2PrivateIP3:
    default: "10.0.32.102"
    description: "Third private IP for Availability Group Listener on first WSFC Node"
    type: "String"
  WSFCNode3NetBIOSName:
    default: "WSFCNode3"
    description: "NetBIOS name of the third WSFC Node (up to 15 characters)"
    type: "String"
  WSFCNode3PrivateIP2:
    default: "10.0.64.101"
    description: "Fixed private IP for the first Active Directory server located in Availability Zone 1"
    type: "String"
  WSFCNode3PrivateIP3:
    default: "10.0.64.102"
    description: "Third private IP for Availability Group Listener on first WSFC Node"
    type: "String"
  WSFCFileServerNetBIOSName:
    default: "WSFCFileServer"
    description: "NetBIOS name of the WSFCFileServer (up to 15 characters)"
    type: "String"
  ClusterName:
    default: "WSFCCluster1"
    description: "NetBIOS name of the Cluster (up to 15 characters)"
    type: "String"
  AvailabiltyGroupName:
    default: "SQLAG1"
    description: "NetBIOS name of the Availablity Group (up to 15 characters)"
    type: "String"
  ThirdAZ: 
    default: "no"
    description: "Enable a 3 AZ deployment, the 3rd AZ can either be used just for the witness, or can be a full SQL cluster node."
    type: "String"
  DomainDNSName: 
    default: "example.com"
    description: "Fully qualified domain name (FQDN) of the forest root domain e.g. example.com"
    type: "String"
  DomainNetBIOSName: 
    default: "example"
    description: "NetBIOS name of the domain (up to 15 characters) for users of earlier versions of Windows e.g. EXAMPLE"
    type: "String"
  ManagedAD:
    default: "No"
    description: "Active Directory being Managed by AWS"
    type: "String"
  AdminSecrets:
    description: "AWS Secrets Parameter Name that has Password and User name for a domain administrator."
    type: "String"
  SQLSecrets:
    description: "AWS Secrets Parameter Name that has Password and User namer for the SQL Service Account."
    type: "String"
  QSS3BucketName:
    default: "aws-quickstart"
    description: "S3 bucket name for the Quick Start assets. Quick Start bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-)."
    type: "String"
  QSS3KeyPrefix:
    default: "quickstart-microsoft-sql/"
    description: "S3 key prefix for the Quick Start assets. Quick Start key prefix can include numbers, lowercase letters, uppercase letters, hyphens (-), and forward slash (/)."
    type: "String"
  StackName:
    default: ""
    description: "Stack Name Input for cfn resource signal"
    type: "String"
  AutomationAssumeRole:
    default: ""
    description: "(Optional) The ARN of the role that allows Automation to perform the actions on your behalf."
    type: "String"
mainSteps:
- name: "wsfcNode1InstanceId"
  action: aws:executeAwsApi
  onFailure: "step:signalfailure"
  inputs:
    Service: ec2
    Api: DescribeInstances
    Filters:  
    - Name: "tag:Name"
      Values: ["{{WSFCNode1NetBIOSName}}"]
    - Name: "instance-state-name"
      Values: [ "running" ]
  outputs:
  - Name: InstanceId
    Selector: "$.Reservations[0].Instances[0].InstanceId"
    Type: "String"
- name: "wsfcNode2InstanceId"
  action: aws:executeAwsApi
  onFailure: "step:signalfailure"
  inputs:
    Service: ec2
    Api: DescribeInstances
    Filters:  
    - Name: "tag:Name"
      Values: ["{{WSFCNode2NetBIOSName}}"]
    - Name: "instance-state-name"
      Values: [ "running" ]
  outputs:
  - Name: InstanceId
    Selector: "$.Reservations[0].Instances[0].InstanceId"
    Type: "String"
- name: InstanceIdBranch
  action: aws:branch
  inputs:
    Choices:
    - Or:
      - Variable: "{{ThirdAZ}}"
        StringEquals: "no"
      - Variable: "{{ThirdAZ}}"
        StringEquals: "witness"
      NextStep: wsfcFileServerInstanceId
    - Variable: "{{ThirdAZ}}"
      StringEquals: "full"
      NextStep: wsfcNode3InstanceId
- name: "wsfcNode3InstanceId"
  action: aws:executeAwsApi
  onFailure: "step:signalfailure"
  inputs:
    Service: ec2
    Api: DescribeInstances
    Filters:  
    - Name: "tag:Name"
      Values: ["{{WSFCNode3NetBIOSName}}"]
    - Name: "instance-state-name"
      Values: [ "running" ]
  outputs:
  - Name: InstanceId
    Selector: "$.Reservations[0].Instances[0].InstanceId"
    Type: "String"
- name: "wsfcnInstanceIds"
  action: aws:executeAwsApi
  onFailure: "step:signalfailure"
  inputs:
    Service: ec2
    Api: DescribeInstances
    Filters:  
    - Name: "tag:Name"
      Values: [ "{{WSFCNode1NetBIOSName}}","{{WSFCNode2NetBIOSName}}", "{{WSFCNode3NetBIOSName}}"]
    - Name: "instance-state-name"
      Values: [ "running" ]
  outputs:
  - Name: InstanceIds
    Selector: "$.Reservations..Instances..InstanceId"
    Type: "StringList"
- name: "wsfcnInitializeDisk"
  action: "aws:runCommand"
  onFailure: "step:signalfailure" 
  inputs:
    DocumentName: AWS-RunPowerShellScript
    InstanceIds: 
      - "{{wsfcnInstanceIds.InstanceIds}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
    Parameters:
      commands: 
        - |
           C:\ProgramData\Amazon\EC2-Windows\Launch\Scripts\InitializeDisks.ps1
- name: "wsfcnInstallDscModules"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
    - "{{wsfcnInstanceIds.InstanceIds}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/install-sql-modules.ps1"}'
      commandLine: "./install-sql-modules.ps1"
- name: "wsfcnLCMConfig"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
    - "{{wsfcnInstanceIds.InstanceIds}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/LCM-Config.ps1"}'
      commandLine: "./LCM-Config.ps1"
- name: "wsfcnDomainJoin"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcnInstanceIds.InstanceIds}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/DomainJoin.ps1"}'
      commandLine: "./DomainJoin.ps1 -DomainNetBIOSName {{DomainNetBIOSName}} -DomainDNSName {{DomainDNSName}} -AdminSecret {{AdminSecrets}}"
- name: "wsfcnDomainConfig"
  action: aws:runCommand
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: AWS-RunPowerShellScript
    InstanceIds: 
      - "{{wsfcnInstanceIds.InstanceIds}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      commands: 
        - |     
           function DscStatusCheck () {
               $LCMState = (Get-DscLocalConfigurationManager).LCMState
               if ($LCMState -eq 'PendingConfiguration' -Or $LCMState -eq 'PendingReboot') {
                   'returning 3010, should continue after reboot'
                   exit 3010
               } else {
                 'Completed'
               }
           }
           
           Start-DscConfiguration 'C:\AWSQuickstart\DomainJoin' -Wait -Verbose -Force

           DscStatusCheck
- name: "Node1nMof"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  #nextStep: 
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcNode1InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/Node1Config.ps1"}'
      commandLine: "./Node1Config.ps1 -DomainNetBIOSName {{DomainNetBIOSName}} -DomainDNSName {{DomainDNSName}} -WSFCNode1PrivateIP2 {{WSFCNode1PrivateIP2}} -ClusterName {{ClusterName}} -AdminSecret {{AdminSecrets}} -SQLSecret {{SQLSecrets}}"
- name: "Node1nConfig"
  action: aws:runCommand
  onFailure: "step:signalfailure"
  nextStep: "Node2Mof"
  inputs:
    DocumentName: AWS-RunPowerShellScript
    InstanceIds: 
      - "{{wsfcNode1InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      commands: 
        - |     
           function DscStatusCheck () {
               $LCMState = (Get-DscLocalConfigurationManager).LCMState
               if ($LCMState -eq 'PendingConfiguration' -Or $LCMState -eq 'PendingReboot') {
                   'returning 3010, should continue after reboot'
                   exit 3010
               } else {
                 'Completed'
               }
           }
           
           Start-DscConfiguration 'C:\AWSQuickstart\WSFCNode1Config' -Wait -Verbose -Force

           DscStatusCheck
- name: "wsfcFileServerInstanceId"
  action: aws:executeAwsApi
  onFailure: "step:signalfailure"
  inputs:
    Service: ec2
    Api: DescribeInstances
    Filters:  
    - Name: "tag:Name"
      Values: ["{{WSFCFileServerNetBIOSName}}"]
    - Name: "instance-state-name"
      Values: [ "running" ]
  outputs:
  - Name: InstanceId
    Selector: "$.Reservations[0].Instances[0].InstanceId"
    Type: "String"
- name: "wsfcwInstanceIds"
  action: aws:executeAwsApi
  onFailure: "step:signalfailure"
  inputs:
    Service: ec2
    Api: DescribeInstances
    Filters:  
    - Name: "tag:Name"
      Values: [ "{{WSFCNode1NetBIOSName}}","{{WSFCNode2NetBIOSName}}", "{{WSFCFileServerNetBIOSName}}"]
    - Name: "instance-state-name"
      Values: [ "running" ]
  outputs:
  - Name: InstanceIds
    Selector: "$.Reservations..Instances..InstanceId"
    Type: "StringList"
- name: "wsfcnodewInitializeDisk"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: AWS-RunPowerShellScript
    InstanceIds: 
      - "{{wsfcwInstanceIds.InstanceIds}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      commands: 
        - |
           C:\ProgramData\Amazon\EC2-Windows\Launch\Scripts\InitializeDisks.ps1
- name: "wsfcwInstallDscModules"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
    - "{{wsfcwInstanceIds.InstanceIds}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/install-sql-modules.ps1"}'
      commandLine: "./install-sql-modules.ps1"
- name: "wsfcwLCMConfig"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
    - "{{wsfcwInstanceIds.InstanceIds}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/LCM-Config.ps1"}'
      commandLine: "./LCM-Config.ps1"
- name: "wsfcwDomainJoin"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcwInstanceIds.InstanceIds}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/DomainJoin.ps1"}'
      commandLine: "./DomainJoin.ps1 -DomainNetBIOSName {{DomainNetBIOSName}} -DomainDNSName {{DomainDNSName}} -AdminSecret {{AdminSecrets}}"
- name: "wsfcwDomainConfig"
  action: aws:runCommand
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: AWS-RunPowerShellScript
    InstanceIds: 
      - "{{wsfcwInstanceIds.InstanceIds}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      commands: 
        - |     
           function DscStatusCheck () {
               $LCMState = (Get-DscLocalConfigurationManager).LCMState
               if ($LCMState -eq 'PendingConfiguration' -Or $LCMState -eq 'PendingReboot') {
                   'returning 3010, should continue after reboot'
                   exit 3010
               } else {
                 'Completed'
               }
           }
           
           Start-DscConfiguration 'C:\AWSQuickstart\DomainJoin' -Wait -Verbose -Force

           DscStatusCheck
- name: "wsfcFileServerConfig"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcFileServerInstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/WSFCFileShare.ps1"}'
      commandLine: "./WSFCFileShare.ps1"
- name: "Node1wMof"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  #nextStep: 
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcNode1InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/Node1Config.ps1"}'
      commandLine: "./Node1Config.ps1 -DomainNetBIOSName {{DomainNetBIOSName}} -DomainDNSName {{DomainDNSName}} -WSFCNode1PrivateIP2 {{WSFCNode1PrivateIP2}} -ClusterName {{ClusterName}} -AdminSecret {{AdminSecrets}} -SQLSecret {{SQLSecrets}} -FileServerNetBIOSName {{WSFCFileServerNetBIOSName}}"
- name: "Node1wConfig"
  action: aws:runCommand
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: AWS-RunPowerShellScript
    InstanceIds: 
      - "{{wsfcNode1InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      commands: 
        - |     
           function DscStatusCheck () {
               $LCMState = (Get-DscLocalConfigurationManager).LCMState
               if ($LCMState -eq 'PendingConfiguration' -Or $LCMState -eq 'PendingReboot') {
                   'returning 3010, should continue after reboot'
                   exit 3010
               } else {
                 'Completed'
               }
           }
           
           Start-DscConfiguration 'C:\AWSQuickstart\WSFCNode1Config' -Wait -Verbose -Force

           DscStatusCheck
- name: "Node2Mof"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcNode2InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/AdditionalNodeConfig.ps1"}'
      commandLine: "./AdditionalNodeConfig.ps1 -DomainNetBIOSName {{DomainNetBIOSName}} -WSFCNodePrivateIP2 {{WSFCNode2PrivateIP2}} -ClusterName {{ClusterName}} -AdminSecret {{AdminSecrets}} -SQLSecret {{SQLSecrets}}"
- name: "Node2Config"
  action: aws:runCommand
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: AWS-RunPowerShellScript
    InstanceIds: 
      - "{{wsfcNode2InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      commands: 
        - |     
           function DscStatusCheck () {
               $LCMState = (Get-DscLocalConfigurationManager).LCMState
               if ($LCMState -eq 'PendingConfiguration' -Or $LCMState -eq 'PendingReboot') {
                   'returning 3010, should continue after reboot'
                   exit 3010
               } else {
                 'Completed'
               }
           }
           
           Start-DscConfiguration 'C:\AWSQuickstart\AdditionalWSFCNode' -Wait -Verbose -Force

           DscStatusCheck
- name: 3AZFullBranch
  action: aws:branch
  inputs:
    Choices:
    - Or:
      - Variable: "{{ThirdAZ}}"
        StringEquals: "no"
      - Variable: "{{ThirdAZ}}"
        StringEquals: "witness"
      NextStep: SqlInstallBranch
    - Variable: "{{ThirdAZ}}"
      StringEquals: "full"
      NextStep: Node3Mof
- name: "Node3Mof"
  action: "aws:runCommand"
  onFailure: "step:signalfailure" 
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcNode3InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/AdditionalNodeConfig.ps1"}'
      commandLine: "./AdditionalNodeConfig.ps1 -DomainNetBIOSName {{DomainNetBIOSName}} -WSFCNodePrivateIP2 {{WSFCNode3PrivateIP2}} -ClusterName {{ClusterName}} -AdminSecret {{AdminSecrets}} -SQLSecret {{SQLSecrets}}"
- name: "Node3Config"
  action: aws:runCommand
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: AWS-RunPowerShellScript
    InstanceIds: 
      - "{{wsfcNode3InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      commands: 
        - |     
           function DscStatusCheck () {
               $LCMState = (Get-DscLocalConfigurationManager).LCMState
               if ($LCMState -eq 'PendingConfiguration' -Or $LCMState -eq 'PendingReboot') {
                   'returning 3010, should continue after reboot'
                   exit 3010
               } else {
                 'Completed'
               }
           }
           
           Start-DscConfiguration 'C:\AWSQuickstart\AdditionalWSFCNode' -Wait -Verbose -Force

           DscStatusCheck
- name: SqlInstallBranch
  action: aws:branch
  inputs:
    Choices:
    - Variable: "{{SQLLicenseProvided}}"
      StringEquals: "no"
      NextStep: NodesSqlInstallBranch
    - Variable: "{{SQLLicenseProvided}}"
      StringEquals: "yes"
      NextStep: NodesReconfigureSQLBranch
- name: NodesSqlInstallBranch
  action: aws:branch
  inputs:
    Choices:
    - Or:
      - Variable: "{{ThirdAZ}}"
        StringEquals: "no"
      - Variable: "{{ThirdAZ}}"
        StringEquals: "witness"
      NextStep: 2NodeDownloadSQL
    - Variable: "{{ThirdAZ}}"
      StringEquals: "full"
      NextStep: 3NodeDownloadSQL
- name: "2NodeDownloadSQL"
  action: "aws:runCommand"
  onFailure: "step:signalfailure" 
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcNode1InstanceId.InstanceId}}"
      - "{{wsfcNode2InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/DownloadSQLEE.ps1"}'
      commandLine: "./DownloadSQLEE.ps1 -SQLServerVersion {{SQLServerVersion}}"
- name: "2NodeSQLInstallMOF"
  action: "aws:runCommand"
  onFailure: "step:signalfailure" 
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcNode1InstanceId.InstanceId}}"
      - "{{wsfcNode2InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/Install-SQLEE.ps1"}'
      commandLine: "./Install-SQLEE.ps1 -DomainNetBIOSName {{DomainNetBIOSName}} -DomainDNSName {{DomainDNSName}} -AdminSecret {{AdminSecrets}} -SQLServerVersion {{SQLServerVersion}} -SQLSecret {{SQLSecrets}}"
- name: "2NodeSQLInstall"
  action: aws:runCommand
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: AWS-RunPowerShellScript
    InstanceIds: 
      - "{{wsfcNode1InstanceId.InstanceId}}"
      - "{{wsfcNode2InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      commands: 
        - |     
           function DscStatusCheck () {
               $LCMState = (Get-DscLocalConfigurationManager).LCMState
               if ($LCMState -eq 'PendingConfiguration' -Or $LCMState -eq 'PendingReboot') {
                   'returning 3010, should continue after reboot'
                   exit 3010
               } else {
                 'Completed'
               }
           }
           
           Start-DscConfiguration 'C:\AWSQuickstart\SQLInstall' -Wait -Verbose -Force

           DscStatusCheck
- name: "2NodeInstallSSMS"
  action: aws:runCommand
  onFailure: "step:signalfailure"
  nextStep: "CreateAGBranch"
  inputs:
    DocumentName: AWS-RunPowerShellScript
    InstanceIds: 
      - "{{wsfcNode1InstanceId.InstanceId}}"
      - "{{wsfcNode2InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      commands: 
        - |
           $ssms = "C:\SQLMedia\SSMS-Setup-ENU.exe"
           $ssmsargs = "/quiet /norestart"
           Start-Process $ssms $ssmsargs -Wait -ErrorAction Stop
- name: "3NodeDownloadSQL"
  action: "aws:runCommand"
  onFailure: "step:signalfailure" 
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcnInstanceIds.InstanceIds}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/DownloadSQLEE.ps1"}'
      commandLine: "./DownloadSQLEE.ps1 -SQLServerVersion {{SQLServerVersion}}"
- name: "3NodeSQLInstallMOF"
  action: "aws:runCommand"
  onFailure: "step:signalfailure" 
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcnInstanceIds.InstanceIds}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/Install-SQLEE.ps1"}'
      commandLine: "./Install-SQLEE.ps1 -DomainNetBIOSName {{DomainNetBIOSName}} -DomainDNSName {{DomainDNSName}} -AdminSecret {{AdminSecrets}} -SQLServerVersion {{SQLServerVersion}} -SQLSecret {{SQLSecrets}}"
- name: "3NodeSQLInstall"
  action: aws:runCommand
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: AWS-RunPowerShellScript
    InstanceIds: 
      - "{{wsfcnInstanceIds.InstanceIds}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      commands: 
        - |     
           function DscStatusCheck () {
               $LCMState = (Get-DscLocalConfigurationManager).LCMState
               if ($LCMState -eq 'PendingConfiguration' -Or $LCMState -eq 'PendingReboot') {
                   'returning 3010, should continue after reboot'
                   exit 3010
               } else {
                 'Completed'
               }
           }
           
           Start-DscConfiguration 'C:\AWSQuickstart\SQLInstall' -Wait -Verbose -Force

           DscStatusCheck
- name: "3NodeInstallSSMS"
  action: aws:runCommand
  onFailure: "step:signalfailure"
  nextStep: "CreateAGBranch"
  inputs:
    DocumentName: AWS-RunPowerShellScript
    InstanceIds: 
      - "{{wsfcnInstanceIds.InstanceIds}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      commands: 
        - |
           $ssms = "C:\sqlinstall\SSMS-Setup-ENU.exe"
           $ssmsargs = "/quiet /norestart"
           Start-Process $ssms $ssmsargs -Wait -ErrorAction Stop
- name: NodesReconfigureSQLBranch
  action: aws:branch
  inputs:
    Choices:
    - Or:
      - Variable: "{{ThirdAZ}}"
        StringEquals: "no"
      - Variable: "{{ThirdAZ}}"
        StringEquals: "witness"
      NextStep: 2NodeReconfigureSQL
    - Variable: "{{ThirdAZ}}"
      StringEquals: "full"
      NextStep: 3NodeReconfigureSQL
- name: "2NodeReconfigureSQL"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  nextStep: "CreateAGBranch" 
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcNode1InstanceId.InstanceId}}"
      - "{{wsfcNode2InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/Reconfigure-SQL-DSC.ps1"}'
      commandLine: "./Reconfigure-SQL-DSC.ps1 -DomainNetBIOSName {{DomainNetBIOSName}} -AdminSecret {{AdminSecrets}} -SQLSecret {{SQLSecrets}}"
- name: "3NodeReconfigureSQL"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  nextStep: "CreateAGBranch" 
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcnInstanceIds.InstanceIds}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/Reconfigure-SQL-DSC.ps1"}'
      commandLine: "./Reconfigure-SQL-DSC.ps1 -DomainNetBIOSName {{DomainNetBIOSName}} -AdminSecret {{AdminSecrets}} -SQLSecret {{SQLSecrets}}"
- name: CreateAGBranch
  action: aws:branch
  inputs:
    Choices:
    - And:
      - Not:
          Variable: "{{ManagedAD}}"
          StringEquals: "yes"
      - Not:
          Variable: "{{ThirdAZ}}"
          StringEquals: "full"
      NextStep: 2NodeNoMadPrimaryCreateAG
    - And:
      - Variable: "{{ManagedAD}}"
        StringEquals: "yes"
      - Not:
          Variable: "{{ThirdAZ}}"
          StringEquals: "full"
      NextStep: 2NodeMadPrimaryCreateAG
    - And:
      - Not:
          Variable: "{{ManagedAD}}"
          StringEquals: "yes"
      - Variable: "{{ThirdAZ}}"
        StringEquals: "full"
      NextStep: 3NodeNoMadPrimaryCreateAG
    - And:
      - Variable: "{{ManagedAD}}"
        StringEquals: "yes"
      - Variable: "{{ThirdAZ}}"
        StringEquals: "full"
      NextStep: 3NodeMadPrimaryCreateAG
- name: "2NodeNoMadPrimaryCreateAG"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcNode1InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/CreateAGNode1.ps1"}'
      commandLine: "./CreateAGNode1.ps1 -DomainNetBIOSName {{DomainNetBIOSName}} -DomainDNSName {{DomainDNSName}} -AdminSecret {{AdminSecrets}} -SQLSecret {{SQLSecrets}} -ClusterName {{ClusterName}} -AvailabiltyGroupName {{AvailabiltyGroupName}} -WSFCNode1NetBIOSName {{WSFCNode1NetBIOSName}} -WSFCNode2NetBIOSName {{WSFCNode2NetBIOSName}} -AGListener1PrivateIP1 {{WSFCNode1PrivateIP3}} -AGListener1PrivateIP2 {{WSFCNode2PrivateIP3}}"
- name: "2NodeNoMadPrimaryCreateAGConfig"
  action: aws:runCommand
  onFailure: "step:signalfailure"
  nextStep: "AdditionalCreateAGBranch"
  inputs:
    DocumentName: AWS-RunPowerShellScript
    InstanceIds: 
      - "{{wsfcNode1InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      commands: 
        - |     
           function DscStatusCheck () {
               $LCMState = (Get-DscLocalConfigurationManager).LCMState
               if ($LCMState -eq 'PendingConfiguration' -Or $LCMState -eq 'PendingReboot') {
                   'returning 3010, should continue after reboot'
                   exit 3010
               } else {
                 'Completed'
               }
           }
           
           Start-DscConfiguration 'C:\AWSQuickstart\AddAG' -Wait -Verbose -Force

           DscStatusCheck
- name: "2NodeMadPrimaryCreateAG"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcNode1InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/CreateAGNode1.ps1"}'
      commandLine: "./CreateAGNode1.ps1 -DomainNetBIOSName {{DomainNetBIOSName}} -DomainDNSName {{DomainDNSName}} -AdminSecret {{AdminSecrets}} -SQLSecret {{SQLSecrets}} -ClusterName {{ClusterName}} -AvailabiltyGroupName {{AvailabiltyGroupName}} -WSFCNode1NetBIOSName {{WSFCNode1NetBIOSName}} -WSFCNode2NetBIOSName {{WSFCNode2NetBIOSName}} -AGListener1PrivateIP1 {{WSFCNode1PrivateIP3}} -AGListener1PrivateIP2 {{WSFCNode2PrivateIP3}} -ManagedAD 'Yes'"
- name: "2NodeMadPrimaryCreateAGConfig"
  action: aws:runCommand
  onFailure: "step:signalfailure"
  nextStep: "AdditionalCreateAGBranch"
  inputs:
    DocumentName: AWS-RunPowerShellScript
    InstanceIds: 
      - "{{wsfcNode1InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      commands: 
        - |     
           function DscStatusCheck () {
               $LCMState = (Get-DscLocalConfigurationManager).LCMState
               if ($LCMState -eq 'PendingConfiguration' -Or $LCMState -eq 'PendingReboot') {
                   'returning 3010, should continue after reboot'
                   exit 3010
               } else {
                 'Completed'
               }
           }
           
           Start-DscConfiguration 'C:\AWSQuickstart\AddAG' -Wait -Verbose -Force

           DscStatusCheck
- name: "3NodeNoMadPrimaryCreateAG"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcNode1InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/CreateAGNode1.ps1"}'
      commandLine: "./CreateAGNode1.ps1 -DomainNetBIOSName {{DomainNetBIOSName}} -DomainDNSName {{DomainDNSName}} -AdminSecret {{AdminSecrets}} -SQLSecret {{SQLSecrets}} -ClusterName {{ClusterName}} -AvailabiltyGroupName {{AvailabiltyGroupName}} -WSFCNode1NetBIOSName {{WSFCNode1NetBIOSName}} -WSFCNode2NetBIOSName {{WSFCNode2NetBIOSName}} -AGListener1PrivateIP1 {{WSFCNode1PrivateIP3}} -AGListener1PrivateIP2 {{WSFCNode2PrivateIP3}} -WSFCNode3NetBIOSName {{WSFCNode3NetBIOSName}} -AGListener1PrivateIP3 {{WSFCNode3PrivateIP3}}"
- name: "3NodeNoMadPrimaryCreateAGConfig"
  action: aws:runCommand
  onFailure: "step:signalfailure"
  nextStep: "AdditionalCreateAGBranch"
  inputs:
    DocumentName: AWS-RunPowerShellScript
    InstanceIds: 
      - "{{wsfcNode1InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      commands: 
        - |     
           function DscStatusCheck () {
               $LCMState = (Get-DscLocalConfigurationManager).LCMState
               if ($LCMState -eq 'PendingConfiguration' -Or $LCMState -eq 'PendingReboot') {
                   'returning 3010, should continue after reboot'
                   exit 3010
               } else {
                 'Completed'
               }
           }
           
           Start-DscConfiguration 'C:\AWSQuickstart\AddAG' -Wait -Verbose -Force

           DscStatusCheck
- name: "3NodeMadPrimaryCreateAG"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcNode1InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/CreateAGNode1.ps1"}'
      commandLine: "./CreateAGNode1.ps1 -DomainNetBIOSName {{DomainNetBIOSName}} -DomainDNSName {{DomainDNSName}} -AdminSecret {{AdminSecrets}} -SQLSecret {{SQLSecrets}} -ClusterName {{ClusterName}} -AvailabiltyGroupName {{AvailabiltyGroupName}} -WSFCNode1NetBIOSName {{WSFCNode1NetBIOSName}} -WSFCNode2NetBIOSName {{WSFCNode2NetBIOSName}} -AGListener1PrivateIP1 {{WSFCNode1PrivateIP3}} -AGListener1PrivateIP2 {{WSFCNode2PrivateIP3}} -WSFCNode3NetBIOSName {{WSFCNode3NetBIOSName}} -AGListener1PrivateIP3 {{WSFCNode3PrivateIP3}} -ManagedAD 'Yes'"
- name: "3NodeMadPrimaryCreateAGConfig"
  action: aws:runCommand
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: AWS-RunPowerShellScript
    InstanceIds: 
      - "{{wsfcNode1InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      commands: 
        - |     
           function DscStatusCheck () {
               $LCMState = (Get-DscLocalConfigurationManager).LCMState
               if ($LCMState -eq 'PendingConfiguration' -Or $LCMState -eq 'PendingReboot') {
                   'returning 3010, should continue after reboot'
                   exit 3010
               } else {
                 'Completed'
               }
           }
           
           Start-DscConfiguration 'C:\AWSQuickstart\AddAG' -Wait -Verbose -Force

           DscStatusCheck
- name: AdditionalCreateAGBranch
  action: aws:branch
  inputs:
    Choices:
    - Or:
      - Variable: "{{ThirdAZ}}"
        StringEquals: "no"
      - Variable: "{{ThirdAZ}}"
        StringEquals: "witness"
      NextStep: 2NodeAdditionalCreateAG
    - Variable: "{{ThirdAZ}}"
      StringEquals: "full"
      NextStep: 3NodeAdditionalCreateAG
- name: "2NodeAdditionalCreateAG"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcNode2InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/AdditionalNodeCreateAG.ps1"}'
      commandLine: "./AdditionalNodeCreateAG.ps1 -DomainNetBIOSName {{DomainNetBIOSName}} -AdminSecret {{AdminSecrets}} -SQLSecret {{SQLSecrets}} -ClusterName {{ClusterName}} -AvailabiltyGroupName {{AvailabiltyGroupName}} -PrimaryNetBIOSName {{WSFCNode1NetBIOSName}}"
- name: "2NodeAdditionalCreateAGConfig"
  action: aws:runCommand
  onFailure: "step:signalfailure"
  nextStep: "CFNSignalEnd"
  inputs:
    DocumentName: AWS-RunPowerShellScript
    InstanceIds: 
      - "{{wsfcNode2InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      commands: 
        - |     
           function DscStatusCheck () {
               $LCMState = (Get-DscLocalConfigurationManager).LCMState
               if ($LCMState -eq 'PendingConfiguration' -Or $LCMState -eq 'PendingReboot') {
                   'returning 3010, should continue after reboot'
                   exit 3010
               } else {
                 'Completed'
               }
           }
           
           Start-DscConfiguration 'C:\AWSQuickstart\AddAG' -Wait -Verbose -Force

           DscStatusCheck
- name: "3NodeAdditionalCreateAG"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcNode2InstanceId.InstanceId}}"
      - "{{wsfcNode3InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/AdditionalNodeCreateAG.ps1"}'
      commandLine: "./AdditionalNodeCreateAG.ps1 -DomainNetBIOSName {{DomainNetBIOSName}} -AdminSecret {{AdminSecrets}} -SQLSecret {{SQLSecrets}} -ClusterName {{ClusterName}} -AvailabiltyGroupName {{AvailabiltyGroupName}} -PrimaryNetBIOSName {{WSFCNode1NetBIOSName}}"
- name: "3NodeAdditionalCreateAGConfig"
  action: aws:runCommand
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: AWS-RunPowerShellScript
    InstanceIds: 
      - "{{wsfcNode2InstanceId.InstanceId}}"
      - "{{wsfcNode3InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      commands: 
        - |     
           function DscStatusCheck () {
               $LCMState = (Get-DscLocalConfigurationManager).LCMState
               if ($LCMState -eq 'PendingConfiguration' -Or $LCMState -eq 'PendingReboot') {
                   'returning 3010, should continue after reboot'
                   exit 3010
               } else {
                 'Completed'
               }
           }
           
           Start-DscConfiguration 'C:\AWSQuickstart\AddAG' -Wait -Verbose -Force

           DscStatusCheck
# Determines if CFN Needs to be Signaled or if Work flow should just end
- name: CFNSignalEnd
  action: aws:branch
  inputs:
    Choices:
    - NextStep: signalsuccess
      Not: 
        Variable: "{{StackName}}"
        StringEquals: ""
    - NextStep: sleepend
      Variable: "{{StackName}}"
      StringEquals: ""
# If all steps complete successfully signals CFN of Success
- name: "signalsuccess"
  action: "aws:executeAwsApi"
  isEnd: True
  inputs:
    Service: cloudformation
    Api: SignalResource
    LogicalResourceId: "SSMWaitCondition"
    StackName: "{{StackName}}"
    Status: SUCCESS
    UniqueId: "{{wsfcNode2InstanceId.InstanceId}}"
# If CFN Signl Not Needed this sleep ends work flow
- name: "sleepend"
  action: "aws:sleep"
  isEnd: True
  inputs:
    Duration: PT1S
# If any steps fails signals CFN of Failure
- name: "signalfailure"
  action: "aws:executeAwsApi"
  inputs:
    Service: cloudformation
    Api: SignalResource
    LogicalResourceId: "SSMWaitCondition"
    StackName: "{{StackName}}"
    Status: FAILURE
    UniqueId: "{{wsfcNode2InstanceId.InstanceId}}"
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



submodules/quickstart-microsoft-sql/templates/AWSQuickstart-MSSQL.yml [1:1101]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
---
schemaVersion: "0.3"
description: Deploy MSSQL with SSM Automation
# Role that is utilized to perform the steps within the Automation Document.
assumeRole: "{{AutomationAssumeRole}}"
# Gathering parameters needed to configure DCs in the Quick Start
parameters:
  SQLServerVersion:
    default: "2017"
    description: "Version of SQL Server to install on Failover Cluster Nodes"
    type: "String"
  SQLLicenseProvided:
    default: "yes"
    description: "License SQL Server from AWS Marketplace"
    type: "String"
  WSFCNode1NetBIOSName:
    default: "WSFCNode1"
    description: "NetBIOS name of the first WSFC Node (up to 15 characters)"
    type: "String"
  WSFCNode1PrivateIP2:
    default: "10.0.0.101"
    description: "Secondary private IP for WSFC cluster on first WSFC Node"
    type: "String"
  WSFCNode1PrivateIP3:
    default: "10.0.0.102"
    description: "Third private IP for Availability Group Listener on first WSFC Node"
    type: "String"
  WSFCNode2NetBIOSName:
    default: "WSFCNode2"
    description: "NetBIOS name of the second WSFC Node (up to 15 characters)"
    type: "String"
  WSFCNode2PrivateIP2:
    default: "10.0.32.101"
    description: "Secondary private IP for WSFC cluster on first WSFC Node"
    type: "String"
  WSFCNode2PrivateIP3:
    default: "10.0.32.102"
    description: "Third private IP for Availability Group Listener on first WSFC Node"
    type: "String"
  WSFCNode3NetBIOSName:
    default: "WSFCNode3"
    description: "NetBIOS name of the third WSFC Node (up to 15 characters)"
    type: "String"
  WSFCNode3PrivateIP2:
    default: "10.0.64.101"
    description: "Fixed private IP for the first Active Directory server located in Availability Zone 1"
    type: "String"
  WSFCNode3PrivateIP3:
    default: "10.0.64.102"
    description: "Third private IP for Availability Group Listener on first WSFC Node"
    type: "String"
  WSFCFileServerNetBIOSName:
    default: "WSFCFileServer"
    description: "NetBIOS name of the WSFCFileServer (up to 15 characters)"
    type: "String"
  ClusterName:
    default: "WSFCCluster1"
    description: "NetBIOS name of the Cluster (up to 15 characters)"
    type: "String"
  AvailabiltyGroupName:
    default: "SQLAG1"
    description: "NetBIOS name of the Availablity Group (up to 15 characters)"
    type: "String"
  ThirdAZ: 
    default: "no"
    description: "Enable a 3 AZ deployment, the 3rd AZ can either be used just for the witness, or can be a full SQL cluster node."
    type: "String"
  DomainDNSName: 
    default: "example.com"
    description: "Fully qualified domain name (FQDN) of the forest root domain e.g. example.com"
    type: "String"
  DomainNetBIOSName: 
    default: "example"
    description: "NetBIOS name of the domain (up to 15 characters) for users of earlier versions of Windows e.g. EXAMPLE"
    type: "String"
  ManagedAD:
    default: "No"
    description: "Active Directory being Managed by AWS"
    type: "String"
  AdminSecrets:
    description: "AWS Secrets Parameter Name that has Password and User name for a domain administrator."
    type: "String"
  SQLSecrets:
    description: "AWS Secrets Parameter Name that has Password and User namer for the SQL Service Account."
    type: "String"
  QSS3BucketName:
    default: "aws-quickstart"
    description: "S3 bucket name for the Quick Start assets. Quick Start bucket name can include numbers, lowercase letters, uppercase letters, and hyphens (-). It cannot start or end with a hyphen (-)."
    type: "String"
  QSS3KeyPrefix:
    default: "quickstart-microsoft-sql/"
    description: "S3 key prefix for the Quick Start assets. Quick Start key prefix can include numbers, lowercase letters, uppercase letters, hyphens (-), and forward slash (/)."
    type: "String"
  StackName:
    default: ""
    description: "Stack Name Input for cfn resource signal"
    type: "String"
  AutomationAssumeRole:
    default: ""
    description: "(Optional) The ARN of the role that allows Automation to perform the actions on your behalf."
    type: "String"
mainSteps:
- name: "wsfcNode1InstanceId"
  action: aws:executeAwsApi
  onFailure: "step:signalfailure"
  inputs:
    Service: ec2
    Api: DescribeInstances
    Filters:  
    - Name: "tag:Name"
      Values: ["{{WSFCNode1NetBIOSName}}"]
    - Name: "instance-state-name"
      Values: [ "running" ]
  outputs:
  - Name: InstanceId
    Selector: "$.Reservations[0].Instances[0].InstanceId"
    Type: "String"
- name: "wsfcNode2InstanceId"
  action: aws:executeAwsApi
  onFailure: "step:signalfailure"
  inputs:
    Service: ec2
    Api: DescribeInstances
    Filters:  
    - Name: "tag:Name"
      Values: ["{{WSFCNode2NetBIOSName}}"]
    - Name: "instance-state-name"
      Values: [ "running" ]
  outputs:
  - Name: InstanceId
    Selector: "$.Reservations[0].Instances[0].InstanceId"
    Type: "String"
- name: InstanceIdBranch
  action: aws:branch
  inputs:
    Choices:
    - Or:
      - Variable: "{{ThirdAZ}}"
        StringEquals: "no"
      - Variable: "{{ThirdAZ}}"
        StringEquals: "witness"
      NextStep: wsfcFileServerInstanceId
    - Variable: "{{ThirdAZ}}"
      StringEquals: "full"
      NextStep: wsfcNode3InstanceId
- name: "wsfcNode3InstanceId"
  action: aws:executeAwsApi
  onFailure: "step:signalfailure"
  inputs:
    Service: ec2
    Api: DescribeInstances
    Filters:  
    - Name: "tag:Name"
      Values: ["{{WSFCNode3NetBIOSName}}"]
    - Name: "instance-state-name"
      Values: [ "running" ]
  outputs:
  - Name: InstanceId
    Selector: "$.Reservations[0].Instances[0].InstanceId"
    Type: "String"
- name: "wsfcnInstanceIds"
  action: aws:executeAwsApi
  onFailure: "step:signalfailure"
  inputs:
    Service: ec2
    Api: DescribeInstances
    Filters:  
    - Name: "tag:Name"
      Values: [ "{{WSFCNode1NetBIOSName}}","{{WSFCNode2NetBIOSName}}", "{{WSFCNode3NetBIOSName}}"]
    - Name: "instance-state-name"
      Values: [ "running" ]
  outputs:
  - Name: InstanceIds
    Selector: "$.Reservations..Instances..InstanceId"
    Type: "StringList"
- name: "wsfcnInitializeDisk"
  action: "aws:runCommand"
  onFailure: "step:signalfailure" 
  inputs:
    DocumentName: AWS-RunPowerShellScript
    InstanceIds: 
      - "{{wsfcnInstanceIds.InstanceIds}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
    Parameters:
      commands: 
        - |
           C:\ProgramData\Amazon\EC2-Windows\Launch\Scripts\InitializeDisks.ps1
- name: "wsfcnInstallDscModules"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
    - "{{wsfcnInstanceIds.InstanceIds}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/install-sql-modules.ps1"}'
      commandLine: "./install-sql-modules.ps1"
- name: "wsfcnLCMConfig"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
    - "{{wsfcnInstanceIds.InstanceIds}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/LCM-Config.ps1"}'
      commandLine: "./LCM-Config.ps1"
- name: "wsfcnDomainJoin"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcnInstanceIds.InstanceIds}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/DomainJoin.ps1"}'
      commandLine: "./DomainJoin.ps1 -DomainNetBIOSName {{DomainNetBIOSName}} -DomainDNSName {{DomainDNSName}} -AdminSecret {{AdminSecrets}}"
- name: "wsfcnDomainConfig"
  action: aws:runCommand
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: AWS-RunPowerShellScript
    InstanceIds: 
      - "{{wsfcnInstanceIds.InstanceIds}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      commands: 
        - |     
           function DscStatusCheck () {
               $LCMState = (Get-DscLocalConfigurationManager).LCMState
               if ($LCMState -eq 'PendingConfiguration' -Or $LCMState -eq 'PendingReboot') {
                   'returning 3010, should continue after reboot'
                   exit 3010
               } else {
                 'Completed'
               }
           }
           
           Start-DscConfiguration 'C:\AWSQuickstart\DomainJoin' -Wait -Verbose -Force

           DscStatusCheck
- name: "Node1nMof"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  #nextStep: 
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcNode1InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/Node1Config.ps1"}'
      commandLine: "./Node1Config.ps1 -DomainNetBIOSName {{DomainNetBIOSName}} -DomainDNSName {{DomainDNSName}} -WSFCNode1PrivateIP2 {{WSFCNode1PrivateIP2}} -ClusterName {{ClusterName}} -AdminSecret {{AdminSecrets}} -SQLSecret {{SQLSecrets}}"
- name: "Node1nConfig"
  action: aws:runCommand
  onFailure: "step:signalfailure"
  nextStep: "Node2Mof"
  inputs:
    DocumentName: AWS-RunPowerShellScript
    InstanceIds: 
      - "{{wsfcNode1InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      commands: 
        - |     
           function DscStatusCheck () {
               $LCMState = (Get-DscLocalConfigurationManager).LCMState
               if ($LCMState -eq 'PendingConfiguration' -Or $LCMState -eq 'PendingReboot') {
                   'returning 3010, should continue after reboot'
                   exit 3010
               } else {
                 'Completed'
               }
           }
           
           Start-DscConfiguration 'C:\AWSQuickstart\WSFCNode1Config' -Wait -Verbose -Force

           DscStatusCheck
- name: "wsfcFileServerInstanceId"
  action: aws:executeAwsApi
  onFailure: "step:signalfailure"
  inputs:
    Service: ec2
    Api: DescribeInstances
    Filters:  
    - Name: "tag:Name"
      Values: ["{{WSFCFileServerNetBIOSName}}"]
    - Name: "instance-state-name"
      Values: [ "running" ]
  outputs:
  - Name: InstanceId
    Selector: "$.Reservations[0].Instances[0].InstanceId"
    Type: "String"
- name: "wsfcwInstanceIds"
  action: aws:executeAwsApi
  onFailure: "step:signalfailure"
  inputs:
    Service: ec2
    Api: DescribeInstances
    Filters:  
    - Name: "tag:Name"
      Values: [ "{{WSFCNode1NetBIOSName}}","{{WSFCNode2NetBIOSName}}", "{{WSFCFileServerNetBIOSName}}"]
    - Name: "instance-state-name"
      Values: [ "running" ]
  outputs:
  - Name: InstanceIds
    Selector: "$.Reservations..Instances..InstanceId"
    Type: "StringList"
- name: "wsfcnodewInitializeDisk"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: AWS-RunPowerShellScript
    InstanceIds: 
      - "{{wsfcwInstanceIds.InstanceIds}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      commands: 
        - |
           C:\ProgramData\Amazon\EC2-Windows\Launch\Scripts\InitializeDisks.ps1
- name: "wsfcwInstallDscModules"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
    - "{{wsfcwInstanceIds.InstanceIds}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/install-sql-modules.ps1"}'
      commandLine: "./install-sql-modules.ps1"
- name: "wsfcwLCMConfig"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
    - "{{wsfcwInstanceIds.InstanceIds}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/LCM-Config.ps1"}'
      commandLine: "./LCM-Config.ps1"
- name: "wsfcwDomainJoin"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcwInstanceIds.InstanceIds}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/DomainJoin.ps1"}'
      commandLine: "./DomainJoin.ps1 -DomainNetBIOSName {{DomainNetBIOSName}} -DomainDNSName {{DomainDNSName}} -AdminSecret {{AdminSecrets}}"
- name: "wsfcwDomainConfig"
  action: aws:runCommand
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: AWS-RunPowerShellScript
    InstanceIds: 
      - "{{wsfcwInstanceIds.InstanceIds}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      commands: 
        - |     
           function DscStatusCheck () {
               $LCMState = (Get-DscLocalConfigurationManager).LCMState
               if ($LCMState -eq 'PendingConfiguration' -Or $LCMState -eq 'PendingReboot') {
                   'returning 3010, should continue after reboot'
                   exit 3010
               } else {
                 'Completed'
               }
           }
           
           Start-DscConfiguration 'C:\AWSQuickstart\DomainJoin' -Wait -Verbose -Force

           DscStatusCheck
- name: "wsfcFileServerConfig"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcFileServerInstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/WSFCFileShare.ps1"}'
      commandLine: "./WSFCFileShare.ps1"
- name: "Node1wMof"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  #nextStep: 
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcNode1InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/Node1Config.ps1"}'
      commandLine: "./Node1Config.ps1 -DomainNetBIOSName {{DomainNetBIOSName}} -DomainDNSName {{DomainDNSName}} -WSFCNode1PrivateIP2 {{WSFCNode1PrivateIP2}} -ClusterName {{ClusterName}} -AdminSecret {{AdminSecrets}} -SQLSecret {{SQLSecrets}} -FileServerNetBIOSName {{WSFCFileServerNetBIOSName}}"
- name: "Node1wConfig"
  action: aws:runCommand
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: AWS-RunPowerShellScript
    InstanceIds: 
      - "{{wsfcNode1InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      commands: 
        - |     
           function DscStatusCheck () {
               $LCMState = (Get-DscLocalConfigurationManager).LCMState
               if ($LCMState -eq 'PendingConfiguration' -Or $LCMState -eq 'PendingReboot') {
                   'returning 3010, should continue after reboot'
                   exit 3010
               } else {
                 'Completed'
               }
           }
           
           Start-DscConfiguration 'C:\AWSQuickstart\WSFCNode1Config' -Wait -Verbose -Force

           DscStatusCheck
- name: "Node2Mof"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcNode2InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/AdditionalNodeConfig.ps1"}'
      commandLine: "./AdditionalNodeConfig.ps1 -DomainNetBIOSName {{DomainNetBIOSName}} -WSFCNodePrivateIP2 {{WSFCNode2PrivateIP2}} -ClusterName {{ClusterName}} -AdminSecret {{AdminSecrets}} -SQLSecret {{SQLSecrets}}"
- name: "Node2Config"
  action: aws:runCommand
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: AWS-RunPowerShellScript
    InstanceIds: 
      - "{{wsfcNode2InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      commands: 
        - |     
           function DscStatusCheck () {
               $LCMState = (Get-DscLocalConfigurationManager).LCMState
               if ($LCMState -eq 'PendingConfiguration' -Or $LCMState -eq 'PendingReboot') {
                   'returning 3010, should continue after reboot'
                   exit 3010
               } else {
                 'Completed'
               }
           }
           
           Start-DscConfiguration 'C:\AWSQuickstart\AdditionalWSFCNode' -Wait -Verbose -Force

           DscStatusCheck
- name: 3AZFullBranch
  action: aws:branch
  inputs:
    Choices:
    - Or:
      - Variable: "{{ThirdAZ}}"
        StringEquals: "no"
      - Variable: "{{ThirdAZ}}"
        StringEquals: "witness"
      NextStep: SqlInstallBranch
    - Variable: "{{ThirdAZ}}"
      StringEquals: "full"
      NextStep: Node3Mof
- name: "Node3Mof"
  action: "aws:runCommand"
  onFailure: "step:signalfailure" 
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcNode3InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/AdditionalNodeConfig.ps1"}'
      commandLine: "./AdditionalNodeConfig.ps1 -DomainNetBIOSName {{DomainNetBIOSName}} -WSFCNodePrivateIP2 {{WSFCNode3PrivateIP2}} -ClusterName {{ClusterName}} -AdminSecret {{AdminSecrets}} -SQLSecret {{SQLSecrets}}"
- name: "Node3Config"
  action: aws:runCommand
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: AWS-RunPowerShellScript
    InstanceIds: 
      - "{{wsfcNode3InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      commands: 
        - |     
           function DscStatusCheck () {
               $LCMState = (Get-DscLocalConfigurationManager).LCMState
               if ($LCMState -eq 'PendingConfiguration' -Or $LCMState -eq 'PendingReboot') {
                   'returning 3010, should continue after reboot'
                   exit 3010
               } else {
                 'Completed'
               }
           }
           
           Start-DscConfiguration 'C:\AWSQuickstart\AdditionalWSFCNode' -Wait -Verbose -Force

           DscStatusCheck
- name: SqlInstallBranch
  action: aws:branch
  inputs:
    Choices:
    - Variable: "{{SQLLicenseProvided}}"
      StringEquals: "no"
      NextStep: NodesSqlInstallBranch
    - Variable: "{{SQLLicenseProvided}}"
      StringEquals: "yes"
      NextStep: NodesReconfigureSQLBranch
- name: NodesSqlInstallBranch
  action: aws:branch
  inputs:
    Choices:
    - Or:
      - Variable: "{{ThirdAZ}}"
        StringEquals: "no"
      - Variable: "{{ThirdAZ}}"
        StringEquals: "witness"
      NextStep: 2NodeDownloadSQL
    - Variable: "{{ThirdAZ}}"
      StringEquals: "full"
      NextStep: 3NodeDownloadSQL
- name: "2NodeDownloadSQL"
  action: "aws:runCommand"
  onFailure: "step:signalfailure" 
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcNode1InstanceId.InstanceId}}"
      - "{{wsfcNode2InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/DownloadSQLEE.ps1"}'
      commandLine: "./DownloadSQLEE.ps1 -SQLServerVersion {{SQLServerVersion}}"
- name: "2NodeSQLInstallMOF"
  action: "aws:runCommand"
  onFailure: "step:signalfailure" 
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcNode1InstanceId.InstanceId}}"
      - "{{wsfcNode2InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/Install-SQLEE.ps1"}'
      commandLine: "./Install-SQLEE.ps1 -DomainNetBIOSName {{DomainNetBIOSName}} -DomainDNSName {{DomainDNSName}} -AdminSecret {{AdminSecrets}} -SQLServerVersion {{SQLServerVersion}} -SQLSecret {{SQLSecrets}}"
- name: "2NodeSQLInstall"
  action: aws:runCommand
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: AWS-RunPowerShellScript
    InstanceIds: 
      - "{{wsfcNode1InstanceId.InstanceId}}"
      - "{{wsfcNode2InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      commands: 
        - |     
           function DscStatusCheck () {
               $LCMState = (Get-DscLocalConfigurationManager).LCMState
               if ($LCMState -eq 'PendingConfiguration' -Or $LCMState -eq 'PendingReboot') {
                   'returning 3010, should continue after reboot'
                   exit 3010
               } else {
                 'Completed'
               }
           }
           
           Start-DscConfiguration 'C:\AWSQuickstart\SQLInstall' -Wait -Verbose -Force

           DscStatusCheck
- name: "2NodeInstallSSMS"
  action: aws:runCommand
  onFailure: "step:signalfailure"
  nextStep: "CreateAGBranch"
  inputs:
    DocumentName: AWS-RunPowerShellScript
    InstanceIds: 
      - "{{wsfcNode1InstanceId.InstanceId}}"
      - "{{wsfcNode2InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      commands: 
        - |
           $ssms = "C:\SQLMedia\SSMS-Setup-ENU.exe"
           $ssmsargs = "/quiet /norestart"
           Start-Process $ssms $ssmsargs -Wait -ErrorAction Stop
- name: "3NodeDownloadSQL"
  action: "aws:runCommand"
  onFailure: "step:signalfailure" 
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcnInstanceIds.InstanceIds}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/DownloadSQLEE.ps1"}'
      commandLine: "./DownloadSQLEE.ps1 -SQLServerVersion {{SQLServerVersion}}"
- name: "3NodeSQLInstallMOF"
  action: "aws:runCommand"
  onFailure: "step:signalfailure" 
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcnInstanceIds.InstanceIds}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/Install-SQLEE.ps1"}'
      commandLine: "./Install-SQLEE.ps1 -DomainNetBIOSName {{DomainNetBIOSName}} -DomainDNSName {{DomainDNSName}} -AdminSecret {{AdminSecrets}} -SQLServerVersion {{SQLServerVersion}} -SQLSecret {{SQLSecrets}}"
- name: "3NodeSQLInstall"
  action: aws:runCommand
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: AWS-RunPowerShellScript
    InstanceIds: 
      - "{{wsfcnInstanceIds.InstanceIds}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      commands: 
        - |     
           function DscStatusCheck () {
               $LCMState = (Get-DscLocalConfigurationManager).LCMState
               if ($LCMState -eq 'PendingConfiguration' -Or $LCMState -eq 'PendingReboot') {
                   'returning 3010, should continue after reboot'
                   exit 3010
               } else {
                 'Completed'
               }
           }
           
           Start-DscConfiguration 'C:\AWSQuickstart\SQLInstall' -Wait -Verbose -Force

           DscStatusCheck
- name: "3NodeInstallSSMS"
  action: aws:runCommand
  onFailure: "step:signalfailure"
  nextStep: "CreateAGBranch"
  inputs:
    DocumentName: AWS-RunPowerShellScript
    InstanceIds: 
      - "{{wsfcnInstanceIds.InstanceIds}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      commands: 
        - |
           $ssms = "C:\sqlinstall\SSMS-Setup-ENU.exe"
           $ssmsargs = "/quiet /norestart"
           Start-Process $ssms $ssmsargs -Wait -ErrorAction Stop
- name: NodesReconfigureSQLBranch
  action: aws:branch
  inputs:
    Choices:
    - Or:
      - Variable: "{{ThirdAZ}}"
        StringEquals: "no"
      - Variable: "{{ThirdAZ}}"
        StringEquals: "witness"
      NextStep: 2NodeReconfigureSQL
    - Variable: "{{ThirdAZ}}"
      StringEquals: "full"
      NextStep: 3NodeReconfigureSQL
- name: "2NodeReconfigureSQL"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  nextStep: "CreateAGBranch" 
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcNode1InstanceId.InstanceId}}"
      - "{{wsfcNode2InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/Reconfigure-SQL-DSC.ps1"}'
      commandLine: "./Reconfigure-SQL-DSC.ps1 -DomainNetBIOSName {{DomainNetBIOSName}} -AdminSecret {{AdminSecrets}} -SQLSecret {{SQLSecrets}}"
- name: "3NodeReconfigureSQL"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  nextStep: "CreateAGBranch" 
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcnInstanceIds.InstanceIds}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/Reconfigure-SQL-DSC.ps1"}'
      commandLine: "./Reconfigure-SQL-DSC.ps1 -DomainNetBIOSName {{DomainNetBIOSName}} -AdminSecret {{AdminSecrets}} -SQLSecret {{SQLSecrets}}"
- name: CreateAGBranch
  action: aws:branch
  inputs:
    Choices:
    - And:
      - Not:
          Variable: "{{ManagedAD}}"
          StringEquals: "yes"
      - Not:
          Variable: "{{ThirdAZ}}"
          StringEquals: "full"
      NextStep: 2NodeNoMadPrimaryCreateAG
    - And:
      - Variable: "{{ManagedAD}}"
        StringEquals: "yes"
      - Not:
          Variable: "{{ThirdAZ}}"
          StringEquals: "full"
      NextStep: 2NodeMadPrimaryCreateAG
    - And:
      - Not:
          Variable: "{{ManagedAD}}"
          StringEquals: "yes"
      - Variable: "{{ThirdAZ}}"
        StringEquals: "full"
      NextStep: 3NodeNoMadPrimaryCreateAG
    - And:
      - Variable: "{{ManagedAD}}"
        StringEquals: "yes"
      - Variable: "{{ThirdAZ}}"
        StringEquals: "full"
      NextStep: 3NodeMadPrimaryCreateAG
- name: "2NodeNoMadPrimaryCreateAG"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcNode1InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/CreateAGNode1.ps1"}'
      commandLine: "./CreateAGNode1.ps1 -DomainNetBIOSName {{DomainNetBIOSName}} -DomainDNSName {{DomainDNSName}} -AdminSecret {{AdminSecrets}} -SQLSecret {{SQLSecrets}} -ClusterName {{ClusterName}} -AvailabiltyGroupName {{AvailabiltyGroupName}} -WSFCNode1NetBIOSName {{WSFCNode1NetBIOSName}} -WSFCNode2NetBIOSName {{WSFCNode2NetBIOSName}} -AGListener1PrivateIP1 {{WSFCNode1PrivateIP3}} -AGListener1PrivateIP2 {{WSFCNode2PrivateIP3}}"
- name: "2NodeNoMadPrimaryCreateAGConfig"
  action: aws:runCommand
  onFailure: "step:signalfailure"
  nextStep: "AdditionalCreateAGBranch"
  inputs:
    DocumentName: AWS-RunPowerShellScript
    InstanceIds: 
      - "{{wsfcNode1InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      commands: 
        - |     
           function DscStatusCheck () {
               $LCMState = (Get-DscLocalConfigurationManager).LCMState
               if ($LCMState -eq 'PendingConfiguration' -Or $LCMState -eq 'PendingReboot') {
                   'returning 3010, should continue after reboot'
                   exit 3010
               } else {
                 'Completed'
               }
           }
           
           Start-DscConfiguration 'C:\AWSQuickstart\AddAG' -Wait -Verbose -Force

           DscStatusCheck
- name: "2NodeMadPrimaryCreateAG"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcNode1InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/CreateAGNode1.ps1"}'
      commandLine: "./CreateAGNode1.ps1 -DomainNetBIOSName {{DomainNetBIOSName}} -DomainDNSName {{DomainDNSName}} -AdminSecret {{AdminSecrets}} -SQLSecret {{SQLSecrets}} -ClusterName {{ClusterName}} -AvailabiltyGroupName {{AvailabiltyGroupName}} -WSFCNode1NetBIOSName {{WSFCNode1NetBIOSName}} -WSFCNode2NetBIOSName {{WSFCNode2NetBIOSName}} -AGListener1PrivateIP1 {{WSFCNode1PrivateIP3}} -AGListener1PrivateIP2 {{WSFCNode2PrivateIP3}} -ManagedAD 'Yes'"
- name: "2NodeMadPrimaryCreateAGConfig"
  action: aws:runCommand
  onFailure: "step:signalfailure"
  nextStep: "AdditionalCreateAGBranch"
  inputs:
    DocumentName: AWS-RunPowerShellScript
    InstanceIds: 
      - "{{wsfcNode1InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      commands: 
        - |     
           function DscStatusCheck () {
               $LCMState = (Get-DscLocalConfigurationManager).LCMState
               if ($LCMState -eq 'PendingConfiguration' -Or $LCMState -eq 'PendingReboot') {
                   'returning 3010, should continue after reboot'
                   exit 3010
               } else {
                 'Completed'
               }
           }
           
           Start-DscConfiguration 'C:\AWSQuickstart\AddAG' -Wait -Verbose -Force

           DscStatusCheck
- name: "3NodeNoMadPrimaryCreateAG"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcNode1InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/CreateAGNode1.ps1"}'
      commandLine: "./CreateAGNode1.ps1 -DomainNetBIOSName {{DomainNetBIOSName}} -DomainDNSName {{DomainDNSName}} -AdminSecret {{AdminSecrets}} -SQLSecret {{SQLSecrets}} -ClusterName {{ClusterName}} -AvailabiltyGroupName {{AvailabiltyGroupName}} -WSFCNode1NetBIOSName {{WSFCNode1NetBIOSName}} -WSFCNode2NetBIOSName {{WSFCNode2NetBIOSName}} -AGListener1PrivateIP1 {{WSFCNode1PrivateIP3}} -AGListener1PrivateIP2 {{WSFCNode2PrivateIP3}} -WSFCNode3NetBIOSName {{WSFCNode3NetBIOSName}} -AGListener1PrivateIP3 {{WSFCNode3PrivateIP3}}"
- name: "3NodeNoMadPrimaryCreateAGConfig"
  action: aws:runCommand
  onFailure: "step:signalfailure"
  nextStep: "AdditionalCreateAGBranch"
  inputs:
    DocumentName: AWS-RunPowerShellScript
    InstanceIds: 
      - "{{wsfcNode1InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      commands: 
        - |     
           function DscStatusCheck () {
               $LCMState = (Get-DscLocalConfigurationManager).LCMState
               if ($LCMState -eq 'PendingConfiguration' -Or $LCMState -eq 'PendingReboot') {
                   'returning 3010, should continue after reboot'
                   exit 3010
               } else {
                 'Completed'
               }
           }
           
           Start-DscConfiguration 'C:\AWSQuickstart\AddAG' -Wait -Verbose -Force

           DscStatusCheck
- name: "3NodeMadPrimaryCreateAG"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcNode1InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/CreateAGNode1.ps1"}'
      commandLine: "./CreateAGNode1.ps1 -DomainNetBIOSName {{DomainNetBIOSName}} -DomainDNSName {{DomainDNSName}} -AdminSecret {{AdminSecrets}} -SQLSecret {{SQLSecrets}} -ClusterName {{ClusterName}} -AvailabiltyGroupName {{AvailabiltyGroupName}} -WSFCNode1NetBIOSName {{WSFCNode1NetBIOSName}} -WSFCNode2NetBIOSName {{WSFCNode2NetBIOSName}} -AGListener1PrivateIP1 {{WSFCNode1PrivateIP3}} -AGListener1PrivateIP2 {{WSFCNode2PrivateIP3}} -WSFCNode3NetBIOSName {{WSFCNode3NetBIOSName}} -AGListener1PrivateIP3 {{WSFCNode3PrivateIP3}} -ManagedAD 'Yes'"
- name: "3NodeMadPrimaryCreateAGConfig"
  action: aws:runCommand
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: AWS-RunPowerShellScript
    InstanceIds: 
      - "{{wsfcNode1InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      commands: 
        - |     
           function DscStatusCheck () {
               $LCMState = (Get-DscLocalConfigurationManager).LCMState
               if ($LCMState -eq 'PendingConfiguration' -Or $LCMState -eq 'PendingReboot') {
                   'returning 3010, should continue after reboot'
                   exit 3010
               } else {
                 'Completed'
               }
           }
           
           Start-DscConfiguration 'C:\AWSQuickstart\AddAG' -Wait -Verbose -Force

           DscStatusCheck
- name: AdditionalCreateAGBranch
  action: aws:branch
  inputs:
    Choices:
    - Or:
      - Variable: "{{ThirdAZ}}"
        StringEquals: "no"
      - Variable: "{{ThirdAZ}}"
        StringEquals: "witness"
      NextStep: 2NodeAdditionalCreateAG
    - Variable: "{{ThirdAZ}}"
      StringEquals: "full"
      NextStep: 3NodeAdditionalCreateAG
- name: "2NodeAdditionalCreateAG"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcNode2InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/AdditionalNodeCreateAG.ps1"}'
      commandLine: "./AdditionalNodeCreateAG.ps1 -DomainNetBIOSName {{DomainNetBIOSName}} -AdminSecret {{AdminSecrets}} -SQLSecret {{SQLSecrets}} -ClusterName {{ClusterName}} -AvailabiltyGroupName {{AvailabiltyGroupName}} -PrimaryNetBIOSName {{WSFCNode1NetBIOSName}}"
- name: "2NodeAdditionalCreateAGConfig"
  action: aws:runCommand
  onFailure: "step:signalfailure"
  nextStep: "CFNSignalEnd"
  inputs:
    DocumentName: AWS-RunPowerShellScript
    InstanceIds: 
      - "{{wsfcNode2InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      commands: 
        - |     
           function DscStatusCheck () {
               $LCMState = (Get-DscLocalConfigurationManager).LCMState
               if ($LCMState -eq 'PendingConfiguration' -Or $LCMState -eq 'PendingReboot') {
                   'returning 3010, should continue after reboot'
                   exit 3010
               } else {
                 'Completed'
               }
           }
           
           Start-DscConfiguration 'C:\AWSQuickstart\AddAG' -Wait -Verbose -Force

           DscStatusCheck
- name: "3NodeAdditionalCreateAG"
  action: "aws:runCommand"
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: "AWS-RunRemoteScript"
    InstanceIds:
      - "{{wsfcNode2InstanceId.InstanceId}}"
      - "{{wsfcNode3InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      sourceType: "S3"
      sourceInfo: '{"path": "https://s3.amazonaws.com/{{QSS3BucketName}}/{{QSS3KeyPrefix}}scripts/AdditionalNodeCreateAG.ps1"}'
      commandLine: "./AdditionalNodeCreateAG.ps1 -DomainNetBIOSName {{DomainNetBIOSName}} -AdminSecret {{AdminSecrets}} -SQLSecret {{SQLSecrets}} -ClusterName {{ClusterName}} -AvailabiltyGroupName {{AvailabiltyGroupName}} -PrimaryNetBIOSName {{WSFCNode1NetBIOSName}}"
- name: "3NodeAdditionalCreateAGConfig"
  action: aws:runCommand
  onFailure: "step:signalfailure"
  inputs:
    DocumentName: AWS-RunPowerShellScript
    InstanceIds: 
      - "{{wsfcNode2InstanceId.InstanceId}}"
      - "{{wsfcNode3InstanceId.InstanceId}}"
    CloudWatchOutputConfig:
      CloudWatchOutputEnabled: "true"
      CloudWatchLogGroupName: !Ref 'QuickStartLogs'
    Parameters:
      commands: 
        - |     
           function DscStatusCheck () {
               $LCMState = (Get-DscLocalConfigurationManager).LCMState
               if ($LCMState -eq 'PendingConfiguration' -Or $LCMState -eq 'PendingReboot') {
                   'returning 3010, should continue after reboot'
                   exit 3010
               } else {
                 'Completed'
               }
           }
           
           Start-DscConfiguration 'C:\AWSQuickstart\AddAG' -Wait -Verbose -Force

           DscStatusCheck
# Determines if CFN Needs to be Signaled or if Work flow should just end
- name: CFNSignalEnd
  action: aws:branch
  inputs:
    Choices:
    - NextStep: signalsuccess
      Not: 
        Variable: "{{StackName}}"
        StringEquals: ""
    - NextStep: sleepend
      Variable: "{{StackName}}"
      StringEquals: ""
# If all steps complete successfully signals CFN of Success
- name: "signalsuccess"
  action: "aws:executeAwsApi"
  isEnd: True
  inputs:
    Service: cloudformation
    Api: SignalResource
    LogicalResourceId: "SSMWaitCondition"
    StackName: "{{StackName}}"
    Status: SUCCESS
    UniqueId: "{{wsfcNode2InstanceId.InstanceId}}"
# If CFN Signl Not Needed this sleep ends work flow
- name: "sleepend"
  action: "aws:sleep"
  isEnd: True
  inputs:
    Duration: PT1S
# If any steps fails signals CFN of Failure
- name: "signalfailure"
  action: "aws:executeAwsApi"
  inputs:
    Service: cloudformation
    Api: SignalResource
    LogicalResourceId: "SSMWaitCondition"
    StackName: "{{StackName}}"
    Status: FAILURE
    UniqueId: "{{wsfcNode2InstanceId.InstanceId}}"
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



