I am trying to have my terraform script run a powershell script on a VM when it’s provisioned. I know it’s trying to run but it’s erroring out. I believe it’s because the backslash in the file paths. I’ve tried escaping it, by making each single back slash into a double, but then it seems to be passed literally instead of as a simple single backslash, and that is failing too.
So how do I do it? anyone? thank you much
resource "azurerm_virtual_machine_extension" "dc" {
name = var.DomainControllerVMName
virtual_machine_id = azurerm_windows_virtual_machine.dc.id
publisher = "Microsoft.Azure.Extensions"
type = "CustomScript"
type_handler_version = "2.0"
settings = jsonencode({
commandToExecute = "$password = convertto-securestring RkP83Ls4S8wV -asplaintext -force;Install-windowsfeature -name AD-Domain-Services –IncludeManagementTool;Install-ADDSForest -CreateDnsDelegation:$false -DatabasePath C:\windows\NTDS -DomainMode WinThreshold -DomainName mdk.mydomain.com -DomainNetbiosName MDK -ForestMode WinThreshold -InstallDns:$true -SafeModeAdministratorPassword $password -LogPath C:\windows\NTDS -NoRebootOnCompletion:$false -SysvolPath C:\windows\SYSVOL -Force:$true -Confirm:$false"
})
tags = {
environment = "Production"
}
depends_on = [azurerm_windows_virtual_machine.dc]
}