Skip to content

Commit

Permalink
WIP: handling data disks being attached independently
Browse files Browse the repository at this point in the history
  • Loading branch information
tombuildsstuff committed Jun 1, 2018
1 parent 21ba312 commit d239408
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions azurerm/resource_arm_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ var virtualMachineResourceName = "azurerm_virtual_machine"

func resourceArmVirtualMachine() *schema.Resource {
return &schema.Resource{
Create: resourceArmVirtualMachineCreate,
Create: resourceArmVirtualMachineCreateUpdate,
Read: resourceArmVirtualMachineRead,
Update: resourceArmVirtualMachineCreate,
Update: resourceArmVirtualMachineCreateUpdate,
Delete: resourceArmVirtualMachineDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
Expand Down Expand Up @@ -503,7 +503,7 @@ func resourceArmVirtualMachine() *schema.Resource {
}
}

func resourceArmVirtualMachineCreate(d *schema.ResourceData, meta interface{}) error {
func resourceArmVirtualMachineCreateUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).vmClient
ctx := meta.(*ArmClient).StopContext

Expand Down Expand Up @@ -532,12 +532,15 @@ func resourceArmVirtualMachineCreate(d *schema.ResourceData, meta interface{}) e
storageProfile.ImageReference = imageRef
}

if _, ok := d.GetOk("storage_data_disk"); ok {
dataDisks, err := expandAzureRmVirtualMachineDataDisk(d)
if err != nil {
return err
// this should handle the data disks being attached outside of this
if d.IsNewResource() || d.HasChange("storage_data_disk") {
if _, ok := d.GetOk("storage_data_disk"); ok {
dataDisks, err := expandAzureRmVirtualMachineDataDisk(d)
if err != nil {
return err
}
storageProfile.DataDisks = &dataDisks
}
storageProfile.DataDisks = &dataDisks
}

networkProfile := expandAzureRmVirtualMachineNetworkProfile(d)
Expand Down

0 comments on commit d239408

Please sign in to comment.