From 8e58f67ab908a3a9d021c26b5aba1ba5b4858f9c Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 13 Oct 2017 14:36:08 +0100 Subject: [PATCH 01/23] converting plan --- azurerm/resource_arm_virtual_machine.go | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/azurerm/resource_arm_virtual_machine.go b/azurerm/resource_arm_virtual_machine.go index 6f630b12d1ea..25f1a11d8cde 100644 --- a/azurerm/resource_arm_virtual_machine.go +++ b/azurerm/resource_arm_virtual_machine.go @@ -37,7 +37,7 @@ func resourceArmVirtualMachine() *schema.Resource { "resource_group_name": resourceGroupNameSchema(), "plan": { - Type: schema.TypeSet, + Type: schema.TypeList, Optional: true, MaxItems: 1, Elem: &schema.Resource{ @@ -58,7 +58,6 @@ func resourceArmVirtualMachine() *schema.Resource { }, }, }, - Set: resourceArmVirtualMachinePlanHash, }, "availability_set_id": { @@ -632,7 +631,7 @@ func resourceArmVirtualMachineRead(d *schema.ResourceData, meta interface{}) err d.Set("location", azureRMNormalizeLocation(*resp.Location)) if resp.Plan != nil { - if err := d.Set("plan", schema.NewSet(resourceArmVirtualMachinePlanHash, flattenAzureRmVirtualMachinePlan(resp.Plan))); err != nil { + if err := d.Set("plan", flattenAzureRmVirtualMachinePlan(resp.Plan)); err != nil { return fmt.Errorf("[DEBUG] Error setting Virtual Machine Plan error: %#v", err) } } @@ -835,16 +834,6 @@ func resourceArmVirtualMachineDeleteManagedDisk(managedDiskID string, meta inter return nil } -func resourceArmVirtualMachinePlanHash(v interface{}) int { - var buf bytes.Buffer - m := v.(map[string]interface{}) - buf.WriteString(fmt.Sprintf("%s-", m["name"].(string))) - buf.WriteString(fmt.Sprintf("%s-", m["publisher"].(string))) - buf.WriteString(fmt.Sprintf("%s-", m["product"].(string))) - - return hashcode.String(buf.String()) -} - func resourceArmVirtualMachineStorageImageReferenceHash(v interface{}) int { var buf bytes.Buffer m := v.(map[string]interface{}) @@ -1109,7 +1098,7 @@ func flattenAzureRmVirtualMachineOsDisk(disk *compute.OSDisk) []interface{} { } func expandAzureRmVirtualMachinePlan(d *schema.ResourceData) (*compute.Plan, error) { - planConfigs := d.Get("plan").(*schema.Set).List() + planConfigs := d.Get("plan").([]interface{}) planConfig := planConfigs[0].(map[string]interface{}) From 6b04776ed015b76d799ba404673afde13a9f23a4 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 13 Oct 2017 14:41:09 +0100 Subject: [PATCH 02/23] `storage_image_reference` Set -> List --- azurerm/resource_arm_virtual_machine.go | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/azurerm/resource_arm_virtual_machine.go b/azurerm/resource_arm_virtual_machine.go index 25f1a11d8cde..0f37689eda30 100644 --- a/azurerm/resource_arm_virtual_machine.go +++ b/azurerm/resource_arm_virtual_machine.go @@ -87,7 +87,7 @@ func resourceArmVirtualMachine() *schema.Resource { }, "storage_image_reference": { - Type: schema.TypeSet, + Type: schema.TypeList, Optional: true, Computed: true, ForceNew: true, @@ -126,7 +126,6 @@ func resourceArmVirtualMachine() *schema.Resource { }, }, }, - Set: resourceArmVirtualMachineStorageImageReferenceHash, }, "storage_os_disk": { @@ -643,7 +642,7 @@ func resourceArmVirtualMachineRead(d *schema.ResourceData, meta interface{}) err d.Set("vm_size", resp.VirtualMachineProperties.HardwareProfile.VMSize) if resp.VirtualMachineProperties.StorageProfile.ImageReference != nil { - if err := d.Set("storage_image_reference", schema.NewSet(resourceArmVirtualMachineStorageImageReferenceHash, flattenAzureRmVirtualMachineImageReference(resp.VirtualMachineProperties.StorageProfile.ImageReference))); err != nil { + if err := d.Set("storage_image_reference", flattenAzureRmVirtualMachineImageReference(resp.VirtualMachineProperties.StorageProfile.ImageReference)); err != nil { return fmt.Errorf("[DEBUG] Error setting Virtual Machine Storage Image Reference error: %#v", err) } } @@ -834,24 +833,6 @@ func resourceArmVirtualMachineDeleteManagedDisk(managedDiskID string, meta inter return nil } -func resourceArmVirtualMachineStorageImageReferenceHash(v interface{}) int { - var buf bytes.Buffer - m := v.(map[string]interface{}) - if m["publisher"] != nil { - buf.WriteString(fmt.Sprintf("%s-", m["publisher"].(string))) - } - if m["offer"] != nil { - buf.WriteString(fmt.Sprintf("%s-", m["offer"].(string))) - } - if m["sku"] != nil { - buf.WriteString(fmt.Sprintf("%s-", m["sku"].(string))) - } - if m["id"] != nil { - buf.WriteString(fmt.Sprintf("%s-", m["id"].(string))) - } - return hashcode.String(buf.String()) -} - func resourceArmVirtualMachineStorageOsProfileHash(v interface{}) int { var buf bytes.Buffer m := v.(map[string]interface{}) @@ -1393,7 +1374,7 @@ func expandAzureRmVirtualMachineDiagnosticsProfile(d *schema.ResourceData) *comp } func expandAzureRmVirtualMachineImageReference(d *schema.ResourceData) (*compute.ImageReference, error) { - storageImageRefs := d.Get("storage_image_reference").(*schema.Set).List() + storageImageRefs := d.Get("storage_image_reference").([]interface{}) storageImageRef := storageImageRefs[0].(map[string]interface{}) imageID := storageImageRef["id"].(string) From c7b38379c7700b985f21a66561883dfcf204a0ab Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 13 Oct 2017 14:47:10 +0100 Subject: [PATCH 03/23] Refactoring `storage_os_disk` from a Set to a List --- azurerm/resource_arm_virtual_machine.go | 32 ++++++++++++------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/azurerm/resource_arm_virtual_machine.go b/azurerm/resource_arm_virtual_machine.go index 0f37689eda30..9c50cb47598a 100644 --- a/azurerm/resource_arm_virtual_machine.go +++ b/azurerm/resource_arm_virtual_machine.go @@ -129,7 +129,7 @@ func resourceArmVirtualMachine() *schema.Resource { }, "storage_os_disk": { - Type: schema.TypeSet, + Type: schema.TypeList, Required: true, MaxItems: 1, Elem: &schema.Resource{ @@ -137,6 +137,12 @@ func resourceArmVirtualMachine() *schema.Resource { "os_type": { Type: schema.TypeString, Optional: true, + Computed: true, + ValidateFunc: validation.StringInSlice([]string{ + string(compute.Linux), + string(compute.Windows), + }, true), + DiffSuppressFunc: ignoreCaseDiffSuppressFunc, }, "name": { @@ -148,6 +154,10 @@ func resourceArmVirtualMachine() *schema.Resource { Type: schema.TypeString, Optional: true, ForceNew: true, + ConflictsWith: []string{ + "storage_os_disk.0.managed_disk_id", + "storage_os_disk.0.managed_disk_type", + }, }, "managed_disk_id": { @@ -155,14 +165,14 @@ func resourceArmVirtualMachine() *schema.Resource { Optional: true, ForceNew: true, Computed: true, - ConflictsWith: []string{"storage_os_disk.vhd_uri"}, + ConflictsWith: []string{"storage_os_disk.0.vhd_uri"}, }, "managed_disk_type": { Type: schema.TypeString, Optional: true, Computed: true, - ConflictsWith: []string{"storage_os_disk.vhd_uri"}, + ConflictsWith: []string{"storage_os_disk.0.vhd_uri"}, ValidateFunc: validation.StringInSlice([]string{ string(compute.PremiumLRS), string(compute.StandardLRS), @@ -189,11 +199,11 @@ func resourceArmVirtualMachine() *schema.Resource { "disk_size_gb": { Type: schema.TypeInt, Optional: true, + Computed: true, ValidateFunc: validateDiskSizeGB, }, }, }, - Set: resourceArmVirtualMachineStorageOsDiskHash, }, "delete_os_disk_on_termination": { @@ -647,7 +657,7 @@ func resourceArmVirtualMachineRead(d *schema.ResourceData, meta interface{}) err } } - if err := d.Set("storage_os_disk", schema.NewSet(resourceArmVirtualMachineStorageOsDiskHash, flattenAzureRmVirtualMachineOsDisk(resp.VirtualMachineProperties.StorageProfile.OsDisk))); err != nil { + if err := d.Set("storage_os_disk", flattenAzureRmVirtualMachineOsDisk(resp.VirtualMachineProperties.StorageProfile.OsDisk)); err != nil { return fmt.Errorf("[DEBUG] Error setting Virtual Machine Storage OS Disk error: %#v", err) } @@ -841,16 +851,6 @@ func resourceArmVirtualMachineStorageOsProfileHash(v interface{}) int { return hashcode.String(buf.String()) } -func resourceArmVirtualMachineStorageOsDiskHash(v interface{}) int { - var buf bytes.Buffer - m := v.(map[string]interface{}) - buf.WriteString(fmt.Sprintf("%s-", m["name"].(string))) - if m["vhd_uri"] != nil { - buf.WriteString(fmt.Sprintf("%s-", m["vhd_uri"].(string))) - } - return hashcode.String(buf.String()) -} - func resourceArmVirtualMachineStorageOsProfileLinuxConfigHash(v interface{}) int { var buf bytes.Buffer m := v.(map[string]interface{}) @@ -1430,7 +1430,7 @@ func expandAzureRmVirtualMachineNetworkProfile(d *schema.ResourceData) compute.N } func expandAzureRmVirtualMachineOsDisk(d *schema.ResourceData) (*compute.OSDisk, error) { - disks := d.Get("storage_os_disk").(*schema.Set).List() + disks := d.Get("storage_os_disk").([]interface{}) config := disks[0].(map[string]interface{}) From 80795826b7fe9077de2660fec3d25bb93b559ce1 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 13 Oct 2017 14:49:29 +0100 Subject: [PATCH 04/23] Fixing the validation for `storage_data_disk` --- azurerm/resource_arm_virtual_machine.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/azurerm/resource_arm_virtual_machine.go b/azurerm/resource_arm_virtual_machine.go index 9c50cb47598a..674cff89b27a 100644 --- a/azurerm/resource_arm_virtual_machine.go +++ b/azurerm/resource_arm_virtual_machine.go @@ -225,6 +225,10 @@ func resourceArmVirtualMachine() *schema.Resource { "vhd_uri": { Type: schema.TypeString, Optional: true, + ConflictsWith: []string{ + "storage_data_disk.0.managed_disk_id", + "storage_data_disk.0.managed_disk_type", + }, }, "managed_disk_id": { @@ -232,14 +236,14 @@ func resourceArmVirtualMachine() *schema.Resource { Optional: true, ForceNew: true, Computed: true, - ConflictsWith: []string{"storage_data_disk.vhd_uri"}, + ConflictsWith: []string{"storage_data_disk.0.vhd_uri"}, }, "managed_disk_type": { Type: schema.TypeString, Optional: true, Computed: true, - ConflictsWith: []string{"storage_data_disk.vhd_uri"}, + ConflictsWith: []string{"storage_data_disk.0.vhd_uri"}, ValidateFunc: validation.StringInSlice([]string{ string(compute.PremiumLRS), string(compute.StandardLRS), From 0e949de3f5119fcfc1a4e0a3a202b5befd421685 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 13 Oct 2017 15:04:33 +0100 Subject: [PATCH 05/23] Moving OS Profile from a Set to a List --- azurerm/resource_arm_virtual_machine.go | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/azurerm/resource_arm_virtual_machine.go b/azurerm/resource_arm_virtual_machine.go index 674cff89b27a..21ac61f97490 100644 --- a/azurerm/resource_arm_virtual_machine.go +++ b/azurerm/resource_arm_virtual_machine.go @@ -284,12 +284,13 @@ func resourceArmVirtualMachine() *schema.Resource { Default: false, }, + // TODO: remove this in the next major version "diagnostics_profile": { Type: schema.TypeSet, Optional: true, MaxItems: 1, ConflictsWith: []string{"boot_diagnostics"}, - Deprecated: "Use field boot_diagnostics instead", + Removed: "Use field boot_diagnostics instead", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "boot_diagnostics": { @@ -334,7 +335,7 @@ func resourceArmVirtualMachine() *schema.Resource { }, "os_profile": { - Type: schema.TypeSet, + Type: schema.TypeList, Optional: true, MaxItems: 1, Elem: &schema.Resource{ @@ -354,6 +355,10 @@ func resourceArmVirtualMachine() *schema.Resource { Type: schema.TypeString, Optional: true, Sensitive: true, + DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { + // TODO: remove this if there's an acceptable workaround + return old == "" + }, }, "custom_data": { @@ -365,7 +370,6 @@ func resourceArmVirtualMachine() *schema.Resource { }, }, }, - Set: resourceArmVirtualMachineStorageOsProfileHash, }, "os_profile_windows_config": { @@ -672,7 +676,7 @@ func resourceArmVirtualMachineRead(d *schema.ResourceData, meta interface{}) err } if resp.VirtualMachineProperties.OsProfile != nil { - if err := d.Set("os_profile", schema.NewSet(resourceArmVirtualMachineStorageOsProfileHash, flattenAzureRmVirtualMachineOsProfile(resp.VirtualMachineProperties.OsProfile))); err != nil { + if err := d.Set("os_profile", flattenAzureRmVirtualMachineOsProfile(resp.VirtualMachineProperties.OsProfile)); err != nil { return fmt.Errorf("[DEBUG] Error setting Virtual Machine Storage OS Profile: %#v", err) } @@ -847,14 +851,6 @@ func resourceArmVirtualMachineDeleteManagedDisk(managedDiskID string, meta inter return nil } -func resourceArmVirtualMachineStorageOsProfileHash(v interface{}) int { - var buf bytes.Buffer - m := v.(map[string]interface{}) - buf.WriteString(fmt.Sprintf("%s-", m["admin_username"].(string))) - buf.WriteString(fmt.Sprintf("%s-", m["computer_name"].(string))) - return hashcode.String(buf.String()) -} - func resourceArmVirtualMachineStorageOsProfileLinuxConfigHash(v interface{}) int { var buf bytes.Buffer m := v.(map[string]interface{}) @@ -1099,7 +1095,7 @@ func expandAzureRmVirtualMachinePlan(d *schema.ResourceData) (*compute.Plan, err } func expandAzureRmVirtualMachineOsProfile(d *schema.ResourceData) (*compute.OSProfile, error) { - osProfiles := d.Get("os_profile").(*schema.Set).List() + osProfiles := d.Get("os_profile").([]interface{}) osProfile := osProfiles[0].(map[string]interface{}) From 91aad909fc8dbc3695c9d25e30845e98e07c1de1 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 13 Oct 2017 15:06:59 +0100 Subject: [PATCH 06/23] Sets to Lists for `os_profile_windows_config` --- azurerm/resource_arm_virtual_machine.go | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/azurerm/resource_arm_virtual_machine.go b/azurerm/resource_arm_virtual_machine.go index 21ac61f97490..8953f1d1e77e 100644 --- a/azurerm/resource_arm_virtual_machine.go +++ b/azurerm/resource_arm_virtual_machine.go @@ -373,7 +373,7 @@ func resourceArmVirtualMachine() *schema.Resource { }, "os_profile_windows_config": { - Type: schema.TypeSet, + Type: schema.TypeList, Optional: true, MaxItems: 1, Elem: &schema.Resource{ @@ -430,7 +430,6 @@ func resourceArmVirtualMachine() *schema.Resource { }, }, }, - Set: resourceArmVirtualMachineStorageOsProfileWindowsConfigHash, }, "os_profile_linux_config": { @@ -859,22 +858,6 @@ func resourceArmVirtualMachineStorageOsProfileLinuxConfigHash(v interface{}) int return hashcode.String(buf.String()) } -func resourceArmVirtualMachineStorageOsProfileWindowsConfigHash(v interface{}) int { - var buf bytes.Buffer - - if v != nil { - m := v.(map[string]interface{}) - if m["provision_vm_agent"] != nil { - buf.WriteString(fmt.Sprintf("%t-", m["provision_vm_agent"].(bool))) - } - if m["enable_automatic_upgrades"] != nil { - buf.WriteString(fmt.Sprintf("%t-", m["enable_automatic_upgrades"].(bool))) - } - } - - return hashcode.String(buf.String()) -} - func flattenAzureRmVirtualMachinePlan(plan *compute.Plan) []interface{} { result := make(map[string]interface{}) result["name"] = *plan.Name @@ -1225,7 +1208,7 @@ func expandAzureRmVirtualMachineOsProfileLinuxConfig(d *schema.ResourceData) (*c } func expandAzureRmVirtualMachineOsProfileWindowsConfig(d *schema.ResourceData) (*compute.WindowsConfiguration, error) { - osProfilesWindowsConfig := d.Get("os_profile_windows_config").(*schema.Set).List() + osProfilesWindowsConfig := d.Get("os_profile_windows_config").([]interface{}) osProfileConfig := osProfilesWindowsConfig[0].(map[string]interface{}) config := &compute.WindowsConfiguration{} From 2b0e76189be3bac3878670a40e24146b5c4773b8 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 13 Oct 2017 15:24:56 +0100 Subject: [PATCH 07/23] Migrating `os_profile_linux_config` / `network_interface_ids` from Sets to Lists --- azurerm/resource_arm_virtual_machine.go | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/azurerm/resource_arm_virtual_machine.go b/azurerm/resource_arm_virtual_machine.go index 8953f1d1e77e..193196ff6f3e 100644 --- a/azurerm/resource_arm_virtual_machine.go +++ b/azurerm/resource_arm_virtual_machine.go @@ -1,7 +1,6 @@ package azurerm import ( - "bytes" "fmt" "log" "net/url" @@ -9,7 +8,6 @@ import ( "github.com/Azure/azure-sdk-for-go/arm/compute" "github.com/Azure/azure-sdk-for-go/storage" - "github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" @@ -433,7 +431,7 @@ func resourceArmVirtualMachine() *schema.Resource { }, "os_profile_linux_config": { - Type: schema.TypeSet, + Type: schema.TypeList, Optional: true, MaxItems: 1, Elem: &schema.Resource{ @@ -460,7 +458,6 @@ func resourceArmVirtualMachine() *schema.Resource { }, }, }, - Set: resourceArmVirtualMachineStorageOsProfileLinuxConfigHash, }, "os_profile_secrets": { @@ -494,12 +491,11 @@ func resourceArmVirtualMachine() *schema.Resource { }, "network_interface_ids": { - Type: schema.TypeSet, + Type: schema.TypeList, Required: true, Elem: &schema.Schema{ Type: schema.TypeString, }, - Set: schema.HashString, }, "primary_network_interface_id": { @@ -850,14 +846,6 @@ func resourceArmVirtualMachineDeleteManagedDisk(managedDiskID string, meta inter return nil } -func resourceArmVirtualMachineStorageOsProfileLinuxConfigHash(v interface{}) int { - var buf bytes.Buffer - m := v.(map[string]interface{}) - buf.WriteString(fmt.Sprintf("%t-", m["disable_password_authentication"].(bool))) - - return hashcode.String(buf.String()) -} - func flattenAzureRmVirtualMachinePlan(plan *compute.Plan) []interface{} { result := make(map[string]interface{}) result["name"] = *plan.Name @@ -899,8 +887,8 @@ func flattenAzureRmVirtualMachineDiagnosticsProfile(profile *compute.BootDiagnos return []interface{}{result} } -func flattenAzureRmVirtualMachineNetworkInterfaces(profile *compute.NetworkProfile) []string { - result := make([]string, 0, len(*profile.NetworkInterfaces)) +func flattenAzureRmVirtualMachineNetworkInterfaces(profile *compute.NetworkProfile) []interface{} { + result := make([]interface{}, 0) for _, nic := range *profile.NetworkInterfaces { result = append(result, *nic.ID) } @@ -1170,7 +1158,7 @@ func expandAzureRmVirtualMachineOsProfileSecrets(d *schema.ResourceData) *[]comp } func expandAzureRmVirtualMachineOsProfileLinuxConfig(d *schema.ResourceData) (*compute.LinuxConfiguration, error) { - osProfilesLinuxConfig := d.Get("os_profile_linux_config").(*schema.Set).List() + osProfilesLinuxConfig := d.Get("os_profile_linux_config").([]interface{}) linuxConfig := osProfilesLinuxConfig[0].(map[string]interface{}) disablePasswordAuth := linuxConfig["disable_password_authentication"].(bool) From f5b71d3c9dcf2963ab12ac6d0af612f503c1ebb8 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 13 Oct 2017 15:31:10 +0100 Subject: [PATCH 08/23] Removing the final vm set --- azurerm/resource_arm_virtual_machine.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/azurerm/resource_arm_virtual_machine.go b/azurerm/resource_arm_virtual_machine.go index 193196ff6f3e..6938af731d4a 100644 --- a/azurerm/resource_arm_virtual_machine.go +++ b/azurerm/resource_arm_virtual_machine.go @@ -461,7 +461,7 @@ func resourceArmVirtualMachine() *schema.Resource { }, "os_profile_secrets": { - Type: schema.TypeSet, + Type: schema.TypeList, Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -895,8 +895,8 @@ func flattenAzureRmVirtualMachineNetworkInterfaces(profile *compute.NetworkProfi return result } -func flattenAzureRmVirtualMachineOsProfileSecrets(secrets *[]compute.VaultSecretGroup) []map[string]interface{} { - result := make([]map[string]interface{}, 0, len(*secrets)) +func flattenAzureRmVirtualMachineOsProfileSecrets(secrets *[]compute.VaultSecretGroup) []interface{} { + result := make([]interface{}, 0) for _, secret := range *secrets { s := map[string]interface{}{ "source_vault_id": *secret.SourceVault.ID, @@ -1119,7 +1119,7 @@ func expandAzureRmVirtualMachineOsProfile(d *schema.ResourceData) (*compute.OSPr } func expandAzureRmVirtualMachineOsProfileSecrets(d *schema.ResourceData) *[]compute.VaultSecretGroup { - secretsConfig := d.Get("os_profile_secrets").(*schema.Set).List() + secretsConfig := d.Get("os_profile_secrets").([]interface{}) secrets := make([]compute.VaultSecretGroup, 0, len(secretsConfig)) for _, secretConfig := range secretsConfig { @@ -1376,7 +1376,7 @@ func expandAzureRmVirtualMachineImageReference(d *schema.ResourceData) (*compute } func expandAzureRmVirtualMachineNetworkProfile(d *schema.ResourceData) compute.NetworkProfile { - nicIds := d.Get("network_interface_ids").(*schema.Set).List() + nicIds := d.Get("network_interface_ids").([]interface{}) primaryNicId := d.Get("primary_network_interface_id").(string) network_interfaces := make([]compute.NetworkInterfaceReference, 0, len(nicIds)) From 96ff9a8cd8123409059578818f95f11b215ca859 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 13 Oct 2017 16:48:59 +0100 Subject: [PATCH 09/23] Changing OSProfile back to a Set --- azurerm/resource_arm_virtual_machine.go | 32 +++++++++++++++---------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/azurerm/resource_arm_virtual_machine.go b/azurerm/resource_arm_virtual_machine.go index 6938af731d4a..0ccb25997397 100644 --- a/azurerm/resource_arm_virtual_machine.go +++ b/azurerm/resource_arm_virtual_machine.go @@ -6,8 +6,11 @@ import ( "net/url" "strings" + "bytes" + "github.com/Azure/azure-sdk-for-go/arm/compute" "github.com/Azure/azure-sdk-for-go/storage" + "github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" @@ -333,7 +336,7 @@ func resourceArmVirtualMachine() *schema.Resource { }, "os_profile": { - Type: schema.TypeList, + Type: schema.TypeSet, Optional: true, MaxItems: 1, Elem: &schema.Resource{ @@ -353,10 +356,6 @@ func resourceArmVirtualMachine() *schema.Resource { Type: schema.TypeString, Optional: true, Sensitive: true, - DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { - // TODO: remove this if there's an acceptable workaround - return old == "" - }, }, "custom_data": { @@ -368,6 +367,7 @@ func resourceArmVirtualMachine() *schema.Resource { }, }, }, + Set: resourceArmVirtualMachineStorageOsProfileHash, }, "os_profile_windows_config": { @@ -671,7 +671,7 @@ func resourceArmVirtualMachineRead(d *schema.ResourceData, meta interface{}) err } if resp.VirtualMachineProperties.OsProfile != nil { - if err := d.Set("os_profile", flattenAzureRmVirtualMachineOsProfile(resp.VirtualMachineProperties.OsProfile)); err != nil { + if err := d.Set("os_profile", schema.NewSet(resourceArmVirtualMachineStorageOsProfileHash, flattenAzureRmVirtualMachineOsProfile(resp.VirtualMachineProperties.OsProfile))); err != nil { return fmt.Errorf("[DEBUG] Error setting Virtual Machine Storage OS Profile: %#v", err) } @@ -947,12 +947,12 @@ func flattenAzureRmVirtualMachineDataDisk(disks *[]compute.DataDisk) interface{} return result } -func flattenAzureRmVirtualMachineOsProfile(osProfile *compute.OSProfile) []interface{} { +func flattenAzureRmVirtualMachineOsProfile(input *compute.OSProfile) []interface{} { result := make(map[string]interface{}) - result["computer_name"] = *osProfile.ComputerName - result["admin_username"] = *osProfile.AdminUsername - if osProfile.CustomData != nil { - result["custom_data"] = *osProfile.CustomData + result["computer_name"] = *input.ComputerName + result["admin_username"] = *input.AdminUsername + if input.CustomData != nil { + result["custom_data"] = *input.CustomData } return []interface{}{result} @@ -1066,7 +1066,7 @@ func expandAzureRmVirtualMachinePlan(d *schema.ResourceData) (*compute.Plan, err } func expandAzureRmVirtualMachineOsProfile(d *schema.ResourceData) (*compute.OSProfile, error) { - osProfiles := d.Get("os_profile").([]interface{}) + osProfiles := d.Get("os_profile").(*schema.Set).List() osProfile := osProfiles[0].(map[string]interface{}) @@ -1498,3 +1498,11 @@ func findStorageAccountResourceGroup(meta interface{}, storageAccountName string return id.ResourceGroup, nil } + +func resourceArmVirtualMachineStorageOsProfileHash(v interface{}) int { + var buf bytes.Buffer + m := v.(map[string]interface{}) + buf.WriteString(fmt.Sprintf("%s-", m["admin_username"].(string))) + buf.WriteString(fmt.Sprintf("%s-", m["computer_name"].(string))) + return hashcode.String(buf.String()) +} From 7862954696973932a353d26e6e80d97e0f7ebebc Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 16 Oct 2017 10:14:30 +0100 Subject: [PATCH 10/23] Removing the extra validation from the data_disk list --- azurerm/resource_arm_virtual_machine.go | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/azurerm/resource_arm_virtual_machine.go b/azurerm/resource_arm_virtual_machine.go index 0ccb25997397..e891a0320a56 100644 --- a/azurerm/resource_arm_virtual_machine.go +++ b/azurerm/resource_arm_virtual_machine.go @@ -226,25 +226,19 @@ func resourceArmVirtualMachine() *schema.Resource { "vhd_uri": { Type: schema.TypeString, Optional: true, - ConflictsWith: []string{ - "storage_data_disk.0.managed_disk_id", - "storage_data_disk.0.managed_disk_type", - }, }, "managed_disk_id": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - Computed: true, - ConflictsWith: []string{"storage_data_disk.0.vhd_uri"}, + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Computed: true, }, "managed_disk_type": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ConflictsWith: []string{"storage_data_disk.0.vhd_uri"}, + Type: schema.TypeString, + Optional: true, + Computed: true, ValidateFunc: validation.StringInSlice([]string{ string(compute.PremiumLRS), string(compute.StandardLRS), From 5b8a07fa2bba368c20e5848639ca3771a3e4a9f5 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 16 Oct 2017 10:41:24 +0100 Subject: [PATCH 11/23] Fixing the OS Disk Type Conflict test --- azurerm/resource_arm_virtual_machine_managed_disks_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/resource_arm_virtual_machine_managed_disks_test.go b/azurerm/resource_arm_virtual_machine_managed_disks_test.go index aece85256717..8b5781bdb835 100644 --- a/azurerm/resource_arm_virtual_machine_managed_disks_test.go +++ b/azurerm/resource_arm_virtual_machine_managed_disks_test.go @@ -187,7 +187,7 @@ func TestAccAzureRMVirtualMachine_osDiskTypeConflict(t *testing.T) { Steps: []resource.TestStep{ { Config: config, - ExpectError: regexp.MustCompile("Conflict between `vhd_uri`"), + ExpectError: regexp.MustCompile("conflicts with storage_os_disk.0.managed_disk_type"), }, }, }) From 20b47915dd028a39573ce042568864ffbe577b9c Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 16 Oct 2017 10:42:33 +0100 Subject: [PATCH 12/23] Removing the Windows Licence test since it doesn't work in our subscription --- ...rm_virtual_machine_unmanaged_disks_test.go | 107 ------------------ 1 file changed, 107 deletions(-) diff --git a/azurerm/resource_arm_virtual_machine_unmanaged_disks_test.go b/azurerm/resource_arm_virtual_machine_unmanaged_disks_test.go index dcc3f1c15491..91a67a7ceac9 100644 --- a/azurerm/resource_arm_virtual_machine_unmanaged_disks_test.go +++ b/azurerm/resource_arm_virtual_machine_unmanaged_disks_test.go @@ -536,25 +536,6 @@ func TestAccAzureRMVirtualMachine_primaryNetworkInterfaceId(t *testing.T) { }) } -func TestAccAzureRMVirtualMachine_windowsLicenseType(t *testing.T) { - var vm compute.VirtualMachine - ri := acctest.RandInt() - config := testAccAzureRMVirtualMachine_windowsLicenseType(ri, testLocation()) - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testCheckAzureRMVirtualMachineDestroy, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), - ), - }, - }, - }) -} - func testAccAzureRMVirtualMachine_basicLinuxMachine(rInt int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { @@ -2246,94 +2227,6 @@ resource "azurerm_virtual_machine" "test" { `, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) } -func testAccAzureRMVirtualMachine_windowsLicenseType(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_network_interface" "test" { - name = "acctni-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - ip_configuration { - name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" - private_ip_address_allocation = "dynamic" - } -} - -resource "azurerm_storage_account" "test" { - name = "accsa%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - account_tier = "Standard" - account_replication_type = "LRS" - - tags { - environment = "staging" - } -} - -resource "azurerm_storage_container" "test" { - name = "vhds" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" - container_access_type = "private" -} - -resource "azurerm_virtual_machine" "test" { - name = "acctvm-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - network_interface_ids = ["${azurerm_network_interface.test.id}"] - vm_size = "Standard_D1_v2" - license_type = "Windows_Server" - - storage_image_reference { - publisher = "MicrosoftWindowsServer" - offer = "WindowsServer-HUB" - sku = "2008-R2-SP1-HUB" - version = "latest" - } - - storage_os_disk { - name = "myosdisk1" - vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" - caching = "ReadWrite" - create_option = "FromImage" - } - - os_profile { - computer_name = "winhost01" - admin_username = "testadmin" - admin_password = "Password1234!" - } - - os_profile_windows_config { - enable_automatic_upgrades = false - provision_vm_agent = true - } -} -`, rInt, location, rInt, rInt, rInt, rInt, rInt) -} - func testAccAzureRMVirtualMachine_plan(rInt int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { From 1a1708fafdb3c146844a396ca78f442107db8ec0 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 16 Oct 2017 11:16:50 +0100 Subject: [PATCH 13/23] Fixing up the os_profile_linux_config tests --- azurerm/resource_arm_virtual_machine.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/azurerm/resource_arm_virtual_machine.go b/azurerm/resource_arm_virtual_machine.go index e891a0320a56..19e54524ab19 100644 --- a/azurerm/resource_arm_virtual_machine.go +++ b/azurerm/resource_arm_virtual_machine.go @@ -425,7 +425,7 @@ func resourceArmVirtualMachine() *schema.Resource { }, "os_profile_linux_config": { - Type: schema.TypeList, + Type: schema.TypeSet, Optional: true, MaxItems: 1, Elem: &schema.Resource{ @@ -452,6 +452,7 @@ func resourceArmVirtualMachine() *schema.Resource { }, }, }, + Set: resourceArmVirtualMachineStorageOsProfileLinuxConfigHash, }, "os_profile_secrets": { @@ -676,7 +677,7 @@ func resourceArmVirtualMachineRead(d *schema.ResourceData, meta interface{}) err } if resp.VirtualMachineProperties.OsProfile.LinuxConfiguration != nil { - if err := d.Set("os_profile_linux_config", flattenAzureRmVirtualMachineOsProfileLinuxConfiguration(resp.VirtualMachineProperties.OsProfile.LinuxConfiguration)); err != nil { + if err := d.Set("os_profile_linux_config", schema.NewSet(resourceArmVirtualMachineStorageOsProfileLinuxConfigHash, flattenAzureRmVirtualMachineOsProfileLinuxConfiguration(resp.VirtualMachineProperties.OsProfile.LinuxConfiguration))); err != nil { return fmt.Errorf("[DEBUG] Error setting Virtual Machine Storage OS Profile Linux Configuration: %#v", err) } } @@ -1152,7 +1153,7 @@ func expandAzureRmVirtualMachineOsProfileSecrets(d *schema.ResourceData) *[]comp } func expandAzureRmVirtualMachineOsProfileLinuxConfig(d *schema.ResourceData) (*compute.LinuxConfiguration, error) { - osProfilesLinuxConfig := d.Get("os_profile_linux_config").([]interface{}) + osProfilesLinuxConfig := d.Get("os_profile_linux_config").(*schema.Set).List() linuxConfig := osProfilesLinuxConfig[0].(map[string]interface{}) disablePasswordAuth := linuxConfig["disable_password_authentication"].(bool) @@ -1500,3 +1501,11 @@ func resourceArmVirtualMachineStorageOsProfileHash(v interface{}) int { buf.WriteString(fmt.Sprintf("%s-", m["computer_name"].(string))) return hashcode.String(buf.String()) } + +func resourceArmVirtualMachineStorageOsProfileLinuxConfigHash(v interface{}) int { + var buf bytes.Buffer + m := v.(map[string]interface{}) + buf.WriteString(fmt.Sprintf("%t-", m["disable_password_authentication"].(bool))) + + return hashcode.String(buf.String()) +} From 807ba0a21049e3b15c620f70c88061167c25bd81 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 16 Oct 2017 11:19:02 +0100 Subject: [PATCH 14/23] Adding a conflicts reference between the Windows & Linux OS profiles --- azurerm/resource_arm_virtual_machine.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/azurerm/resource_arm_virtual_machine.go b/azurerm/resource_arm_virtual_machine.go index 19e54524ab19..6198f6d78aa1 100644 --- a/azurerm/resource_arm_virtual_machine.go +++ b/azurerm/resource_arm_virtual_machine.go @@ -422,6 +422,7 @@ func resourceArmVirtualMachine() *schema.Resource { }, }, }, + ConflictsWith: []string{"os_profile_linux_config"}, }, "os_profile_linux_config": { @@ -452,7 +453,8 @@ func resourceArmVirtualMachine() *schema.Resource { }, }, }, - Set: resourceArmVirtualMachineStorageOsProfileLinuxConfigHash, + Set: resourceArmVirtualMachineStorageOsProfileLinuxConfigHash, + ConflictsWith: []string{"os_profile_windows_config"}, }, "os_profile_secrets": { From 6b2e219f97de69d3f101a9ec639301310cbea925 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 16 Oct 2017 11:42:10 +0100 Subject: [PATCH 15/23] Adding a check that either a Windows or Linux OS Profile is specified. Fixes #426 --- azurerm/resource_arm_virtual_machine.go | 4 + ..._arm_virtual_machine_managed_disks_test.go | 158 ++++++++++++++++++ website/docs/r/virtual_machine.html.markdown | 6 +- 3 files changed, 165 insertions(+), 3 deletions(-) diff --git a/azurerm/resource_arm_virtual_machine.go b/azurerm/resource_arm_virtual_machine.go index 6198f6d78aa1..f2ca770f243e 100644 --- a/azurerm/resource_arm_virtual_machine.go +++ b/azurerm/resource_arm_virtual_machine.go @@ -1100,6 +1100,10 @@ func expandAzureRmVirtualMachineOsProfile(d *schema.ResourceData) (*compute.OSPr } } + if profile.LinuxConfiguration == nil && profile.WindowsConfiguration == nil { + return nil, fmt.Errorf("Error: either a `os_profile_linux_config` or a `os_profile_windows_config` must be specified.") + } + if _, ok := d.GetOk("os_profile_secrets"); ok { secrets := expandAzureRmVirtualMachineOsProfileSecrets(d) if secrets != nil { diff --git a/azurerm/resource_arm_virtual_machine_managed_disks_test.go b/azurerm/resource_arm_virtual_machine_managed_disks_test.go index 8b5781bdb835..aa769d63d6d7 100644 --- a/azurerm/resource_arm_virtual_machine_managed_disks_test.go +++ b/azurerm/resource_arm_virtual_machine_managed_disks_test.go @@ -256,6 +256,38 @@ func TestAccAzureRMVirtualMachine_changeStorageDataDiskCreationOption(t *testing }) } +func TestAccAzureRMVirtualMachine_linuxNoConfig(t *testing.T) { + ri := acctest.RandInt() + config := testAccAzureRMVirtualMachine_linuxNoConfig(ri, testLocation()) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMVirtualMachineDestroy, + Steps: []resource.TestStep{ + { + Config: config, + ExpectError: regexp.MustCompile("Error: either a `os_profile_linux_config` or a `os_profile_windows_config` must be specified."), + }, + }, + }) +} + +func TestAccAzureRMVirtualMachine_windowsNoConfig(t *testing.T) { + ri := acctest.RandInt() + config := testAccAzureRMVirtualMachine_windowsNoConfig(ri, testLocation()) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMVirtualMachineDestroy, + Steps: []resource.TestStep{ + { + Config: config, + ExpectError: regexp.MustCompile("Error: either a `os_profile_linux_config` or a `os_profile_windows_config` must be specified."), + }, + }, + }) +} + func testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_explicit(rInt int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { @@ -1207,3 +1239,129 @@ func testGetAzureRMVirtualMachineManagedDisk(managedDiskID *string) (*disk.Model return &d, nil } + +func testAccAzureRMVirtualMachine_linuxNoConfig(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_network_interface" "test" { + name = "acctni-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + ip_configuration { + name = "testconfiguration1" + subnet_id = "${azurerm_subnet.test.id}" + private_ip_address_allocation = "dynamic" + } +} + +resource "azurerm_virtual_machine" "test" { + name = "acctvm%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + network_interface_ids = ["${azurerm_network_interface.test.id}"] + vm_size = "Standard_F1" + + storage_image_reference { + publisher = "Canonical" + offer = "UbuntuServer" + sku = "16.04-LTS" + version = "latest" + } + + storage_os_disk { + name = "myosdisk1" + caching = "ReadWrite" + create_option = "FromImage" + managed_disk_type = "Standard_LRS" + } + + os_profile { + computer_name = "acctvm%d" + admin_username = "testadmin" + admin_password = "Password1234!" + } +} +`, rInt, location, rInt, rInt, rInt, rInt, rInt) +} + +func testAccAzureRMVirtualMachine_windowsNoConfig(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_network_interface" "test" { + name = "acctni-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + ip_configuration { + name = "testconfiguration1" + subnet_id = "${azurerm_subnet.test.id}" + private_ip_address_allocation = "dynamic" + } +} + +resource "azurerm_virtual_machine" "test" { + name = "acctvm%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + network_interface_ids = ["${azurerm_network_interface.test.id}"] + vm_size = "Standard_F1" + + storage_image_reference { + publisher = "MicrosoftWindowsServer" + offer = "WindowsServer" + sku = "2012-Datacenter" + version = "latest" + } + + storage_os_disk { + name = "myosdisk1" + caching = "ReadWrite" + create_option = "FromImage" + managed_disk_type = "Standard_LRS" + } + + os_profile { + computer_name = "acctvm%d" + admin_username = "testadmin" + admin_password = "Password1234!" + } +} +`, rInt, location, rInt, rInt, rInt, rInt, rInt) +} diff --git a/website/docs/r/virtual_machine.html.markdown b/website/docs/r/virtual_machine.html.markdown index aea5ccedf8a4..fa0104dfc2e5 100644 --- a/website/docs/r/virtual_machine.html.markdown +++ b/website/docs/r/virtual_machine.html.markdown @@ -238,9 +238,9 @@ The following arguments are supported: * `delete_data_disks_on_termination` - (Optional) Flag to enable deletion of storage data disk VHD blobs or managed disks when the VM is deleted, defaults to `false` * `os_profile` - (Optional) An OS Profile block as documented below. Required when `create_option` in the `storage_os_disk` block is set to `FromImage`. -* `license_type` - (Optional, when a windows machine) Specifies the Windows OS license type. The only allowable value, if supplied, is `Windows_Server`. -* `os_profile_windows_config` - (Required, when a windows machine) A Windows config block as documented below. -* `os_profile_linux_config` - (Required, when a linux machine) A Linux config block as documented below. +* `license_type` - (Optional, when a Windows machine) Specifies the Windows OS license type. The only allowable value, if supplied, is `Windows_Server`. +* `os_profile_windows_config` - (Required, when a Windows machine) A Windows config block as documented below. +* `os_profile_linux_config` - (Required, when a Linux machine) A Linux config block as documented below. * `os_profile_secrets` - (Optional) A collection of Secret blocks as documented below. * `network_interface_ids` - (Required) Specifies the list of resource IDs for the network interfaces associated with the virtual machine. * `primary_network_interface_id` - (Optional) Specifies the resource ID for the primary network interface associated with the virtual machine. From ee5929252c33443ab4b957f35b757f0bb093d8fc Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 16 Oct 2017 11:48:19 +0100 Subject: [PATCH 16/23] Converting `os_profile_windows_config` back to a set --- azurerm/resource_arm_virtual_machine.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/azurerm/resource_arm_virtual_machine.go b/azurerm/resource_arm_virtual_machine.go index f2ca770f243e..22102c45fa21 100644 --- a/azurerm/resource_arm_virtual_machine.go +++ b/azurerm/resource_arm_virtual_machine.go @@ -365,7 +365,7 @@ func resourceArmVirtualMachine() *schema.Resource { }, "os_profile_windows_config": { - Type: schema.TypeList, + Type: schema.TypeSet, Optional: true, MaxItems: 1, Elem: &schema.Resource{ @@ -422,6 +422,7 @@ func resourceArmVirtualMachine() *schema.Resource { }, }, }, + Set: resourceArmVirtualMachineStorageOsProfileWindowsConfigHash, ConflictsWith: []string{"os_profile_linux_config"}, }, @@ -673,7 +674,7 @@ func resourceArmVirtualMachineRead(d *schema.ResourceData, meta interface{}) err } if resp.VirtualMachineProperties.OsProfile.WindowsConfiguration != nil { - if err := d.Set("os_profile_windows_config", flattenAzureRmVirtualMachineOsProfileWindowsConfiguration(resp.VirtualMachineProperties.OsProfile.WindowsConfiguration)); err != nil { + if err := d.Set("os_profile_windows_config", schema.NewSet(resourceArmVirtualMachineStorageOsProfileWindowsConfigHash, flattenAzureRmVirtualMachineOsProfileWindowsConfiguration(resp.VirtualMachineProperties.OsProfile.WindowsConfiguration))); err != nil { return fmt.Errorf("[DEBUG] Error setting Virtual Machine Storage OS Profile Windows Configuration: %#v", err) } } @@ -1197,7 +1198,7 @@ func expandAzureRmVirtualMachineOsProfileLinuxConfig(d *schema.ResourceData) (*c } func expandAzureRmVirtualMachineOsProfileWindowsConfig(d *schema.ResourceData) (*compute.WindowsConfiguration, error) { - osProfilesWindowsConfig := d.Get("os_profile_windows_config").([]interface{}) + osProfilesWindowsConfig := d.Get("os_profile_windows_config").(*schema.Set).List() osProfileConfig := osProfilesWindowsConfig[0].(map[string]interface{}) config := &compute.WindowsConfiguration{} @@ -1508,6 +1509,22 @@ func resourceArmVirtualMachineStorageOsProfileHash(v interface{}) int { return hashcode.String(buf.String()) } +func resourceArmVirtualMachineStorageOsProfileWindowsConfigHash(v interface{}) int { + var buf bytes.Buffer + + if v != nil { + m := v.(map[string]interface{}) + if m["provision_vm_agent"] != nil { + buf.WriteString(fmt.Sprintf("%t-", m["provision_vm_agent"].(bool))) + } + if m["enable_automatic_upgrades"] != nil { + buf.WriteString(fmt.Sprintf("%t-", m["enable_automatic_upgrades"].(bool))) + } + } + + return hashcode.String(buf.String()) +} + func resourceArmVirtualMachineStorageOsProfileLinuxConfigHash(v interface{}) int { var buf bytes.Buffer m := v.(map[string]interface{}) From 25875b8ee33855b4389763467a53f8f41aac2304 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 16 Oct 2017 15:26:39 +0100 Subject: [PATCH 17/23] Adding a test with multiple NIC's --- ..._arm_virtual_machine_managed_disks_test.go | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/azurerm/resource_arm_virtual_machine_managed_disks_test.go b/azurerm/resource_arm_virtual_machine_managed_disks_test.go index aa769d63d6d7..b9cbb0679ca2 100644 --- a/azurerm/resource_arm_virtual_machine_managed_disks_test.go +++ b/azurerm/resource_arm_virtual_machine_managed_disks_test.go @@ -7,6 +7,8 @@ import ( "strings" "testing" + "os" + "github.com/Azure/azure-sdk-for-go/arm/compute" "github.com/Azure/azure-sdk-for-go/arm/disk" "github.com/hashicorp/terraform/helper/acctest" @@ -288,6 +290,33 @@ func TestAccAzureRMVirtualMachine_windowsNoConfig(t *testing.T) { }) } +func TestAccAzureRMVirtualMachine_multipleNICs(t *testing.T) { + resourceName := "azurerm_virtual_machine.test" + ri := acctest.RandInt() + rs := acctest.RandString(5) + subscriptionId := os.Getenv("ARM_SUBSCRIPTION_ID") + prefix := fmt.Sprintf("/subscriptions/%s/resourceGroups/acctestRG-%d/providers/Microsoft.Network/networkInterfaces", subscriptionId, ri) + firstNicName := fmt.Sprintf("%s/acctni1-%d", prefix, ri) + secondNicName := fmt.Sprintf("%s/acctni2-%d", prefix, ri) + + config := testAccAzureRMVirtualMachine_multipleNICs(ri, rs, testLocation()) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMVirtualMachineDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "network_interface_ids.0", firstNicName), + resource.TestCheckResourceAttr(resourceName, "network_interface_ids.1", secondNicName), + ), + }, + }, + }) +} + func testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_explicit(rInt int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { @@ -1365,3 +1394,81 @@ resource "azurerm_virtual_machine" "test" { } `, rInt, location, rInt, rInt, rInt, rInt, rInt) } + +func testAccAzureRMVirtualMachine_multipleNICs(rInt int, rString string, 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_network_interface" "first" { + name = "acctni1-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + ip_configuration { + name = "testconfiguration1" + subnet_id = "${azurerm_subnet.test.id}" + private_ip_address_allocation = "dynamic" + } +} + +resource "azurerm_network_interface" "second" { + name = "acctni2-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + ip_configuration { + name = "testconfiguration1" + subnet_id = "${azurerm_subnet.test.id}" + private_ip_address_allocation = "dynamic" + } +} + +resource "azurerm_virtual_machine" "test" { + name = "acctvm%s" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + network_interface_ids = ["${azurerm_network_interface.first.id}", "${azurerm_network_interface.second.id}"] + primary_network_interface_id = "${azurerm_network_interface.first.id}" + vm_size = "Standard_F1" + + storage_image_reference { + publisher = "MicrosoftWindowsServer" + offer = "WindowsServer" + sku = "2012-Datacenter" + version = "latest" + } + + storage_os_disk { + name = "myosdisk1" + caching = "ReadWrite" + create_option = "FromImage" + managed_disk_type = "Standard_LRS" + } + + os_profile { + computer_name = "acctvm%s" + admin_username = "testadmin" + admin_password = "Password1234!" + } + + os_profile_windows_config {} +} +`, rInt, location, rInt, rInt, rInt, rInt, rString, rString) +} From 53f27e41dcf9b7af27e124112e57718b94bcb652 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 16 Oct 2017 16:01:25 +0100 Subject: [PATCH 18/23] Switching Storage Image Ref back to a set / setting the OS type --- azurerm/resource_arm_virtual_machine.go | 34 +++++++++++++++++-------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/azurerm/resource_arm_virtual_machine.go b/azurerm/resource_arm_virtual_machine.go index 22102c45fa21..89feaa4a5e69 100644 --- a/azurerm/resource_arm_virtual_machine.go +++ b/azurerm/resource_arm_virtual_machine.go @@ -88,7 +88,7 @@ func resourceArmVirtualMachine() *schema.Resource { }, "storage_image_reference": { - Type: schema.TypeList, + Type: schema.TypeSet, Optional: true, Computed: true, ForceNew: true, @@ -127,6 +127,7 @@ func resourceArmVirtualMachine() *schema.Resource { }, }, }, + Set: resourceArmVirtualMachineStorageImageReferenceHash, }, "storage_os_disk": { @@ -653,7 +654,7 @@ func resourceArmVirtualMachineRead(d *schema.ResourceData, meta interface{}) err d.Set("vm_size", resp.VirtualMachineProperties.HardwareProfile.VMSize) if resp.VirtualMachineProperties.StorageProfile.ImageReference != nil { - if err := d.Set("storage_image_reference", flattenAzureRmVirtualMachineImageReference(resp.VirtualMachineProperties.StorageProfile.ImageReference)); err != nil { + if err := d.Set("storage_image_reference", schema.NewSet(resourceArmVirtualMachineStorageImageReferenceHash, flattenAzureRmVirtualMachineImageReference(resp.VirtualMachineProperties.StorageProfile.ImageReference))); err != nil { return fmt.Errorf("[DEBUG] Error setting Virtual Machine Storage Image Reference error: %#v", err) } } @@ -1043,6 +1044,7 @@ func flattenAzureRmVirtualMachineOsDisk(disk *compute.OSDisk) []interface{} { if disk.DiskSizeGB != nil { result["disk_size_gb"] = *disk.DiskSizeGB } + result["os_type"] = string(disk.OsType) return []interface{}{result} } @@ -1347,7 +1349,7 @@ func expandAzureRmVirtualMachineDiagnosticsProfile(d *schema.ResourceData) *comp } func expandAzureRmVirtualMachineImageReference(d *schema.ResourceData) (*compute.ImageReference, error) { - storageImageRefs := d.Get("storage_image_reference").([]interface{}) + storageImageRefs := d.Get("storage_image_reference").(*schema.Set).List() storageImageRef := storageImageRefs[0].(map[string]interface{}) imageID := storageImageRef["id"].(string) @@ -1456,13 +1458,7 @@ func expandAzureRmVirtualMachineOsDisk(d *schema.ResourceData) (*compute.OSDisk, } if v := config["os_type"].(string); v != "" { - if v == "linux" { - osDisk.OsType = compute.Linux - } else if v == "windows" { - osDisk.OsType = compute.Windows - } else { - return nil, fmt.Errorf("[ERROR] os_type must be 'linux' or 'windows'") - } + osDisk.OsType = compute.OperatingSystemTypes(v) } if v := config["caching"].(string); v != "" { @@ -1532,3 +1528,21 @@ func resourceArmVirtualMachineStorageOsProfileLinuxConfigHash(v interface{}) int return hashcode.String(buf.String()) } + +func resourceArmVirtualMachineStorageImageReferenceHash(v interface{}) int { + var buf bytes.Buffer + m := v.(map[string]interface{}) + if m["publisher"] != nil { + buf.WriteString(fmt.Sprintf("%s-", m["publisher"].(string))) + } + if m["offer"] != nil { + buf.WriteString(fmt.Sprintf("%s-", m["offer"].(string))) + } + if m["sku"] != nil { + buf.WriteString(fmt.Sprintf("%s-", m["sku"].(string))) + } + if m["id"] != nil { + buf.WriteString(fmt.Sprintf("%s-", m["id"].(string))) + } + return hashcode.String(buf.String()) +} From a4c40b0cfa6478a0bb7a9521d9e82dfff6dcb84d Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 16 Oct 2017 19:19:43 +0100 Subject: [PATCH 19/23] Adding a test covering disk renumbering. Fixes #20 --- ..._arm_virtual_machine_managed_disks_test.go | 241 ++++++++++++++++++ 1 file changed, 241 insertions(+) diff --git a/azurerm/resource_arm_virtual_machine_managed_disks_test.go b/azurerm/resource_arm_virtual_machine_managed_disks_test.go index b9cbb0679ca2..6359516888fa 100644 --- a/azurerm/resource_arm_virtual_machine_managed_disks_test.go +++ b/azurerm/resource_arm_virtual_machine_managed_disks_test.go @@ -317,6 +317,37 @@ func TestAccAzureRMVirtualMachine_multipleNICs(t *testing.T) { }) } +func TestAccAzureRMVirtualMachine_reorderedDisks(t *testing.T) { + var beforeVm compute.VirtualMachine + //var beforeVm, afterVm compute.VirtualMachine + resourceName := "azurerm_virtual_machine.test" + ri := acctest.RandInt() + config := testAccAzureRMVirtualMachine_reorderedDisksBefore(ri, testLocation()) + //updatedConfig := testAccAzureRMVirtualMachine_reorderedDisksAfter(ri, testLocation()) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMVirtualMachineDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMVirtualMachineExists(resourceName, &beforeVm), + ), + }, + /* + { + Config: updatedConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMVirtualMachineExists(resourceName, &afterVm), + ), + }, + */ + }, + }) +} + func testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_explicit(rInt int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { @@ -1472,3 +1503,213 @@ resource "azurerm_virtual_machine" "test" { } `, rInt, location, rInt, rInt, rInt, rInt, rString, rString) } + +func testAccAzureRMVirtualMachine_reorderedDisksBefore(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_network_interface" "test" { + name = "acctni-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + ip_configuration { + name = "testconfiguration1" + subnet_id = "${azurerm_subnet.test.id}" + private_ip_address_allocation = "dynamic" + } +} + +resource "azurerm_managed_disk" "first" { + name = "acctestdisk-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + storage_account_type = "Standard_LRS" + create_option = "Empty" + disk_size_gb = "10" +} + +resource "azurerm_managed_disk" "second" { + name = "acctestdisk2-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + storage_account_type = "Standard_LRS" + create_option = "Empty" + disk_size_gb = "20" +} + +resource "azurerm_virtual_machine" "test" { + name = "acctvm-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + network_interface_ids = ["${azurerm_network_interface.test.id}"] + vm_size = "Standard_F2" + + storage_image_reference { + publisher = "Canonical" + offer = "UbuntuServer" + sku = "16.04-LTS" + version = "latest" + } + + storage_os_disk { + name = "osdisk%d" + caching = "ReadWrite" + create_option = "FromImage" + } + + storage_data_disk { + name = "${azurerm_managed_disk.first.name}" + managed_disk_id = "${azurerm_managed_disk.first.id}" + create_option = "Attach" + lun = 1 + disk_size_gb = "${azurerm_managed_disk.first.disk_size_gb}" + } + + storage_data_disk { + name = "${azurerm_managed_disk.second.name}" + managed_disk_id = "${azurerm_managed_disk.second.id}" + create_option = "Attach" + lun = 10 + disk_size_gb = "${azurerm_managed_disk.second.disk_size_gb}" + } + + os_profile { + computer_name = "hn%d" + admin_username = "testadmin" + admin_password = "Password1234!" + } + + os_profile_linux_config { + disable_password_authentication = false + } + + tags { + environment = "Production" + cost-center = "Ops" + } +} +`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt) +} + +func testAccAzureRMVirtualMachine_reorderedDisksAfter(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_network_interface" "test" { + name = "acctni-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + ip_configuration { + name = "testconfiguration1" + subnet_id = "${azurerm_subnet.test.id}" + private_ip_address_allocation = "dynamic" + } +} + +resource "azurerm_managed_disk" "first" { + name = "acctestdisk-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + storage_account_type = "Standard_LRS" + create_option = "Empty" + disk_size_gb = "10" +} + +resource "azurerm_managed_disk" "second" { + name = "acctestdisk2-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + storage_account_type = "Standard_LRS" + create_option = "Empty" + disk_size_gb = "20" +} + +resource "azurerm_virtual_machine" "test" { + name = "acctvm-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + network_interface_ids = ["${azurerm_network_interface.test.id}"] + vm_size = "Standard_F2" + + storage_image_reference { + publisher = "Canonical" + offer = "UbuntuServer" + sku = "16.04-LTS" + version = "latest" + } + + storage_os_disk { + name = "osdisk%d" + caching = "ReadWrite" + create_option = "FromImage" + } + + storage_data_disk { + name = "${azurerm_managed_disk.second.name}" + managed_disk_id = "${azurerm_managed_disk.second.id}" + create_option = "Attach" + lun = 1 + disk_size_gb = "${azurerm_managed_disk.second.disk_size_gb}" + } + + storage_data_disk { + name = "${azurerm_managed_disk.first.name}" + managed_disk_id = "${azurerm_managed_disk.first.id}" + create_option = "Attach" + lun = 10 + disk_size_gb = "${azurerm_managed_disk.first.disk_size_gb}" + } + + os_profile { + computer_name = "hn%d" + admin_username = "testadmin" + admin_password = "Password1234!" + } + + os_profile_linux_config { + disable_password_authentication = false + } + + tags { + environment = "Production" + cost-center = "Ops" + } +} +`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt) +} From bfca0d677abcf1e33615c4ce9794e658fe26b4ad Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 16 Oct 2017 22:34:45 +0100 Subject: [PATCH 20/23] Checking for the Managed Disk's ID before accessing it. Fixes #81 --- azurerm/resource_arm_virtual_machine.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/azurerm/resource_arm_virtual_machine.go b/azurerm/resource_arm_virtual_machine.go index 89feaa4a5e69..4bd46ade215d 100644 --- a/azurerm/resource_arm_virtual_machine.go +++ b/azurerm/resource_arm_virtual_machine.go @@ -1037,7 +1037,9 @@ func flattenAzureRmVirtualMachineOsDisk(disk *compute.OSDisk) []interface{} { } if disk.ManagedDisk != nil { result["managed_disk_type"] = string(disk.ManagedDisk.StorageAccountType) - result["managed_disk_id"] = *disk.ManagedDisk.ID + if disk.ManagedDisk.ID != nil { + result["managed_disk_id"] = *disk.ManagedDisk.ID + } } result["create_option"] = disk.CreateOption result["caching"] = disk.Caching From 309c22b48b0b81ff7f6b72bb925130ca6c1ad8e4 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 16 Oct 2017 22:46:24 +0100 Subject: [PATCH 21/23] Checking to see if the os_profile is nil before determining the hash code. Fixes #72 --- azurerm/resource_arm_virtual_machine.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/azurerm/resource_arm_virtual_machine.go b/azurerm/resource_arm_virtual_machine.go index 4bd46ade215d..3cb883856a92 100644 --- a/azurerm/resource_arm_virtual_machine.go +++ b/azurerm/resource_arm_virtual_machine.go @@ -1501,9 +1501,13 @@ func findStorageAccountResourceGroup(meta interface{}, storageAccountName string func resourceArmVirtualMachineStorageOsProfileHash(v interface{}) int { var buf bytes.Buffer - m := v.(map[string]interface{}) - buf.WriteString(fmt.Sprintf("%s-", m["admin_username"].(string))) - buf.WriteString(fmt.Sprintf("%s-", m["computer_name"].(string))) + + if v != nil { + m := v.(map[string]interface{}) + buf.WriteString(fmt.Sprintf("%s-", m["admin_username"].(string))) + buf.WriteString(fmt.Sprintf("%s-", m["computer_name"].(string))) + } + return hashcode.String(buf.String()) } From 962459bf85d5cda8cd9797029e7bd5cc243f4a59 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Tue, 17 Oct 2017 10:37:27 +0100 Subject: [PATCH 22/23] Removing the unused test --- ..._arm_virtual_machine_managed_disks_test.go | 241 ------------------ 1 file changed, 241 deletions(-) diff --git a/azurerm/resource_arm_virtual_machine_managed_disks_test.go b/azurerm/resource_arm_virtual_machine_managed_disks_test.go index 6359516888fa..b9cbb0679ca2 100644 --- a/azurerm/resource_arm_virtual_machine_managed_disks_test.go +++ b/azurerm/resource_arm_virtual_machine_managed_disks_test.go @@ -317,37 +317,6 @@ func TestAccAzureRMVirtualMachine_multipleNICs(t *testing.T) { }) } -func TestAccAzureRMVirtualMachine_reorderedDisks(t *testing.T) { - var beforeVm compute.VirtualMachine - //var beforeVm, afterVm compute.VirtualMachine - resourceName := "azurerm_virtual_machine.test" - ri := acctest.RandInt() - config := testAccAzureRMVirtualMachine_reorderedDisksBefore(ri, testLocation()) - //updatedConfig := testAccAzureRMVirtualMachine_reorderedDisksAfter(ri, testLocation()) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testCheckAzureRMVirtualMachineDestroy, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists(resourceName, &beforeVm), - ), - }, - /* - { - Config: updatedConfig, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists(resourceName, &afterVm), - ), - }, - */ - }, - }) -} - func testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_explicit(rInt int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { @@ -1503,213 +1472,3 @@ resource "azurerm_virtual_machine" "test" { } `, rInt, location, rInt, rInt, rInt, rInt, rString, rString) } - -func testAccAzureRMVirtualMachine_reorderedDisksBefore(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_network_interface" "test" { - name = "acctni-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - ip_configuration { - name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" - private_ip_address_allocation = "dynamic" - } -} - -resource "azurerm_managed_disk" "first" { - name = "acctestdisk-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_type = "Standard_LRS" - create_option = "Empty" - disk_size_gb = "10" -} - -resource "azurerm_managed_disk" "second" { - name = "acctestdisk2-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_type = "Standard_LRS" - create_option = "Empty" - disk_size_gb = "20" -} - -resource "azurerm_virtual_machine" "test" { - name = "acctvm-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - network_interface_ids = ["${azurerm_network_interface.test.id}"] - vm_size = "Standard_F2" - - storage_image_reference { - publisher = "Canonical" - offer = "UbuntuServer" - sku = "16.04-LTS" - version = "latest" - } - - storage_os_disk { - name = "osdisk%d" - caching = "ReadWrite" - create_option = "FromImage" - } - - storage_data_disk { - name = "${azurerm_managed_disk.first.name}" - managed_disk_id = "${azurerm_managed_disk.first.id}" - create_option = "Attach" - lun = 1 - disk_size_gb = "${azurerm_managed_disk.first.disk_size_gb}" - } - - storage_data_disk { - name = "${azurerm_managed_disk.second.name}" - managed_disk_id = "${azurerm_managed_disk.second.id}" - create_option = "Attach" - lun = 10 - disk_size_gb = "${azurerm_managed_disk.second.disk_size_gb}" - } - - os_profile { - computer_name = "hn%d" - admin_username = "testadmin" - admin_password = "Password1234!" - } - - os_profile_linux_config { - disable_password_authentication = false - } - - tags { - environment = "Production" - cost-center = "Ops" - } -} -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt) -} - -func testAccAzureRMVirtualMachine_reorderedDisksAfter(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_network_interface" "test" { - name = "acctni-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - ip_configuration { - name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" - private_ip_address_allocation = "dynamic" - } -} - -resource "azurerm_managed_disk" "first" { - name = "acctestdisk-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_type = "Standard_LRS" - create_option = "Empty" - disk_size_gb = "10" -} - -resource "azurerm_managed_disk" "second" { - name = "acctestdisk2-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_type = "Standard_LRS" - create_option = "Empty" - disk_size_gb = "20" -} - -resource "azurerm_virtual_machine" "test" { - name = "acctvm-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - network_interface_ids = ["${azurerm_network_interface.test.id}"] - vm_size = "Standard_F2" - - storage_image_reference { - publisher = "Canonical" - offer = "UbuntuServer" - sku = "16.04-LTS" - version = "latest" - } - - storage_os_disk { - name = "osdisk%d" - caching = "ReadWrite" - create_option = "FromImage" - } - - storage_data_disk { - name = "${azurerm_managed_disk.second.name}" - managed_disk_id = "${azurerm_managed_disk.second.id}" - create_option = "Attach" - lun = 1 - disk_size_gb = "${azurerm_managed_disk.second.disk_size_gb}" - } - - storage_data_disk { - name = "${azurerm_managed_disk.first.name}" - managed_disk_id = "${azurerm_managed_disk.first.id}" - create_option = "Attach" - lun = 10 - disk_size_gb = "${azurerm_managed_disk.first.disk_size_gb}" - } - - os_profile { - computer_name = "hn%d" - admin_username = "testadmin" - admin_password = "Password1234!" - } - - os_profile_linux_config { - disable_password_authentication = false - } - - tags { - environment = "Production" - cost-center = "Ops" - } -} -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt) -} From fcb3c0baf5bc76c0ecbdd62020a3245303c9bf05 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Tue, 17 Oct 2017 12:18:10 +0100 Subject: [PATCH 23/23] Making `enable_blob_encryption` and `enable_file_encryption` computed --- azurerm/resource_arm_storage_account.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/azurerm/resource_arm_storage_account.go b/azurerm/resource_arm_storage_account.go index 652c2205ff7e..d23ca9ed60e2 100644 --- a/azurerm/resource_arm_storage_account.go +++ b/azurerm/resource_arm_storage_account.go @@ -128,11 +128,13 @@ func resourceArmStorageAccount() *schema.Resource { "enable_blob_encryption": { Type: schema.TypeBool, Optional: true, + Computed: true, }, "enable_file_encryption": { Type: schema.TypeBool, Optional: true, + Computed: true, }, "enable_https_traffic_only": {