diff --git a/azurerm/resource_arm_app_service.go b/azurerm/resource_arm_app_service.go index f07527b021fa..83f92e81b6ae 100644 --- a/azurerm/resource_arm_app_service.go +++ b/azurerm/resource_arm_app_service.go @@ -287,10 +287,24 @@ func resourceArmAppService() *schema.Resource { func resourceArmAppServiceCreate(d *schema.ResourceData, meta interface{}) error { client := meta.(*ArmClient).appServicesClient + ctx := meta.(*ArmClient).StopContext log.Printf("[INFO] preparing arguments for AzureRM App Service creation.") name := d.Get("name").(string) + availabilityRequest := web.ResourceNameAvailabilityRequest{ + Name: utils.String(name), + Type: web.CheckNameResourceTypesMicrosoftWebsites, + } + available, err := client.CheckNameAvailability(ctx, availabilityRequest) + if err != nil { + return fmt.Errorf("Error checking if the name %q was available: %+v", name, err) + } + + if !*available.NameAvailable { + return fmt.Errorf("The name %q used for the App Service needs to be globally unique and isn't available: %s", name, *available.Message) + } + resGroup := d.Get("resource_group_name").(string) location := d.Get("location").(string) appServicePlanId := d.Get("app_service_plan_id").(string) @@ -319,7 +333,6 @@ func resourceArmAppServiceCreate(d *schema.ResourceData, meta interface{}) error forceDNSRegistration := false skipCustomDomainVerification := true ttlInSeconds := "60" - ctx := meta.(*ArmClient).StopContext createFuture, err := client.CreateOrUpdate(ctx, resGroup, name, siteEnvelope, &skipDNSRegistration, &skipCustomDomainVerification, &forceDNSRegistration, ttlInSeconds) if err != nil { return err