Problem
When using the azurerm_virtual_machine_scale_set resource, Terraform may crash with an unexpected EOF error.
!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!! * module.mymodulename.azurerm_virtual_machine_scale_set.main: 1 error occurred: * module.mymodulename.azurerm_virtual_machine_scale_set.main: azurerm_virtual_machine_scale_set.main: unexpected EOF panic: runtime error: invalid memory address or nil pointer dereference
Cause
This crash can occur when using the deprecated azurerm_virtual_machine_scale_set resource with newer Azure features that it does not support. Because the Azure API does not support these operations with the older resource, Terraform panics.
The azurerm_virtual_machine_scale_set resource is feature-frozen and has been superseded by two new resources: azurerm_linux_virtual_machine_scale_set and azurerm_windows_virtual_machine_scale_set.
As noted in the provider documentation:
The
azurerm_virtual_machine_scale_setresource has been superseded by theazurerm_linux_virtual_machine_scale_setandazurerm_windows_virtual_machine_scale_setresources. The existingazurerm_virtual_machine_scale_setresource will continue to be available throughout the 2.x releases however is in a feature-frozen state to maintain compatibility - new functionality will instead be added to theazurerm_linux_virtual_machine_scale_setandazurerm_windows_virtual_machine_scale_setresources.
Additional explanation from the provider engineering team is available in the related GitHub issue.
Solution
To resolve this issue, you must replace the deprecated azurerm_virtual_machine_scale_set resource in your configuration with either azurerm_linux_virtual_machine_scale_set or azurerm_windows_virtual_machine_scale_set, depending on your use case.
You can migrate your existing infrastructure to the new resource by using the terraform state mv command or by importing the existing scale set into the new resource definition.
Additional Information
- From AzureRM provider v2.86 onwards, the
azurerm_linux_virtual_machine_scale_setandazurerm_windows_virtual_machine_scale_setresources use only the Uniform Orchestration Mode. - For the Flexible Orchestration Mode, use the
azurerm_orchestrated_virtual_machine_scale_setresource instead. This resource also exclusively uses Flexible Orchestration Mode from v2.86 onwards. - For a detailed comparison of Virtual Machine Scale Set (VMSS) Orchestration Modes, refer to the official Azure documentation.
- If you are using an AzureRM 1.x provider release, you must upgrade to a newer version. The replacement scale set resources were released in v2.0.0. Refer to the AzureRM v2.0 upgrade guide for assistance.