Hi teams
I’m a engineer studing terraform.
I have a one problem.
I’m trying to deploy vm in azure.
resource "azurerm_virtual_machine_extension" "example" {
name = "custom-script-extension"
virtual_machine_id = local.vm_id.id
publisher = "Microsoft.Compute"
type = "CustomScriptExtension"
type_handler_version = "1.10"
settings = <<SETTINGS
{
"fileUris": ["storageaccount file uri"],
"commandToExecute": "powershell -ExecutionPolicy Unrestricted -File windows.ps1"
}
SETTINGS
protected_settings = <<PROTECTED_SETTINGS
{
"storageAccountName": <"storage account name">,
"storageAccountKey": <"storage account key">
}
PROTECTED_SETTINGS
}
Using the resource block above, an Azure Window vm is created and a custom powerhell script in the storage account is applied, but extension is not applied and extension is not executed after a long time, so how do I solve it?
Below is custom powershell script code
# Firewall & Windows Update Disable
Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False
Stop-Service -Name wuauserv -Force
Set-Service -Name wuauserv -StartupType Disabled
# WinRM Setting
Start-Process "C:\windows\system32\winrm.cmd" "qc /q"
Start-Sleep -Seconds 10
Start-Process "C:\windows\system32\winrm.cmd" "set winrm/config/service @{AllowUnencrypted=`"true`"}"
Start-Sleep -Seconds 10
Start-Process "C:\windows\system32\winrm.cmd" "set winrm/config/service/auth @{Basic=`"true`"}"
# Account Add
Start-Process "C:\Windows\System32\net.exe" "user test QWERasdf123!! /ADD"
Start-Process "C:\Windows\System32\wbem\WMIC.exe" "USERACCOUNT WHERE Name='test' SET PasswordExpires=FALSE"
Start-Process "C:\Windows\System32\net.exe" "localgroup administrators test /add"
# Create Folder
if (-not(Get-Item -Path c:\temp)) {
New-Item -Path C:\ -Name Temp -ItemType Directory
}
write-host "TEST" | out-file c:\temp\test.txt
Install-Module -Name Az -Repository PSGallery -Force