diff --git a/azurerm/internal/services/compute/tests/linux_virtual_machine_scale_set_other_resource_test.go b/azurerm/internal/services/compute/tests/linux_virtual_machine_scale_set_other_resource_test.go index dfb83bccb1ef..ba003fc2ba80 100644 --- a/azurerm/internal/services/compute/tests/linux_virtual_machine_scale_set_other_resource_test.go +++ b/azurerm/internal/services/compute/tests/linux_virtual_machine_scale_set_other_resource_test.go @@ -608,6 +608,25 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_otherVmExtensions(t *testing.T) { }) } +func TestAccAzureRMLinuxVirtualMachineScaleSet_otherVmExtensionsOnlySettings(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherVmExtensionsOnlySettings(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName)), + }, + // TODO - extension should be changed to extension.0.protected_settings when either binary testing is available or this feature is promoted from beta + data.ImportStep("admin_password", "extension"), + }, + }) +} + func TestAccAzureRMLinuxVirtualMachineScaleSet_otherVmExtensionsForceUpdateTag(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") @@ -2107,6 +2126,69 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { `, template, data.RandomInteger, enabled) } +func testAccAzureRMLinuxVirtualMachineScaleSet_otherVmExtensionsOnlySettings(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) + return fmt.Sprintf(` +%[1]s + +provider "azurerm" { + features {} +} + +resource "azurerm_linux_virtual_machine_scale_set" "test" { + name = "acctestvmss-%d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + sku = "Standard_F2" + instances = 1 + admin_username = "adminuser" + admin_password = "P@ssword1234!" + + disable_password_authentication = false + + source_image_reference { + publisher = "Canonical" + offer = "UbuntuServer" + sku = "16.04-LTS" + version = "latest" + } + + os_disk { + storage_account_type = "Standard_LRS" + caching = "ReadWrite" + } + + network_interface { + name = "example" + primary = true + + ip_configuration { + name = "internal" + primary = true + subnet_id = azurerm_subnet.test.id + } + } + + extension { + name = "CustomScript" + publisher = "Microsoft.Azure.Extensions" + type = "CustomScript" + type_handler_version = "2.0" + auto_upgrade_minor_version = true + + settings = jsonencode({ + "commandToExecute" = "echo $HOSTNAME" + }) + + } + + tags = { + accTest = "true" + } +} +`, template, data.RandomInteger) +} + func testAccAzureRMLinuxVirtualMachineScaleSet_otherVmExtensions(data acceptance.TestData) string { template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` diff --git a/azurerm/internal/services/compute/virtual_machine_scale_set.go b/azurerm/internal/services/compute/virtual_machine_scale_set.go index 1aa8d3a8d2b9..cd8dca6e33b3 100644 --- a/azurerm/internal/services/compute/virtual_machine_scale_set.go +++ b/azurerm/internal/services/compute/virtual_machine_scale_set.go @@ -1392,19 +1392,24 @@ func expandVirtualMachineScaleSetExtensions(input []interface{}) (*compute.Virtu extensionProps.ForceUpdateTag = utils.String(forceUpdateTag.(string)) } - settings, err := structure.ExpandJsonFromString(extensionRaw["settings"].(string)) - if err != nil { - return nil, fmt.Errorf("failed to parse JSON from `settings`: %+v", err) + settings, ok := extensionRaw["settings"].(string) + if ok && settings != "" { + settings, err := structure.ExpandJsonFromString(settings) + if err != nil { + return nil, fmt.Errorf("failed to parse JSON from `settings`: %+v", err) + } + extensionProps.Settings = settings } - extensionProps.Settings = settings - protectedSettings, err := structure.ExpandJsonFromString(extensionRaw["protected_settings"].(string)) - if err != nil { - return nil, fmt.Errorf("failed to parse JSON from `settings`: %+v", err) + protectedSettings, ok := extensionRaw["protected_settings"].(string) + if ok && protectedSettings != "" { + protectedSettings, err := structure.ExpandJsonFromString(protectedSettings) + if err != nil { + return nil, fmt.Errorf("failed to parse JSON from `settings`: %+v", err) + } + extensionProps.ProtectedSettings = protectedSettings } - extensionProps.ProtectedSettings = protectedSettings - extension.VirtualMachineScaleSetExtensionProperties = &extensionProps extensions = append(extensions, extension) }