From 5f42b961e26ffcb52c51315725b39f8074e78b5e Mon Sep 17 00:00:00 2001 From: kt Date: Tue, 25 Sep 2018 15:25:44 -0700 Subject: [PATCH] address pr comments (#1958) --- .../resource_arm_virtual_machine_scale_set.go | 33 ++++++++++++------- ...urce_arm_virtual_machine_scale_set_test.go | 2 -- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/azurerm/resource_arm_virtual_machine_scale_set.go b/azurerm/resource_arm_virtual_machine_scale_set.go index bcd153f3226b..005d0691eede 100644 --- a/azurerm/resource_arm_virtual_machine_scale_set.go +++ b/azurerm/resource_arm_virtual_machine_scale_set.go @@ -22,6 +22,7 @@ func resourceArmVirtualMachineScaleSet() *schema.Resource { Read: resourceArmVirtualMachineScaleSetRead, Update: resourceArmVirtualMachineScaleSetCreate, Delete: resourceArmVirtualMachineScaleSetDelete, + Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -163,7 +164,7 @@ func resourceArmVirtualMachineScaleSet() *schema.Resource { "admin_password": { Type: schema.TypeString, - Required: true, + Optional: true, Sensitive: true, ValidateFunc: validation.NoZeroValues, }, @@ -973,22 +974,30 @@ 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 v := config.DisablePasswordAuthentication; v != nil { + result["disable_password_authentication"] = *v + } + + if ssh := config.SSH; ssh != nil { + if keys := ssh.PublicKeys; keys != nil { + ssh_keys := make([]map[string]interface{}, 0, len(*keys)) + for _, i := range *keys { + key := make(map[string]interface{}) - if i.KeyData != nil { - key["key_data"] = *i.KeyData + if i.Path != nil { + key["path"] = *i.Path + } + + 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} diff --git a/azurerm/resource_arm_virtual_machine_scale_set_test.go b/azurerm/resource_arm_virtual_machine_scale_set_test.go index ef5092302b93..624279c753e9 100644 --- a/azurerm/resource_arm_virtual_machine_scale_set_test.go +++ b/azurerm/resource_arm_virtual_machine_scale_set_test.go @@ -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!" } @@ -2168,7 +2167,6 @@ resource "azurerm_virtual_machine_scale_set" "test" { os_profile { computer_name_prefix = "prefix" admin_username = "ubuntu" - admin_password = "password" custom_data = "custom data!" }