Skip to content

Commit

Permalink
UPDATE add more information about power off
Browse files Browse the repository at this point in the history
  • Loading branch information
HappyTobi committed Jan 18, 2021
1 parent aa696c6 commit 9f20056
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1089,10 +1089,14 @@ func resourceLinuxVirtualMachineDelete(d *schema.ResourceData, meta interface{})
return fmt.Errorf("retrieving Linux Virtual Machine %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
}

// If the VM was in a Failed state we can skip porwering off
// If the VM was in a Failed state we can skip powering off, since that'll fail
if strings.EqualFold(*existing.ProvisioningState, "failed") {
log.Printf("[DEBUG] Powering Off Linux Virtual Machine was skipped because the VM was in %q state %q (Resource Group %q).", *existing.ProvisioningState, id.Name, id.ResourceGroup)
} else {
//ISSUE: 4920
// shutting down the Virtual Machine prior to removing it means users are no longer charged for some Azure resources
// thus this can be a large cost-saving when deleting larger instances
// https://docs.microsoft.com/en-us/azure/virtual-machines/states-lifecycle
log.Printf("[DEBUG] Powering Off Linux Virtual Machine %q (Resource Group %q)..", id.Name, id.ResourceGroup)
skipShutdown := !meta.(*clients.Client).Features.VirtualMachine.GracefulShutdown
powerOffFuture, err := client.PowerOff(ctx, id.ResourceGroup, id.Name, utils.Bool(skipShutdown))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1175,9 +1175,14 @@ func resourceWindowsVirtualMachineDelete(d *schema.ResourceData, meta interface{
return fmt.Errorf("retrieving Windows Virtual Machine %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
}

// If the VM was in a Failed state we can skip powering off, since that'll fail
if strings.EqualFold(*existing.ProvisioningState, "failed") {
log.Printf("[DEBUG] Powering Off Windows Virtual Machine was skipped because the VM was in %q state %q (Resource Group %q).", *existing.ProvisioningState, id.Name, id.ResourceGroup)
} else {
//ISSUE: 4920
// shutting down the Virtual Machine prior to removing it means users are no longer charged for some Azure resources
// thus this can be a large cost-saving when deleting larger instances
// https://docs.microsoft.com/en-us/azure/virtual-machines/states-lifecycle
log.Printf("[DEBUG] Powering Off Windows Virtual Machine %q (Resource Group %q)..", id.Name, id.ResourceGroup)
skipShutdown := !meta.(*clients.Client).Features.VirtualMachine.GracefulShutdown
powerOffFuture, err := client.PowerOff(ctx, id.ResourceGroup, id.Name, utils.Bool(skipShutdown))
Expand Down

0 comments on commit 9f20056

Please sign in to comment.