Skip to content

Commit

Permalink
fix vmss tests
Browse files Browse the repository at this point in the history
  • Loading branch information
katbyte committed Sep 20, 2018
1 parent 461eb96 commit 8eb204a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
43 changes: 23 additions & 20 deletions azurerm/resource_arm_virtual_machine_scale_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ func resourceArmVirtualMachineScaleSet() *schema.Resource {
if _, hasPassword := diff.GetOk("os_profile.0.admin_password"); !hasPassword {
disablePassword := false

if v, hasDisable := diff.GetOk("os_profile_linux_config.0.disable_password_authentication"); !hasDisable {
if v, hasDisable := diff.GetOk("os_profile_linux_config.0.disable_password_authentication"); hasDisable {
disablePassword = v.(bool)
}

Expand Down Expand Up @@ -857,11 +857,9 @@ func resourceArmVirtualMachineScaleSetRead(d *schema.ResourceData, meta interfac
}

if osProfile := profile.OsProfile; osProfile != nil {
if linuxConfiguration := osProfile.LinuxConfiguration; linuxConfiguration != nil {
flattenedLinuxConfiguration := flattenAzureRmVirtualMachineScaleSetOsProfileLinuxConfig(linuxConfiguration)
if err := d.Set("os_profile_linux_config", flattenedLinuxConfiguration); err != nil {
return fmt.Errorf("[DEBUG] Error setting `os_profile_linux_config`: %#v", err)
}
flattenedLinuxConfiguration := flattenAzureRmVirtualMachineScaleSetOsProfileLinuxConfig(osProfile.LinuxConfiguration)
if err := d.Set("os_profile_linux_config", flattenedLinuxConfiguration); err != nil {
return fmt.Errorf("[DEBUG] Error setting `os_profile_linux_config`: %#v", err)
}

if secrets := osProfile.Secrets; secrets != nil {
Expand Down Expand Up @@ -991,22 +989,25 @@ func flattenAzureRmVirtualMachineScaleSetIdentity(identity *compute.VirtualMachi

func flattenAzureRmVirtualMachineScaleSetOsProfileLinuxConfig(config *compute.LinuxConfiguration) []interface{} {
result := make(map[string]interface{})
result["disable_password_authentication"] = *config.DisablePasswordAuthentication

if config.SSH != nil && len(*config.SSH.PublicKeys) > 0 {
ssh_keys := make([]map[string]interface{}, 0, len(*config.SSH.PublicKeys))
for _, i := range *config.SSH.PublicKeys {
key := make(map[string]interface{})
key["path"] = *i.Path
if config != nil {
result["disable_password_authentication"] = *config.DisablePasswordAuthentication

if config.SSH != nil && len(*config.SSH.PublicKeys) > 0 {
ssh_keys := make([]map[string]interface{}, 0, len(*config.SSH.PublicKeys))
for _, i := range *config.SSH.PublicKeys {
key := make(map[string]interface{})
key["path"] = *i.Path

if i.KeyData != nil {
key["key_data"] = *i.KeyData
}

if i.KeyData != nil {
key["key_data"] = *i.KeyData
ssh_keys = append(ssh_keys, key)
}

ssh_keys = append(ssh_keys, key)
result["ssh_keys"] = ssh_keys
}

result["ssh_keys"] = ssh_keys
}

return []interface{}{result}
Expand Down Expand Up @@ -1615,9 +1616,7 @@ func expandAzureRMVirtualMachineScaleSetsOsProfile(d *schema.ResourceData) (*com
}
}

if _, ok := d.GetOk("os_profile_linux_config"); ok {
osProfile.LinuxConfiguration = expandAzureRmVirtualMachineScaleSetOsProfileLinuxConfig(d)
}
osProfile.LinuxConfiguration = expandAzureRmVirtualMachineScaleSetOsProfileLinuxConfig(d)

if _, ok := d.GetOk("os_profile_windows_config"); ok {
winConfig, err := expandAzureRmVirtualMachineScaleSetOsProfileWindowsConfig(d)
Expand Down Expand Up @@ -1809,6 +1808,10 @@ func expandAzureRmVirtualMachineScaleSetStorageProfileImageReference(d *schema.R
func expandAzureRmVirtualMachineScaleSetOsProfileLinuxConfig(d *schema.ResourceData) *compute.LinuxConfiguration {
osProfilesLinuxConfig := d.Get("os_profile_linux_config").([]interface{})

if len(osProfilesLinuxConfig) == 0 || osProfilesLinuxConfig[0] == nil {
return nil
}

linuxConfig := osProfilesLinuxConfig[0].(map[string]interface{})
disablePasswordAuth := linuxConfig["disable_password_authentication"].(bool)

Expand Down
1 change: 0 additions & 1 deletion azurerm/resource_arm_virtual_machine_scale_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2054,7 +2054,6 @@ resource "azurerm_virtual_machine_scale_set" "test" {
os_profile {
computer_name_prefix = "prefix"
admin_username = "ubuntu"
admin_password = "password"
custom_data = "custom data!"
}
Expand Down

0 comments on commit 8eb204a

Please sign in to comment.