Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_frontdoor, azurerm_linux_virtual_machine, azurerm_windows_virtual_machine, azurerm_ssh_public_key - Fix nil panic by throwing error when the resource was missing during update #21975

Merged
merged 2 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions internal/services/compute/linux_virtual_machine_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -956,10 +956,6 @@ func resourceLinuxVirtualMachineUpdate(d *pluginsdk.ResourceData, meta interface
log.Printf("[DEBUG] Retrieving Linux Virtual Machine %q (Resource Group %q)..", id.Name, id.ResourceGroup)
existing, err := client.Get(ctx, id.ResourceGroup, id.Name, compute.InstanceViewTypesUserData)
if err != nil {
if utils.ResponseWasNotFound(existing.Response) {
return nil
}

return fmt.Errorf("retrieving Linux Virtual Machine %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
}

Expand Down
6 changes: 1 addition & 5 deletions internal/services/compute/ssh_public_key_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,8 @@ func resourceSshPublicKeyUpdate(d *pluginsdk.ResourceData, meta interface{}) err
return err
}

existing, err := client.Get(ctx, *id)
_, err = client.Get(ctx, *id)
if err != nil {
if response.WasNotFound(existing.HttpResponse) {
return nil
}

return fmt.Errorf("retrieving %s: %+v", *id, err)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1006,10 +1006,6 @@ func resourceWindowsVirtualMachineUpdate(d *pluginsdk.ResourceData, meta interfa
log.Printf("[DEBUG] Retrieving Windows Virtual Machine %q (Resource Group %q)..", id.Name, id.ResourceGroup)
existing, err := client.Get(ctx, id.ResourceGroup, id.Name, compute.InstanceViewTypesUserData)
if err != nil {
if utils.ResponseWasNotFound(existing.Response) {
return nil
}

return fmt.Errorf("retrieving Windows Virtual Machine %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
}

Expand Down
8 changes: 3 additions & 5 deletions internal/services/frontdoor/frontdoor_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,16 @@ func resourceFrontDoorUpdate(d *pluginsdk.ResourceData, meta interface{}) error
// remove in 3.0
// due to a change in the RP, if a Frontdoor exists in a location other than 'Global' it may continue to
// exist in that location, if this is a brand new Frontdoor it must be created in the 'Global' location
location := "Global"
cfgLocation, hasLocation := d.GetOk("location")
var location string

exists, err := client.Get(ctx, id)
if err != nil || exists.Model == nil {
if !response.WasNotFound(exists.HttpResponse) {
return fmt.Errorf("locating %s: %+v", id, err)
}
return fmt.Errorf("locating %s: %+v", id, err)
} else {
location = azure.NormalizeLocation(*exists.Model.Location)
}

cfgLocation, hasLocation := d.GetOk("location")
if hasLocation {
if location != azure.NormalizeLocation(cfgLocation) {
return fmt.Errorf("the Front Door %q (Resource Group %q) already exists in %q and cannot be moved to the %q location", name, resourceGroup, location, cfgLocation)
Expand Down