CustomScriptExtension を使ってタイムゾーンを変更しても、既に実行中の Windows サービスには反映されなかった。反映するには Windows サービスの再起動が必要とはね。
commandToExec で powershell.exe を使い、-Command に複数コマンドを指定するハックで解決できた。PowerShell なら Restart-Service コマンドレットが使えるので、Windows サービスの再起動も簡単。
resource "azurerm_windows_virtual_machine_scale_set" "example" { # ... } resource "azurerm_virtual_machine_scale_set_extension" "custom_script" { name = "customscript-example" virtual_machine_scale_set_id = azurerm_windows_virtual_machine_scale_set.example.id publisher = "Microsoft.Compute" type = "CustomScriptExtension" type_handler_version = "1.10" settings = jsonencode({ "commandToExecute" = "powershell.exe -Command \"tzutil /s 'Tokyo Standard Time'; Restart-Service -Name Example\"" }) }