Skip to content

Commit

Permalink
provider/azurerm: Error creating azurerm_virtual_machine data_disk
Browse files Browse the repository at this point in the history
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
  • Loading branch information
stack72 committed May 8, 2016
1 parent 26ffa04 commit 07ba09b
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions builtin/providers/azurerm/resource_arm_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,8 @@ func resourceArmVirtualMachine() *schema.Resource {
},

"storage_data_disk": &schema.Schema{
Type: schema.TypeSet,
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Expand All @@ -165,8 +164,16 @@ func resourceArmVirtualMachine() *schema.Resource {
},

"disk_size_gb": &schema.Schema{
Type: schema.TypeInt,
Required: true,
Type: schema.TypeInt,
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{
Expand All @@ -175,7 +182,6 @@ func resourceArmVirtualMachine() *schema.Resource {
},
},
},
Set: resourceArmVirtualMachineStorageDataDiskHash,
},

"os_profile": &schema.Schema{
Expand Down Expand Up @@ -420,10 +426,11 @@ func resourceArmVirtualMachineCreate(d *schema.ResourceData, meta interface{}) e

log.Printf("[DEBUG] Waiting for Virtual Machine (%s) to become available", name)
stateConf := &resource.StateChangeConf{
Pending: []string{"Creating", "Updating"},
Target: []string{"Succeeded"},
Refresh: virtualMachineStateRefreshFunc(client, resGroup, name),
Timeout: 10 * time.Minute,
Pending: []string{"Creating", "Updating"},
Target: []string{"Succeeded"},
Refresh: virtualMachineStateRefreshFunc(client, resGroup, name),
Timeout: 20 * time.Minute,
MinTimeout: 10 * time.Second,
}
if _, err := stateConf.WaitForState(); err != nil {
return fmt.Errorf("Error waiting for Virtual Machine (%s) to become available: %s", name, err)
Expand Down Expand Up @@ -663,17 +670,17 @@ func flattenAzureRmVirtualMachineOsProfileSecrets(secrets *[]compute.VaultSecret
return result
}

func flattenAzureRmVirtualMachineDataDisk(disks *[]compute.DataDisk) []map[string]interface{} {
result := make([]map[string]interface{}, 0, len(*disks))
for _, i := range *disks {
func flattenAzureRmVirtualMachineDataDisk(disks *[]compute.DataDisk) interface{} {
result := make([]interface{}, len(*disks))
for i, disk := range *disks {
l := make(map[string]interface{})
l["name"] = *i.Name
l["vhd_url"] = *i.Vhd.URI
l["create_option"] = i.CreateOption
l["disk_size_gb"] = *i.DiskSizeGB
l["lun"] = *i.Lun
l["name"] = *disk.Name
l["vhd_uri"] = *disk.Vhd.URI
l["create_option"] = disk.CreateOption
l["disk_size_gb"] = *disk.DiskSizeGB
l["lun"] = *disk.Lun

result = append(result, l)
result[i] = l
}
return result
}
Expand Down

0 comments on commit 07ba09b

Please sign in to comment.