-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #668 from terraform-providers/app-service-plan-dat…
…a-source New Data Source: `azurerm_app_service_plan`
- Loading branch information
Showing
5 changed files
with
306 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" | ||
) | ||
|
||
func dataSourceAppServicePlan() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceAppServicePlanRead, | ||
Importer: &schema.ResourceImporter{ | ||
State: schema.ImportStatePassthrough, | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
|
||
"resource_group_name": resourceGroupNameForDataSourceSchema(), | ||
|
||
"location": locationForDataSourceSchema(), | ||
|
||
"kind": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"sku": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"tier": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"size": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"capacity": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
||
"properties": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"reserved": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"per_site_scaling": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
||
"maximum_number_of_workers": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
|
||
"tags": tagsForDataSourceSchema(), | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceAppServicePlanRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).appServicePlansClient | ||
|
||
name := d.Get("name").(string) | ||
resourceGroup := d.Get("resource_group_name").(string) | ||
|
||
resp, err := client.Get(resourceGroup, name) | ||
if err != nil { | ||
if utils.ResponseWasNotFound(resp.Response) { | ||
d.SetId("") | ||
return nil | ||
} | ||
|
||
return fmt.Errorf("Error making Read request on App Service Plan %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
d.SetId(*resp.ID) | ||
|
||
d.Set("name", name) | ||
d.Set("resource_group_name", resourceGroup) | ||
d.Set("location", azureRMNormalizeLocation(*resp.Location)) | ||
d.Set("kind", resp.Kind) | ||
|
||
if props := resp.AppServicePlanProperties; props != nil { | ||
d.Set("properties", flattenAppServiceProperties(props)) | ||
|
||
if props.MaximumNumberOfWorkers != nil { | ||
d.Set("maximum_number_of_workers", int(*props.MaximumNumberOfWorkers)) | ||
} | ||
} | ||
|
||
if sku := resp.Sku; sku != nil { | ||
d.Set("sku", flattenAppServicePlanSku(sku)) | ||
} | ||
|
||
flattenAndSetTags(d, resp.Tags) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceAzureRMAppServicePlan_basic(t *testing.T) { | ||
dataSourceName := "data.azurerm_app_service_plan.test" | ||
rInt := acctest.RandInt() | ||
location := testLocation() | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceAppServicePlan_basic(rInt, location), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(dataSourceName, "kind", "Windows"), | ||
resource.TestCheckResourceAttr(dataSourceName, "sku.#", "1"), | ||
resource.TestCheckResourceAttr(dataSourceName, "sku.0.tier", "Basic"), | ||
resource.TestCheckResourceAttr(dataSourceName, "sku.0.size", "B1"), | ||
resource.TestCheckResourceAttr(dataSourceName, "properties.#", "1"), | ||
resource.TestCheckResourceAttr(dataSourceName, "properties.0.per_site_scaling", "false"), | ||
resource.TestCheckResourceAttr(dataSourceName, "tags.%", "0"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccDataSourceAzureRMAppServicePlan_complete(t *testing.T) { | ||
dataSourceName := "data.azurerm_app_service_plan.test" | ||
rInt := acctest.RandInt() | ||
location := testLocation() | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceAppServicePlan_complete(rInt, location), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(dataSourceName, "kind", "Windows"), | ||
resource.TestCheckResourceAttr(dataSourceName, "sku.#", "1"), | ||
resource.TestCheckResourceAttr(dataSourceName, "sku.0.tier", "Standard"), | ||
resource.TestCheckResourceAttr(dataSourceName, "sku.0.size", "S1"), | ||
resource.TestCheckResourceAttr(dataSourceName, "properties.#", "1"), | ||
resource.TestCheckResourceAttr(dataSourceName, "properties.0.per_site_scaling", "true"), | ||
resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"), | ||
resource.TestCheckResourceAttr(dataSourceName, "tags.environment", "Test"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceAppServicePlan_basic(rInt int, location string) string { | ||
return fmt.Sprintf(` | ||
resource "azurerm_resource_group" "test" { | ||
name = "acctestRG-%d" | ||
location = "%s" | ||
} | ||
resource "azurerm_app_service_plan" "test" { | ||
name = "acctestASP-%d" | ||
location = "${azurerm_resource_group.test.location}" | ||
resource_group_name = "${azurerm_resource_group.test.name}" | ||
sku { | ||
tier = "Basic" | ||
size = "B1" | ||
} | ||
} | ||
data "azurerm_app_service_plan" "test" { | ||
name = "${azurerm_app_service_plan.test.name}" | ||
resource_group_name = "${azurerm_app_service_plan.test.resource_group_name}" | ||
} | ||
`, rInt, location, rInt) | ||
} | ||
|
||
func testAccDataSourceAppServicePlan_complete(rInt int, location string) string { | ||
return fmt.Sprintf(` | ||
resource "azurerm_resource_group" "test" { | ||
name = "acctestRG-%d" | ||
location = "%s" | ||
} | ||
resource "azurerm_app_service_plan" "test" { | ||
name = "acctestASP-%d" | ||
location = "${azurerm_resource_group.test.location}" | ||
resource_group_name = "${azurerm_resource_group.test.name}" | ||
kind = "Windows" | ||
sku { | ||
tier = "Standard" | ||
size = "S1" | ||
} | ||
properties { | ||
per_site_scaling = true | ||
} | ||
tags { | ||
environment = "Test" | ||
} | ||
} | ||
data "azurerm_app_service_plan" "test" { | ||
name = "${azurerm_app_service_plan.test.name}" | ||
resource_group_name = "${azurerm_app_service_plan.test.resource_group_name}" | ||
} | ||
`, rInt, location, rInt) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
--- | ||
layout: "azurerm" | ||
page_title: "Azure Resource Manager: azurerm_app_service_plan" | ||
sidebar_current: "docs-azurerm-datasource-app-service-plan" | ||
description: |- | ||
Get information about an App Service Plan. | ||
--- | ||
|
||
# Data Source: azurerm_app_service_plan | ||
|
||
Use this data source to obtain information about an App Service Plan (formerly known as a `Server Farm`). | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "azurerm_app_service_plan" "test" { | ||
name = "search-app-service" | ||
resource_group_name = "search-service" | ||
} | ||
output "app_service_plan_id" { | ||
value = "${data.azurerm_app_service_plan.test.id}" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `name` - (Required) The name of the App Service Plan. | ||
* `resource_group_name` - (Required) The Name of the Resource Group where the App Service Plan exists. | ||
|
||
## Attributes Reference | ||
|
||
* `id` - The ID of the built-in App Service Plan. | ||
|
||
* `location` - The Azure location where the App Service Plan exists | ||
|
||
* `kind` - The Operating System type of the App Service Plan | ||
|
||
* `sku` - A `sku` block as documented below. | ||
|
||
* `properties` - A `properties` block as documented below. | ||
|
||
* `tags` - A mapping of tags to assign to the resource. | ||
|
||
A `sku` block supports the following: | ||
|
||
* `tier` - Specifies the plan's pricing tier. | ||
|
||
* `size` - Specifies the plan's instance size. | ||
|
||
* `capacity` - Specifies the number of workers associated with this App Service Plan. | ||
|
||
A `properties` block supports the following: | ||
|
||
* `maximum_number_of_workers` - Maximum number of instances that can be assigned to this App Service plan. | ||
|
||
* `reserved` - Is this App Service Plan `Reserved`? | ||
|
||
* `per_site_scaling` - Can Apps assigned to this App Service Plan be scaled independently? | ||
|
||
* `maximum_number_of_workers` - The maximum number of workers supported with the App Service Plan's sku. |