Skip to content

Commit

Permalink
Merge pull request #981 from terraform-providers/app-service-plan-con…
Browse files Browse the repository at this point in the history
…sumption

Support for Function Apps in Consumption Plans
  • Loading branch information
tombuildsstuff authored Mar 15, 2018
2 parents 0a627db + 515b491 commit 67b7480
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 5 deletions.
1 change: 1 addition & 0 deletions azurerm/resource_arm_app_service_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func resourceArmAppServicePlan() *schema.Resource {
Default: "Windows",
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
"FunctionApp",
"Linux",
"Windows",
}, true),
Expand Down
43 changes: 43 additions & 0 deletions azurerm/resource_arm_app_service_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,28 @@ func TestAccAzureRMAppServicePlan_completeWindows(t *testing.T) {
})
}

func TestAccAzureRMAppServicePlan_consumptionPlan(t *testing.T) {
resourceName := "azurerm_app_service_plan.test"
ri := acctest.RandInt()
config := testAccAzureRMAppServicePlan_consumptionPlan(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMAppServicePlanDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAppServicePlanExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "sku.0.tier", "Dynamic"),
resource.TestCheckResourceAttr(resourceName, "sku.0.size", "Y1"),
),
},
},
})
}

func testCheckAzureRMAppServicePlanDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*ArmClient).appServicePlansClient

Expand Down Expand Up @@ -365,3 +387,24 @@ resource "azurerm_app_service_plan" "test" {
}
`, rInt, location, rInt)
}

func testAccAzureRMAppServicePlan_consumptionPlan(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"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
kind = "FunctionApp"
sku {
tier = "Dynamic"
size = "Y1"
}
}
`, rInt, location, rInt)
}
60 changes: 60 additions & 0 deletions azurerm/resource_arm_function_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,29 @@ func TestAccAzureRMFunctionApp_3264bit(t *testing.T) {
})
}

func TestAccAzureRMFunctionApp_consumptionPlan(t *testing.T) {
resourceName := "azurerm_function_app.test"
ri := acctest.RandInt()
rs := strings.ToLower(acctest.RandString(11))
location := testLocation()
config := testAccAzureRMFunctionApp_consumptionPlan(ri, rs, location)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMFunctionAppDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMFunctionAppExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "site_config.0.use_32_bit_worker_process", "true"),
),
},
},
})
}

func testCheckAzureRMFunctionAppDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*ArmClient).appServicesClient

Expand Down Expand Up @@ -659,3 +682,40 @@ resource "azurerm_function_app" "test" {
}
`, rInt, location, rString, rInt, rInt)
}

func testAccAzureRMFunctionApp_consumptionPlan(rInt int, rString string, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_storage_account" "test" {
name = "acctestsa%s"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
account_tier = "Standard"
account_replication_type = "LRS"
}
resource "azurerm_app_service_plan" "test" {
name = "acctestASP-%d"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
kind = "FunctionApp"
sku {
tier = "Dynamic"
size = "Y1"
}
}
resource "azurerm_function_app" "test" {
name = "acctest-%d-func"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
app_service_plan_id = "${azurerm_app_service_plan.test.id}"
storage_connection_string = "${azurerm_storage_account.test.primary_connection_string}"
}
`, rInt, location, rString, rInt, rInt)
}
27 changes: 24 additions & 3 deletions website/docs/r/app_service_plan.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ description: |-

Create an App Service Plan component.

## Example Usage
## Example Usage (Dedicated)

```hcl
resource "azurerm_resource_group" "test" {
Expand All @@ -20,7 +20,7 @@ resource "azurerm_resource_group" "test" {
resource "azurerm_app_service_plan" "test" {
name = "api-appserviceplan-pro"
location = "West Europe"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
sku {
Expand All @@ -30,6 +30,27 @@ resource "azurerm_app_service_plan" "test" {
}
```

## Example Usage (Shared / Consumption Plan)

```hcl
resource "azurerm_resource_group" "test" {
name = "api-rg-pro"
location = "West Europe"
}
resource "azurerm_app_service_plan" "test" {
name = "api-appserviceplan-pro"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
kind = "FunctionApp"
sku {
tier = "Dynamic"
size = "Y1"
}
}
```

## Argument Reference

The following arguments are supported:
Expand All @@ -40,7 +61,7 @@ The following arguments are supported:

* `location` - (Required) Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created.

* `kind` - (Optional) The kind of the App Service Plan to create. Possible values are `Windows` and `Linux`. Defaults to `Windows`. Changing this forces a new resource to be created.
* `kind` - (Optional) The kind of the App Service Plan to create. Possible values are `Windows`, `Linux` and `FunctionApp` (for a Consumption Plan). Defaults to `Windows`. Changing this forces a new resource to be created.

* `sku` - (Required) A `sku` block as documented below.

Expand Down
38 changes: 36 additions & 2 deletions website/docs/r/function_app.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ description: |-

Manages a Function App.

-> **Note:** Function Apps can be deployed to either an App Service Plan or to a Consumption Plan. At this time it's possible to deploy a Function App into an existing Consumption Plan or a new/existing App Service Plan [using the `azurerm_app_service_plan` Data Source](app_service_plan.html) - however it's not currently possible to create a new Consumption Plan natively in Terraform. Support for this will be added in the future, and in the interim can be achieved by using [the `azurerm_template_deployment` resource](template_deployment.html).

## Example Usage (with App Service Plan)

```hcl
Expand Down Expand Up @@ -40,6 +38,42 @@ resource "azurerm_app_service_plan" "test" {
}
}
resource "azurerm_function_app" "test" {
name = "test-azure-functions"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
app_service_plan_id = "${azurerm_app_service_plan.test.id}"
storage_connection_string = "${azurerm_storage_account.test.primary_connection_string}"
}
```
## Example Usage (in a Consumption Plan)

```hcl
resource "azurerm_resource_group" "test" {
name = "azure-functions-cptest-rg"
location = "westus2"
}
resource "azurerm_storage_account" "test" {
name = "functionsapptestsa"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
account_tier = "Standard"
account_replication_type = "LRS"
}
resource "azurerm_app_service_plan" "test" {
name = "azure-functions-test-service-plan"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
kind = "FunctionApp"
sku {
tier = "Dynamic"
size = "Y1"
}
}
resource "azurerm_function_app" "test" {
name = "test-azure-functions"
location = "${azurerm_resource_group.test.location}"
Expand Down

0 comments on commit 67b7480

Please sign in to comment.