Skip to content

Commit

Permalink
Returning a more helpful error message if the function app already ex…
Browse files Browse the repository at this point in the history
…ists
  • Loading branch information
tombuildsstuff committed Mar 28, 2018
1 parent 70fc814 commit cecd09f
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion azurerm/resource_arm_function_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,25 @@ func resourceArmFunctionApp() *schema.Resource {

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

log.Printf("[INFO] preparing arguments for AzureRM Function App 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 Function App 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)
kind := "functionapp"
Expand Down Expand Up @@ -194,7 +209,6 @@ func resourceArmFunctionAppCreate(d *schema.ResourceData, meta interface{}) erro
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
Expand Down

0 comments on commit cecd09f

Please sign in to comment.