Skip to content

Commit

Permalink
r/app_service_environment: checking the ID's from the state
Browse files Browse the repository at this point in the history
  • Loading branch information
tombuildsstuff committed Feb 23, 2020
1 parent 8bf7e31 commit 1a4c5af
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 48 deletions.
14 changes: 10 additions & 4 deletions azurerm/internal/services/web/resource_arm_app_service_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(`
Expand Down

0 comments on commit 1a4c5af

Please sign in to comment.