diff --git a/azurerm/internal/services/web/resource_arm_app_service_plan.go b/azurerm/internal/services/web/resource_arm_app_service_plan.go index 66ac7d4f8e815..6e9d7e38421d7 100644 --- a/azurerm/internal/services/web/resource_arm_app_service_plan.go +++ b/azurerm/internal/services/web/resource_arm_app_service_plan.go @@ -264,17 +264,23 @@ func resourceArmAppServicePlanRead(d *schema.ResourceData, meta interface{}) err d.Set("kind", resp.Kind) if props := resp.AppServicePlanProperties; props != nil { - if profile := props.HostingEnvironmentProfile; profile != nil { - d.Set("app_service_environment_id", profile.ID) + appServiceEnvironmentId := "" + if props.HostingEnvironmentProfile != nil && props.HostingEnvironmentProfile.ID != nil { + appServiceEnvironmentId = *props.HostingEnvironmentProfile.ID } + d.Set("app_service_environment_id", appServiceEnvironmentId) + maximumNumberOfWorkers := 0 if props.MaximumNumberOfWorkers != nil { - d.Set("maximum_number_of_workers", int(*props.MaximumNumberOfWorkers)) + maximumNumberOfWorkers = int(*props.MaximumNumberOfWorkers) } + d.Set("maximum_number_of_workers", maximumNumberOfWorkers) + maximumElasticWorkerCount := 0 if props.MaximumElasticWorkerCount != nil { - d.Set("maximum_elastic_worker_count", int(*props.MaximumElasticWorkerCount)) + maximumElasticWorkerCount = int(*props.MaximumElasticWorkerCount) } + d.Set("maximum_elastic_worker_count", maximumElasticWorkerCount) d.Set("per_site_scaling", props.PerSiteScaling) d.Set("reserved", props.Reserved) diff --git a/azurerm/internal/services/web/tests/app_service_environment_resource_test.go b/azurerm/internal/services/web/tests/app_service_environment_resource_test.go index 0e0ef9687f649..9957bcbb06091 100644 --- a/azurerm/internal/services/web/tests/app_service_environment_resource_test.go +++ b/azurerm/internal/services/web/tests/app_service_environment_resource_test.go @@ -118,7 +118,7 @@ func TestAccAzureRMAppServiceEnvironment_withAppServicePlan(t *testing.T) { Config: testAccAzureRMAppServiceEnvironment_withAppServicePlan(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMAppServiceEnvironmentExists(data.ResourceName), - testCheckAppServicePlanMemberOfAppServiceEnvironment(data.ResourceName, aspData.ResourceName), + resource.TestCheckResourceAttrPair(data.ResourceName, "id", aspData.ResourceName, ""), ), }, data.ImportStep(), @@ -182,49 +182,6 @@ func testCheckAzureRMAppServiceEnvironmentDestroy(s *terraform.State) error { return nil } -func testCheckAppServicePlanMemberOfAppServiceEnvironment(ase string, asp string) resource.TestCheckFunc { - return func(s *terraform.State) error { - aseClient := acceptance.AzureProvider.Meta().(*clients.Client).Web.AppServiceEnvironmentsClient - aspClient := acceptance.AzureProvider.Meta().(*clients.Client).Web.AppServicePlansClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - aseResource, ok := s.RootModule().Resources[ase] - if !ok { - return fmt.Errorf("Not found: %s", ase) - } - - appServiceEnvironmentName := aseResource.Primary.Attributes["name"] - appServiceEnvironmentResourceGroup := aseResource.Primary.Attributes["resource_group_name"] - - aseResp, err := aseClient.Get(ctx, appServiceEnvironmentResourceGroup, appServiceEnvironmentName) - if err != nil { - if utils.ResponseWasNotFound(aseResp.Response) { - return fmt.Errorf("Bad: App Service Environment %q (resource group %q) does not exist: %+v", appServiceEnvironmentName, appServiceEnvironmentResourceGroup, err) - } - } - - aspResource, ok := s.RootModule().Resources[asp] - if !ok { - return fmt.Errorf("Not found: %s", ase) - } - - appServicePlanName := aspResource.Primary.Attributes["name"] - appServicePlanResourceGroup := aspResource.Primary.Attributes["resource_group_name"] - - aspResp, err := aspClient.Get(ctx, appServicePlanResourceGroup, appServicePlanName) - if err != nil { - if utils.ResponseWasNotFound(aseResp.Response) { - return fmt.Errorf("Bad: App Service Plan %q (resource group %q) does not exist: %+v", appServicePlanName, appServicePlanResourceGroup, err) - } - } - if aspResp.HostingEnvironmentProfile.ID != aseResp.ID { - return fmt.Errorf("Bad: App Service Plan %s not a member of App Service Environment %s", appServicePlanName, appServiceEnvironmentName) - } - - return nil - } -} - func testAccAzureRMAppServiceEnvironment_basic(data acceptance.TestData) string { template := testAccAzureRMAppServiceEnvironment_template(data) return fmt.Sprintf(`