I'm trying to use Terraform to create a Windows 10 VM and use the "provisioner" feature to push to and execute configuration scripts on the new VM. This seems to be working fine as I've got winrm properly configured and the provisioner is connecting as the newly created local admin account. This is a pretty extensive configuration and takes quite a while to run (about 30 minutes for the entire process from start to finish). The last step in the script is to run Sysprep to generalize the VM so that it can be used to create an Azure managed Image (from which we'll create VMs for the actual required work). It seems that all the configuration steps are successfully executing, but Terraform is exiting with an HTTP 401 error:
Error: Error applying plan: 1 error(s) occurred: * azurerm_virtual_machine.newimage: error executing "C:/Temp/terraform_467018566.cmd": http response error: 401 - invalid content type
From what I can tell, it did all work, so I'm not sure what's triggering the exit status. Could it be that because the VM is shutting down after running Sysprep, Terraform (or maybe winrm) is thinking something went wrong? This is the last command in the script which remote-exec is running:
%WINDIR%\system32\sysprep\sysprep.exe /generalize /shutdown /oobe