Skip to content

Commit

Permalink
Merge pull request #7157 from terraform-providers/b/ase-app-name-avai…
Browse files Browse the repository at this point in the history
…lability

fix scope of name availability check in ASE hosted app services
  • Loading branch information
jackofallops committed Jun 2, 2020
2 parents 780adf2 + 1354593 commit 84094f0
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 1 deletion.
15 changes: 14 additions & 1 deletion azurerm/internal/services/web/resource_arm_app_service.go
Expand Up @@ -192,6 +192,7 @@ func resourceArmAppService() *schema.Resource {

func resourceArmAppServiceCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).Web.AppServicesClient
aspClient := meta.(*clients.Client).Web.AppServicePlansClient
ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d)
defer cancel()

Expand All @@ -217,6 +218,19 @@ func resourceArmAppServiceCreate(d *schema.ResourceData, meta interface{}) error
Name: utils.String(name),
Type: web.CheckNameResourceTypesMicrosoftWebsites,
}

appServicePlanId := d.Get("app_service_plan_id").(string)
aspID, err := ParseAppServicePlanID(appServicePlanId)
if err != nil {
return err
}
// Check if App Service Plan is part of ASE
// If so, the name needs updating to <app name>.<ASE name>.appserviceenvironment.net and FQDN setting true for name availability check
aspDetails, _ := aspClient.Get(ctx, aspID.ResourceGroup, aspID.Name)
if aspDetails.HostingEnvironmentProfile != nil {
availabilityRequest.Name = utils.String(fmt.Sprintf("%s.%s.appserviceenvironment.net", name, aspID.Name))
availabilityRequest.IsFqdn = utils.Bool(true)
}
available, err := client.CheckNameAvailability(ctx, availabilityRequest)
if err != nil {
return fmt.Errorf("Error checking if the name %q was available: %+v", name, err)
Expand All @@ -227,7 +241,6 @@ func resourceArmAppServiceCreate(d *schema.ResourceData, meta interface{}) error
}

location := azure.NormalizeLocation(d.Get("location").(string))
appServicePlanId := d.Get("app_service_plan_id").(string)
enabled := d.Get("enabled").(bool)
httpsOnly := d.Get("https_only").(bool)
t := d.Get("tags").(map[string]interface{})
Expand Down
Expand Up @@ -1674,6 +1674,24 @@ func TestAccAzureRMAppService_basicWindowsContainer(t *testing.T) {
})
}

func TestAccAzureRMAppService_aseScopeNameCheck(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_app_service", "test")
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMAppServiceDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMAppService_inAppServiceEnvironment(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAppServiceExists(data.ResourceName),
),
},
data.ImportStep(),
},
})
}

func testCheckAzureRMAppServiceDestroy(s *terraform.State) error {
client := acceptance.AzureProvider.Meta().(*clients.Client).Web.AppServicesClient
ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext
Expand Down Expand Up @@ -4381,3 +4399,63 @@ resource "azurerm_app_service" "test" {
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger)
}

func testAccAzureRMAppService_inAppServiceEnvironment(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_virtual_network" "test" {
name = "acctest-vnet-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
address_space = ["10.0.0.0/16"]
}
resource "azurerm_subnet" "ase" {
name = "asesubnet"
resource_group_name = azurerm_resource_group.test.name
virtual_network_name = azurerm_virtual_network.test.name
address_prefix = "10.0.1.0/24"
}
resource "azurerm_subnet" "gateway" {
name = "gatewaysubnet"
resource_group_name = azurerm_resource_group.test.name
virtual_network_name = azurerm_virtual_network.test.name
address_prefix = "10.0.2.0/24"
}
resource "azurerm_app_service_environment" "test" {
name = "acctest-ase-%d"
subnet_id = azurerm_subnet.ase.id
}
resource "azurerm_app_service_plan" "test" {
name = "acctest-ASP-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
app_service_environment_id = azurerm_app_service_environment.test.id
sku {
tier = "Isolated"
size = "I1"
capacity = 1
}
}
resource "azurerm_app_service" "test" {
name = "acctestAS-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
app_service_plan_id = azurerm_app_service_plan.test.id
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

0 comments on commit 84094f0

Please sign in to comment.