I am looking to spin up a Domain Controller in AWS using Terraform. I've tried passing all commands through userdata, but I just can't find a way to get the commands run after a reboot.
Here is my userdata:
workflow Rename-And-Continue {
Rename-Computer -NewName "HACKDC" -Force -Passthru
Restart-Computer -Wait
Install-WindowsFeature AD-Domain-Services, rsat-adds -IncludeAllSubFeature
Install-ADDSForest -DomainName hackdc -SafeModeAdministratorPassword (ConvertTo-SecureString "SOMEPASSWORD" -AsPlainText -Force) -DomainMode Win2012R2 -DomainNetbiosName HACKDC -ForestMode Win2012R2 -Confirm:$false -Force
Restart-Service NetLogon -EA 0
Get-Service -Name ADWS; while($s.Status -ne "Running") {Start-Service ADWS; Start-Sleep 3};
}
$AtStartup = New-JobTrigger -AtStartup
Register-ScheduledJob -Name testWorkflow -Trigger $AtStartup -ScriptBlock {Import-Module PSWorkflow; Get-Job testWorkflow -State Suspended | Resume-Job};
Rename-And-Continue -AsJob -JobName testWorkflow
The main question here is what can be done to ensure that the workflow properly runs, so that I can set up the environment even if multiple restarts are required (yes I know the above isn't every step for properly configuring a DC, just a snippet)