Skip to content

Commit

Permalink
Avoid panic if RG or ASE do not exist when creating an App Service (h…
Browse files Browse the repository at this point in the history
…ashicorp#12518)

Since the `Get` function of the `AppServices` client does not return an
error if the resource is not found, the code behaves as if everything is
fine and attempts to access fields of a struct that have not been
un-marshalled, since the API responded with 404.
  • Loading branch information
koikonom authored and yupwei68 committed Jul 26, 2021
1 parent 09d8697 commit 6630dc8
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions azurerm/internal/services/web/app_service_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,9 @@ func resourceAppServiceCreate(d *pluginsdk.ResourceData, meta interface{}) error
// Check if App Service Plan is part of ASE
// If so, the name needs updating to <app name>.<ASE name>.appserviceenvironment.net and FQDN setting true for name availability check
aspDetails, err := aspClient.Get(ctx, aspID.ResourceGroup, aspID.ServerfarmName)
if err != nil {
return fmt.Errorf("App Service Environment %q (Resource Group %q) does not exist", aspID.ServerfarmName, aspID.ResourceGroup)
// 404 is incorrectly being considered an acceptable response, issue tracked at https://github.com/Azure/azure-sdk-for-go/issues/15002
if err != nil || utils.ResponseWasNotFound(aspDetails.Response) {
return fmt.Errorf("App Service Environment %q or Resource Group %q does not exist", aspID.ServerfarmName, aspID.ResourceGroup)
}
if aspDetails.HostingEnvironmentProfile != nil {
availabilityRequest.Name = utils.String(fmt.Sprintf("%s.%s.appserviceenvironment.net", name, *aspDetails.HostingEnvironmentProfile.Name))
Expand Down

0 comments on commit 6630dc8

Please sign in to comment.