Skip to content

Commit

Permalink
Merge pull request #1037 from terraform-providers/app-function-app-ch…
Browse files Browse the repository at this point in the history
…eck-name

App Service/Function App - returning a helpful error when the name is in use
  • Loading branch information
tombuildsstuff authored Mar 28, 2018
2 parents 70fc814 + 8478030 commit 3fe766b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
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
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 3fe766b

Please sign in to comment.