provider/azurerm: Error creating `azurerm_virtual_machine` data_disk

The `storage_data_disk` was trying to use vhd_url rather than vhd_uri.
This was causing an error on creating a new data_disk as part of a VM

Also added validation as data_disks can only be 1 - 1023 GB in size
This commit is contained in:
stack72 2016-05-09 00:35:49 +01:00
parent 26ffa0452d
commit 8dc47ac799
1 changed files with 23 additions and 16 deletions

View File

@ -144,9 +144,8 @@ func resourceArmVirtualMachine() *schema.Resource {
}, },
"storage_data_disk": &schema.Schema{ "storage_data_disk": &schema.Schema{
Type: schema.TypeSet, Type: schema.TypeList,
Optional: true, Optional: true,
Computed: true,
Elem: &schema.Resource{ Elem: &schema.Resource{
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"name": &schema.Schema{ "name": &schema.Schema{
@ -167,6 +166,14 @@ func resourceArmVirtualMachine() *schema.Resource {
"disk_size_gb": &schema.Schema{ "disk_size_gb": &schema.Schema{
Type: schema.TypeInt, Type: schema.TypeInt,
Required: true, Required: true,
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
value := v.(int)
if value < 1 || value > 1023 {
errors = append(errors, fmt.Errorf(
"The `disk_size_gb` can only be between 1 and 1023"))
}
return
},
}, },
"lun": &schema.Schema{ "lun": &schema.Schema{
@ -175,7 +182,6 @@ func resourceArmVirtualMachine() *schema.Resource {
}, },
}, },
}, },
Set: resourceArmVirtualMachineStorageDataDiskHash,
}, },
"os_profile": &schema.Schema{ "os_profile": &schema.Schema{
@ -420,10 +426,11 @@ func resourceArmVirtualMachineCreate(d *schema.ResourceData, meta interface{}) e
log.Printf("[DEBUG] Waiting for Virtual Machine (%s) to become available", name) log.Printf("[DEBUG] Waiting for Virtual Machine (%s) to become available", name)
stateConf := &resource.StateChangeConf{ stateConf := &resource.StateChangeConf{
Pending: []string{"Creating", "Updating"}, Pending: []string{"Creating", "Updating"},
Target: []string{"Succeeded"}, Target: []string{"Succeeded"},
Refresh: virtualMachineStateRefreshFunc(client, resGroup, name), Refresh: virtualMachineStateRefreshFunc(client, resGroup, name),
Timeout: 10 * time.Minute, Timeout: 20 * time.Minute,
MinTimeout: 10 * time.Second,
} }
if _, err := stateConf.WaitForState(); err != nil { if _, err := stateConf.WaitForState(); err != nil {
return fmt.Errorf("Error waiting for Virtual Machine (%s) to become available: %s", name, err) return fmt.Errorf("Error waiting for Virtual Machine (%s) to become available: %s", name, err)
@ -663,17 +670,17 @@ func flattenAzureRmVirtualMachineOsProfileSecrets(secrets *[]compute.VaultSecret
return result return result
} }
func flattenAzureRmVirtualMachineDataDisk(disks *[]compute.DataDisk) []map[string]interface{} { func flattenAzureRmVirtualMachineDataDisk(disks *[]compute.DataDisk) interface{} {
result := make([]map[string]interface{}, 0, len(*disks)) result := make([]interface{}, len(*disks))
for _, i := range *disks { for i, disk := range *disks {
l := make(map[string]interface{}) l := make(map[string]interface{})
l["name"] = *i.Name l["name"] = *disk.Name
l["vhd_url"] = *i.Vhd.URI l["vhd_uri"] = *disk.Vhd.URI
l["create_option"] = i.CreateOption l["create_option"] = disk.CreateOption
l["disk_size_gb"] = *i.DiskSizeGB l["disk_size_gb"] = *disk.DiskSizeGB
l["lun"] = *i.Lun l["lun"] = *disk.Lun
result = append(result, l) result[i] = l
} }
return result return result
} }