Skip to content

Commit

Permalink
Merge pull request #266 from dominik-lekse/bugfix/vmss-unattendconfig…
Browse files Browse the repository at this point in the history
…-panic

Fix panic in `azurerm_virtual_machine_scale_set` resource with `additional_unattend_config` block
  • Loading branch information
tombuildsstuff authored Sep 18, 2017
2 parents 7029dfe + ef45b1a commit 0d25ba2
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 4 deletions.
11 changes: 7 additions & 4 deletions azurerm/resource_arm_virtual_machine_scale_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func resourceArmVirtualMachineScaleSet() *schema.Resource {
},
},
"additional_unattend_config": {
Type: schema.TypeSet,
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -656,7 +656,7 @@ func resourceArmVirtualMachineScaleSetRead(d *schema.ResourceData, meta interfac

if properties.VirtualMachineProfile.OsProfile.LinuxConfiguration != nil {
if err := d.Set("os_profile_linux_config", flattenAzureRmVirtualMachineScaleSetOsProfileLinuxConfig(properties.VirtualMachineProfile.OsProfile.LinuxConfiguration)); err != nil {
return fmt.Errorf("[DEBUG] Error setting Virtual Machine Scale Set OS Profile Windows config error: %#v", err)
return fmt.Errorf("[DEBUG] Error setting Virtual Machine Scale Set OS Profile Linux config error: %#v", err)
}
}

Expand Down Expand Up @@ -772,7 +772,10 @@ func flattenAzureRmVirtualMachineScaleSetOsProfileWindowsConfig(config *compute.
c["pass"] = i.PassName
c["component"] = i.ComponentName
c["setting_name"] = i.SettingName
c["content"] = *i.Content

if i.Content != nil {
c["content"] = *i.Content
}

content = append(content, c)
}
Expand Down Expand Up @@ -1438,7 +1441,7 @@ func expandAzureRmVirtualMachineScaleSetOsProfileWindowsConfig(d *schema.Resourc
}
}
if v := osProfileConfig["additional_unattend_config"]; v != nil {
additionalConfig := v.(*schema.Set).List()
additionalConfig := v.([]interface{})
if len(additionalConfig) > 0 {
additionalConfigContent := make([]compute.AdditionalUnattendContent, 0, len(additionalConfig))
for _, addConfig := range additionalConfig {
Expand Down
102 changes: 102 additions & 0 deletions azurerm/resource_arm_virtual_machine_scale_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,24 @@ func TestAccAzureRMVirtualMachineScaleSet_basicLinux_managedDisk(t *testing.T) {
})
}

func TestAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk(t *testing.T) {
ri := acctest.RandInt()
config := testAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk(ri, testLocation())
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMVirtualMachineScaleSetDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMVirtualMachineScaleSetExists("azurerm_virtual_machine_scale_set.test"),
),
},
},
})
}

func TestAccAzureRMVirtualMachineScaleSet_basicLinux_managedDiskNoName(t *testing.T) {
ri := acctest.RandInt()
config := testAccAzureRMVirtualMachineScaleSet_basicLinux_managedDiskNoName(ri, testLocation())
Expand Down Expand Up @@ -1062,6 +1080,90 @@ resource "azurerm_virtual_machine_scale_set" "test" {
`, rInt, location, rInt, rInt, rInt, rInt, rInt)
}

func testAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_virtual_network" "test" {
name = "acctvn-%d"
address_space = ["10.0.0.0/16"]
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
}
resource "azurerm_subnet" "test" {
name = "acctsub-%d"
resource_group_name = "${azurerm_resource_group.test.name}"
virtual_network_name = "${azurerm_virtual_network.test.name}"
address_prefix = "10.0.2.0/24"
}
resource "azurerm_virtual_machine_scale_set" "test" {
name = "acctvmss-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
upgrade_policy_mode = "Manual"
sku {
name = "Standard_D1_v2"
tier = "Standard"
capacity = 2
}
os_profile {
computer_name_prefix = "testvm"
admin_username = "myadmin"
admin_password = "Passwword1234"
}
os_profile_windows_config {
enable_automatic_upgrades = false
provision_vm_agent = true
additional_unattend_config {
pass = "oobeSystem"
component = "Microsoft-Windows-Shell-Setup"
setting_name = "AutoLogon"
content = "<AutoLogon><Username>myadmin</Username><Password><Value>Passwword1234</Value></Password><Enabled>true</Enabled><LogonCount>1</LogonCount></AutoLogon>"
}
additional_unattend_config {
pass = "oobeSystem"
component = "Microsoft-Windows-Shell-Setup"
setting_name = "FirstLogonCommands"
content = "<FirstLogonCommands><SynchronousCommand><CommandLine>shutdown /r /t 0 /c \"initial reboot\"</CommandLine><Description>reboot</Description><Order>1</Order></SynchronousCommand></FirstLogonCommands>"
}
}
network_profile {
name = "TestNetworkProfile-%d"
primary = true
ip_configuration {
name = "TestIPConfiguration"
subnet_id = "${azurerm_subnet.test.id}"
}
}
storage_profile_os_disk {
name = ""
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}
storage_profile_image_reference {
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "2016-Datacenter-Server-Core"
version = "latest"
}
}
`, rInt, location, rInt, rInt, rInt, rInt)
}

func testAccAzureRMVirtualMachineScaleSet_basicLinux_managedDiskNoName(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down

0 comments on commit 0d25ba2

Please sign in to comment.