I have a previous working terraform setup which creates a Windows VM in Azure and runs a bootstrap script via a custom script extension to install and configure SQL Server. This has been working fine for months, but suddenly (I assume after a specific Windows image update) it decides that installing the Failover-Clustering feature now requires a reboot, which breaks the script as there are steps that need to run after this feature is installed, i.e. running the PowerShell Get-Cluster command returns the following error:
ERROR: Unhandled exception caught: The term 'Get-Cluster' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
If I manually restart the VM and then run the command again, it is now recognised.
So, what I want to know is, is there any way to handle this other than to create an intermediate image with Failover-Clustering installed, and then use that as the base image? I know I can't add a second custom script extension (why Microsoft, just, why?) and I'm struggling to think of an easier way to do this.
Expected Install-WindowsFeature Failover-Clustering -IncludeAllSubFeature -IncludeManagementTools
not to require a reboot, like it use to.
The
Failover-Clustering
feature requires a mandatory reboot after installation on the computer. Unfortunately, this reboot requirement cannot be avoided.There is one possible workaround is to reboot the VM after completing the installation and run the remaining script with Terraform without manual reboot. The script includes a reboot step after installing the Failover-Clustering feature. You can use the
azurerm_virtual_machine_extension
resource in Terraform to add a custom script extension that reboots the VM after the feature is installed.Terraform Code
additional_script.ps1
Terraform apply
The code executed the Failover-Clustering feature installation and ran additional commands from the script.