templates/ad-1.template.yaml [477:681]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            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'
          QSS3BucketRegion:
            default: 'us-east-1'
            description:
              'The AWS Region where the Quick Start S3 bucket (QSS3BucketName) is hosted. When using your own bucket, you must specify this value'
            type: 'String'
          QSS3KeyPrefix:
            default: 'quickstart-microsoft-activedirectory/'
            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'
          URLSuffix:
            default: 'amazonaws.com'
            description: 'AWS URL suffix'
            type: 'String'
        mainSteps:
          - name: dcsInstanceIds
            action: aws:executeAwsApi
            onFailure: step:signalfailure
            inputs:
              Service: ec2
              Api: DescribeInstances
              Filters:
                - Name: tag:Name
                  Values: ['{{ADServer1NetBIOSName}}', '{{ADServer2NetBIOSName}}']
                - Name: tag:aws:cloudformation:stack-name
                  Values: ['{{StackName}}']
                - Name: instance-state-name
                  Values: ['running']
            outputs:
              - Name: InstanceIds
                Selector: $.Reservations..Instances..InstanceId
                Type: StringList
            nextStep: dc1InstanceId
          - name: dc1InstanceId
            action: aws:executeAwsApi
            onFailure: step:signalfailure
            inputs:
              Service: ec2
              Api: DescribeInstances
              Filters:
                - Name: tag:Name
                  Values: ['{{ADServer1NetBIOSName}}']
                - Name: tag:aws:cloudformation:stack-name
                  Values: ['{{StackName}}']
                - Name: instance-state-name
                  Values: ['running']
            outputs:
              - Name: InstanceId
                Selector: $.Reservations[0].Instances[0].InstanceId
                Type: String
            nextStep: dc2InstanceId
          - name: dc2InstanceId
            action: aws:executeAwsApi
            onFailure: step:signalfailure
            inputs:
              Service: ec2
              Api: DescribeInstances
              Filters:
                - Name: tag:Name
                  Values: ['{{ADServer2NetBIOSName}}']
                - Name: tag:aws:cloudformation:stack-name
                  Values: ['{{StackName}}']
                - Name: instance-state-name
                  Values: ['running']
            outputs:
              - Name: InstanceId
                Selector: $.Reservations[0].Instances[0].InstanceId
                Type: String
            nextStep: intializeInstance
          - name: intializeInstance
            action: aws:runCommand
            inputs:
              DocumentName: AWS-RunPowerShellScript
              InstanceIds:
                - '{{dcsInstanceIds.InstanceIds}}'
              Parameters:
                commands: |-
                  [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

                  $S3BucketName = '{{QSS3BucketName}}'
                  $S3KeyPrefix = '{{QSS3KeyPrefix}}'
                  $S3BucketRegion = '{{QSS3BucketRegion}}'

                  $CustomModules = @(
                      'Module-AD.psd1',
                      'Module-AD.psm1'
                  )

                  $Modules = @(
                      @{
                          Name = 'NetworkingDsc'
                          Version = '8.2.0'
                      },
                      @{
                          Name = 'ActiveDirectoryDsc'
                          Version = '6.0.1'
                      },
                      @{
                          Name = 'ComputerManagementDsc'
                          Version = '8.4.0'
                      },
                      @{
                          Name = 'DnsServerDsc'
                          Version = '3.0.0'
                      }
                  )

                  Write-Output 'Creating AWSQuickstart Directory'
                  Try {
                      $Null = New-Item -Path 'C:\AWSQuickstart\Module-AD' -ItemType 'Directory' -ErrorAction Stop
                  } Catch [System.Exception] {
                      Write-Output "Failed to create AWSQuickstart directory $_"
                      Exit 1
                  }

                  $S3KeyPrefix = $S3KeyPrefix.Substring(0,$S3KeyPrefix.Length -1)
                  Write-Output 'Downloading AD PowerShell Module'
                  Foreach ($CustomModule in $CustomModules) {
                      Try {
                          $Null = Read-S3Object -BucketName $S3BucketName -Key "$($S3KeyPrefix)/scripts/Modules/Module-AD/$CustomModule" -File "C:\AWSQuickstart\Module-AD\$CustomModule" -Region $S3BucketRegion
                      } Catch [System.Exception] {
                          Write-Output "Failed to read and download $CustomModule.Name from S3 $_"
                          Exit 1
                      }
                  }

                  Write-Output 'Installing NuGet Package Provider'
                  Try {
                      $Null = Install-PackageProvider -Name 'NuGet' -MinimumVersion '2.8.5' -Force -ErrorAction Stop
                  } Catch [System.Exception] {
                      Write-Output "Failed to install NuGet Package Provider $_"
                      Exit 1
                  }

                  Write-Output 'Setting PSGallery Respository to trusted'
                  Try {
                      Set-PSRepository -Name 'PSGallery' -InstallationPolicy 'Trusted' -ErrorAction Stop
                  } Catch [System.Exception] {
                      Write-Output "Failed to set PSGallery Respository to trusted $_"
                      Exit 1
                  }

                  Write-Output 'Installing the needed Powershell DSC modules for this Quick Start'
                  Foreach ($Module in $Modules) {
                      Try {
                          Install-Module -Name $Module.Name -RequiredVersion $Module.Version -ErrorAction Stop
                      } Catch [System.Exception] {
                          Write-Output "Failed to Import Modules $_"
                          Exit 1
                      }
                  } 
              CloudWatchOutputConfig:
                CloudWatchOutputEnabled: true
                CloudWatchLogGroupName: !Sub /aws/Quick_Start/${AWS::StackName}
            nextStep: configureInstance
          - name: configureInstance
            action: aws:runCommand
            inputs:
              DocumentName: AWS-RunPowerShellScript
              InstanceIds:
                - '{{dcsInstanceIds.InstanceIds}}'
              Parameters:
                commands: |-
                  Try {
                      Import-Module -Name 'C:\AWSQuickstart\Module-AD\Module-AD.psm1' -Force
                  } Catch [System.Exception] {
                      Write-Output "Failed to import AD PS Module $_"
                      Exit 1
                  }
                  New-VolumeFromRawDisk
                  Invoke-PreConfig
                  Invoke-LcmConfig
              CloudWatchOutputConfig:
                CloudWatchOutputEnabled: true
                CloudWatchLogGroupName: !Sub /aws/Quick_Start/${AWS::StackName}
            nextStep: configureDc1Mof
          - name: configureDc1Mof
            action: aws:runCommand
            inputs:
              DocumentName: AWS-RunPowerShellScript
              InstanceIds:
                - '{{dc1InstanceId.InstanceId}}'
              Parameters:
                commands: |-
                  Try {
                      Import-Module -Name 'C:\AWSQuickstart\Module-AD\Module-AD.psm1' -Force
                  } Catch [System.Exception] {
                      Write-Output "Failed to import AD PS Module $_"
                      Exit 1
                  }
                  $EniConfig = Get-EniConfig
                  $DaSecret = Get-SecretInfo -Domain '{{DomainNetBIOSName}}' -SecretArn '{{ADAdminSecParamName}}'
                  $RmSecret = Get-SecretInfo -Domain '{{DomainNetBIOSName}}' -SecretArn '{{RestoreModeSecParamName}}'
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



templates/ad-2.template.yaml [665:869]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            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'
          QSS3BucketRegion:
            default: 'us-east-1'
            description:
              'The AWS Region where the Quick Start S3 bucket (QSS3BucketName) is hosted. When using your own bucket, you must specify this value'
            type: 'String'
          QSS3KeyPrefix:
            default: 'quickstart-microsoft-activedirectory/'
            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'
          URLSuffix:
            default: 'amazonaws.com'
            description: 'AWS URL suffix'
            type: 'String'
        mainSteps:
          - name: dcsInstanceIds
            action: aws:executeAwsApi
            onFailure: step:signalfailure
            inputs:
              Service: ec2
              Api: DescribeInstances
              Filters:
                - Name: tag:Name
                  Values: ['{{ADServer1NetBIOSName}}', '{{ADServer2NetBIOSName}}']
                - Name: tag:aws:cloudformation:stack-name
                  Values: ['{{StackName}}']
                - Name: instance-state-name
                  Values: ['running']
            outputs:
              - Name: InstanceIds
                Selector: $.Reservations..Instances..InstanceId
                Type: StringList
            nextStep: dc1InstanceId
          - name: dc1InstanceId
            action: aws:executeAwsApi
            onFailure: step:signalfailure
            inputs:
              Service: ec2
              Api: DescribeInstances
              Filters:
                - Name: tag:Name
                  Values: ['{{ADServer1NetBIOSName}}']
                - Name: tag:aws:cloudformation:stack-name
                  Values: ['{{StackName}}']
                - Name: instance-state-name
                  Values: ['running']
            outputs:
              - Name: InstanceId
                Selector: $.Reservations[0].Instances[0].InstanceId
                Type: String
            nextStep: dc2InstanceId
          - name: dc2InstanceId
            action: aws:executeAwsApi
            onFailure: step:signalfailure
            inputs:
              Service: ec2
              Api: DescribeInstances
              Filters:
                - Name: tag:Name
                  Values: ['{{ADServer2NetBIOSName}}']
                - Name: tag:aws:cloudformation:stack-name
                  Values: ['{{StackName}}']
                - Name: instance-state-name
                  Values: ['running']
            outputs:
              - Name: InstanceId
                Selector: $.Reservations[0].Instances[0].InstanceId
                Type: String
            nextStep: intializeInstance
          - name: intializeInstance
            action: aws:runCommand
            inputs:
              DocumentName: AWS-RunPowerShellScript
              InstanceIds:
                - '{{dcsInstanceIds.InstanceIds}}'
              Parameters:
                commands: |-
                  [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

                  $S3BucketName = '{{QSS3BucketName}}'
                  $S3KeyPrefix = '{{QSS3KeyPrefix}}'
                  $S3BucketRegion = '{{QSS3BucketRegion}}'

                  $CustomModules = @(
                      'Module-AD.psd1',
                      'Module-AD.psm1'
                  )

                  $Modules = @(
                      @{
                          Name = 'NetworkingDsc'
                          Version = '8.2.0'
                      },
                      @{
                          Name = 'ActiveDirectoryDsc'
                          Version = '6.0.1'
                      },
                      @{
                          Name = 'ComputerManagementDsc'
                          Version = '8.4.0'
                      },
                      @{
                          Name = 'DnsServerDsc'
                          Version = '3.0.0'
                      }
                  )

                  Write-Output 'Creating AWSQuickstart Directory'
                  Try {
                      $Null = New-Item -Path 'C:\AWSQuickstart\Module-AD' -ItemType 'Directory' -ErrorAction Stop
                  } Catch [System.Exception] {
                      Write-Output "Failed to create AWSQuickstart directory $_"
                      Exit 1
                  }

                  $S3KeyPrefix = $S3KeyPrefix.Substring(0,$S3KeyPrefix.Length -1)
                  Write-Output 'Downloading AD PowerShell Module'
                  Foreach ($CustomModule in $CustomModules) {
                      Try {
                          $Null = Read-S3Object -BucketName $S3BucketName -Key "$($S3KeyPrefix)/scripts/Modules/Module-AD/$CustomModule" -File "C:\AWSQuickstart\Module-AD\$CustomModule" -Region $S3BucketRegion
                      } Catch [System.Exception] {
                          Write-Output "Failed to read and download $CustomModule.Name from S3 $_"
                          Exit 1
                      }
                  }

                  Write-Output 'Installing NuGet Package Provider'
                  Try {
                      $Null = Install-PackageProvider -Name 'NuGet' -MinimumVersion '2.8.5' -Force -ErrorAction Stop
                  } Catch [System.Exception] {
                      Write-Output "Failed to install NuGet Package Provider $_"
                      Exit 1
                  }

                  Write-Output 'Setting PSGallery Respository to trusted'
                  Try {
                      Set-PSRepository -Name 'PSGallery' -InstallationPolicy 'Trusted' -ErrorAction Stop
                  } Catch [System.Exception] {
                      Write-Output "Failed to set PSGallery Respository to trusted $_"
                      Exit 1
                  }

                  Write-Output 'Installing the needed Powershell DSC modules for this Quick Start'
                  Foreach ($Module in $Modules) {
                      Try {
                          Install-Module -Name $Module.Name -RequiredVersion $Module.Version -ErrorAction Stop
                      } Catch [System.Exception] {
                          Write-Output "Failed to Import Modules $_"
                          Exit 1
                      }
                  } 
              CloudWatchOutputConfig:
                CloudWatchOutputEnabled: true
                CloudWatchLogGroupName: !Sub /aws/Quick_Start/${AWS::StackName}
            nextStep: configureInstance
          - name: configureInstance
            action: aws:runCommand
            inputs:
              DocumentName: AWS-RunPowerShellScript
              InstanceIds:
                - '{{dcsInstanceIds.InstanceIds}}'
              Parameters:
                commands: |-
                  Try {
                      Import-Module -Name 'C:\AWSQuickstart\Module-AD\Module-AD.psm1' -Force
                  } Catch [System.Exception] {
                      Write-Output "Failed to import AD PS Module $_"
                      Exit 1
                  }
                  New-VolumeFromRawDisk
                  Invoke-PreConfig
                  Invoke-LcmConfig
              CloudWatchOutputConfig:
                CloudWatchOutputEnabled: true
                CloudWatchLogGroupName: !Sub /aws/Quick_Start/${AWS::StackName}
            nextStep: configureDc1Mof
          - name: configureDc1Mof
            action: aws:runCommand
            inputs:
              DocumentName: AWS-RunPowerShellScript
              InstanceIds:
                - '{{dc1InstanceId.InstanceId}}'
              Parameters:
                commands: |-
                  Try {
                      Import-Module -Name 'C:\AWSQuickstart\Module-AD\Module-AD.psm1' -Force
                  } Catch [System.Exception] {
                      Write-Output "Failed to import AD PS Module $_"
                      Exit 1
                  }
                  $EniConfig = Get-EniConfig
                  $DaSecret = Get-SecretInfo -Domain '{{DomainNetBIOSName}}' -SecretArn '{{ADAdminSecParamName}}'
                  $RmSecret = Get-SecretInfo -Domain '{{DomainNetBIOSName}}' -SecretArn '{{RestoreModeSecParamName}}'
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



