Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App Service/Function App - returning a helpful error when the name is in use #1037

Merged
merged 2 commits into from
Mar 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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