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": { diff --git a/azurerm/resource_arm_virtual_machine.go b/azurerm/resource_arm_virtual_machine.go index 6f630b12d1ea..3cb883856a92 100644 --- a/azurerm/resource_arm_virtual_machine.go +++ b/azurerm/resource_arm_virtual_machine.go @@ -1,12 +1,13 @@ package azurerm import ( - "bytes" "fmt" "log" "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" @@ -37,7 +38,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 +59,6 @@ func resourceArmVirtualMachine() *schema.Resource { }, }, }, - Set: resourceArmVirtualMachinePlanHash, }, "availability_set_id": { @@ -131,7 +131,7 @@ func resourceArmVirtualMachine() *schema.Resource { }, "storage_os_disk": { - Type: schema.TypeSet, + Type: schema.TypeList, Required: true, MaxItems: 1, Elem: &schema.Resource{ @@ -139,6 +139,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": { @@ -150,6 +156,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": { @@ -157,14 +167,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), @@ -191,11 +201,11 @@ func resourceArmVirtualMachine() *schema.Resource { "disk_size_gb": { Type: schema.TypeInt, Optional: true, + Computed: true, ValidateFunc: validateDiskSizeGB, }, }, }, - Set: resourceArmVirtualMachineStorageOsDiskHash, }, "delete_os_disk_on_termination": { @@ -220,18 +230,16 @@ func resourceArmVirtualMachine() *schema.Resource { }, "managed_disk_id": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - Computed: true, - ConflictsWith: []string{"storage_data_disk.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.vhd_uri"}, + Type: schema.TypeString, + Optional: true, + Computed: true, ValidateFunc: validation.StringInSlice([]string{ string(compute.PremiumLRS), string(compute.StandardLRS), @@ -272,12 +280,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": { @@ -414,7 +423,8 @@ func resourceArmVirtualMachine() *schema.Resource { }, }, }, - Set: resourceArmVirtualMachineStorageOsProfileWindowsConfigHash, + Set: resourceArmVirtualMachineStorageOsProfileWindowsConfigHash, + ConflictsWith: []string{"os_profile_linux_config"}, }, "os_profile_linux_config": { @@ -445,11 +455,12 @@ func resourceArmVirtualMachine() *schema.Resource { }, }, }, - Set: resourceArmVirtualMachineStorageOsProfileLinuxConfigHash, + Set: resourceArmVirtualMachineStorageOsProfileLinuxConfigHash, + ConflictsWith: []string{"os_profile_windows_config"}, }, "os_profile_secrets": { - Type: schema.TypeSet, + Type: schema.TypeList, Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -479,12 +490,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": { @@ -632,7 +642,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) } } @@ -649,7 +659,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) } @@ -665,13 +675,13 @@ 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) } } 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) } } @@ -835,76 +845,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{}) - 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{}) - buf.WriteString(fmt.Sprintf("%s-", m["admin_username"].(string))) - buf.WriteString(fmt.Sprintf("%s-", m["computer_name"].(string))) - 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{}) - buf.WriteString(fmt.Sprintf("%t-", m["disable_password_authentication"].(bool))) - - 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 @@ -946,16 +886,16 @@ 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) } 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, @@ -1006,12 +946,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} @@ -1097,19 +1037,22 @@ 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 if disk.DiskSizeGB != nil { result["disk_size_gb"] = *disk.DiskSizeGB } + result["os_type"] = string(disk.OsType) return []interface{}{result} } 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{}) @@ -1162,6 +1105,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 { @@ -1178,7 +1125,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 { @@ -1435,7 +1382,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)) @@ -1460,7 +1407,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{}) @@ -1513,13 +1460,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 != "" { @@ -1557,3 +1498,57 @@ func findStorageAccountResourceGroup(meta interface{}, storageAccountName string return id.ResourceGroup, nil } + +func resourceArmVirtualMachineStorageOsProfileHash(v interface{}) int { + var buf bytes.Buffer + + 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()) +} + +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{}) + buf.WriteString(fmt.Sprintf("%t-", m["disable_password_authentication"].(bool))) + + 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()) +} diff --git a/azurerm/resource_arm_virtual_machine_managed_disks_test.go b/azurerm/resource_arm_virtual_machine_managed_disks_test.go index aece85256717..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" @@ -187,7 +189,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"), }, }, }) @@ -256,6 +258,65 @@ 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_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" { @@ -1207,3 +1268,207 @@ 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) +} + +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) +} 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" { 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.