Terraform| Running powershell script with multiple reboots

I am trying to run a powershell script within userdata which contains multiple functions which invokes reboot after every step. After first step when it reboots, it doesnt go to second step and stops there. The Ec2 is launched in private subnet.
the template is well handled in cloudformation, can you please suggest how it can be handled in terraform.

Cloudformation Code below:

“01_Command1”: {
“command”: {
“Fn::Sub”: “powershell.exe -ExecutionPolicy Bypass -Command “& Import-Module .\xxx.psd1; -DomainName {DomainName} -InstanceName {InstanceName}””
},
“cwd”: “[SCRIPT_BASE_LOCATION]\bootstrap”,
“waitAfterCompletion”: “forever”
},
“02_ChocolateyInstall”: {
“command”: {
“Fn::Sub”: “powershell.exe -ExecutionPolicy Bypass -Command “& Import-Module .\xxx.psd1; -AccountId '{AWS::AccountId}' -InstanceName {InstanceName} -DomainName ${DomainName}””
},
“cwd”: “[SCRIPT_BASE_LOCATION]\bootstrap”,
“waitAfterCompletion”: “forever”

…and so on

I am trying to use this with terraform as below in userdata but after domain join, it doesnt proceed further because EC2 reboots in step1:

resource “aws_instance” “admin_box” {
{…
user_data = <<EOF

New-Item C:\test Directory

net use \

copy \ Destination>

cd “c:\test”

import-module .<some powershell module>

…Same function sequence i.e. domain-join, install chocolatey, other applications but after domain join it doesnt move forward.

If I use persist=true as below:
persist true /persist after powershell script",
the Ec2 reboots continuously after step1

Any suggestions…?

Any response on above thread?