Skip to content

Commit

Permalink
Adding a check to see if the App Service Name is unique
Browse files Browse the repository at this point in the history
  • Loading branch information
tombuildsstuff committed Mar 28, 2018
1 parent cecd09f commit 8478030
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion azurerm/resource_arm_app_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8478030

Please sign in to comment.