Skip to content

Commit

Permalink
Merge pull request #129 from echuvyrov/bug96vmssnameoptional
Browse files Browse the repository at this point in the history
[MS] Resolve #96, Making Name in VMSS storage_profile_os_disk Optional
  • Loading branch information
tombuildsstuff authored Jun 27, 2017
2 parents b39dae4 + 31d33a1 commit 53189ac
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 8 deletions.
18 changes: 11 additions & 7 deletions azurerm/resource_arm_virtual_machine_scale_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func resourceArmVirtualMachineScaleSet() *schema.Resource {
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Optional: true,
},

"image": {
Expand Down Expand Up @@ -1182,6 +1182,10 @@ func expandAzureRMVirtualMachineScaleSetsStorageProfileOsDisk(d *schema.Resource
createOption := osDiskConfig["create_option"].(string)
managedDiskType := osDiskConfig["managed_disk_type"].(string)

if managedDiskType == "" && name == "" {
return nil, fmt.Errorf("[ERROR] `name` must be set in `storage_profile_os_disk` for unmanaged disk")
}

osDisk := &compute.VirtualMachineScaleSetOSDisk{
Name: &name,
Caching: compute.CachingTypes(caching),
Expand All @@ -1207,13 +1211,13 @@ func expandAzureRMVirtualMachineScaleSetsStorageProfileOsDisk(d *schema.Resource
managedDisk := &compute.VirtualMachineScaleSetManagedDiskParameters{}

if managedDiskType != "" {
if name == "" {
osDisk.Name = nil
managedDisk.StorageAccountType = compute.StorageAccountTypes(managedDiskType)
osDisk.ManagedDisk = managedDisk
} else {
return nil, fmt.Errorf("[ERROR] Conflict between `name` and `managed_disk_type` on `storage_profile_os_disk` (please set name to blank)")
if name != "" {
return nil, fmt.Errorf("[ERROR] Conflict between `name` and `managed_disk_type` on `storage_profile_os_disk` (please remove name or set it to blank)")
}

osDisk.Name = nil
managedDisk.StorageAccountType = compute.StorageAccountTypes(managedDiskType)
osDisk.ManagedDisk = managedDisk
}

//BEGIN: code to be removed after GH-13016 is merged
Expand Down
80 changes: 80 additions & 0 deletions azurerm/resource_arm_virtual_machine_scale_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,24 @@ func TestAccAzureRMVirtualMachineScaleSet_basicLinux_managedDisk(t *testing.T) {
})
}

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

func TestAccAzureRMVirtualMachineScaleSet_basicLinux_disappears(t *testing.T) {
ri := acctest.RandInt()
config := fmt.Sprintf(testAccAzureRMVirtualMachineScaleSet_basic, ri, ri, ri, ri, ri, ri, ri, ri)
Expand Down Expand Up @@ -898,6 +916,68 @@ resource "azurerm_virtual_machine_scale_set" "test" {
}
`

var testAccAzureRMVirtualMachineScaleSet_basicLinux_managedDiskNoName = `
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "West US 2"
}
resource "azurerm_virtual_network" "test" {
name = "acctvn-%d"
address_space = ["10.0.0.0/16"]
location = "West US 2"
resource_group_name = "${azurerm_resource_group.test.name}"
}
resource "azurerm_subnet" "test" {
name = "acctsub-%d"
resource_group_name = "${azurerm_resource_group.test.name}"
virtual_network_name = "${azurerm_virtual_network.test.name}"
address_prefix = "10.0.2.0/24"
}
resource "azurerm_virtual_machine_scale_set" "test" {
name = "acctvmss-%d"
location = "West US 2"
resource_group_name = "${azurerm_resource_group.test.name}"
upgrade_policy_mode = "Manual"
sku {
name = "Standard_D1_v2"
tier = "Standard"
capacity = 2
}
os_profile {
computer_name_prefix = "testvm-%d"
admin_username = "myadmin"
admin_password = "Passwword1234"
}
network_profile {
name = "TestNetworkProfile-%d"
primary = true
ip_configuration {
name = "TestIPConfiguration"
subnet_id = "${azurerm_subnet.test.id}"
}
}
storage_profile_os_disk {
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}
storage_profile_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
}
`

var testAccAzureRMVirtualMachineScaleSetLoadbalancerTemplate = `
resource "azurerm_resource_group" "test" {
name = "acctestrg-%d"
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/virtual_machine_scale_set.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ The following arguments are supported:

`storage_profile_os_disk` supports the following:

* `name` - (Required) Specifies the disk name. Value must be blank (`""`) when `managed_disk_type` is specified.
* `name` - (Optional) Specifies the disk name. Must be specified when using unmanaged disk ('managed_disk_type' property not set).
* `vhd_containers` - (Optional) Specifies the vhd uri. Cannot be used when `image` or `managed_disk_type` is specified.
* `managed_disk_type` - (Optional) Specifies the type of managed disk to create. Value you must be either `Standard_LRS` or `Premium_LRS`. Cannot be used when `vhd_containers` or `image` is specified.
* `create_option` - (Required) Specifies how the virtual machine should be created. The only possible option is `FromImage`.
Expand Down

0 comments on commit 53189ac

Please sign in to comment.