From b6964e14dfe96f68484c1ca1e81d46c10c8b0504 Mon Sep 17 00:00:00 2001 From: Aris van Ommeren Date: Tue, 5 May 2020 22:18:15 +0200 Subject: [PATCH] add --- .../web/resource_arm_function_app_slot.go | 13 +++ .../resource_arm_function_app_slot_test.go | 84 +++++++++++++++++-- .../docs/r/function_app_slot.html.markdown | 2 + 3 files changed, 91 insertions(+), 8 deletions(-) diff --git a/azurerm/internal/services/web/resource_arm_function_app_slot.go b/azurerm/internal/services/web/resource_arm_function_app_slot.go index 8f0eaa4b5ddf1..8f4a2c2df6ea4 100644 --- a/azurerm/internal/services/web/resource_arm_function_app_slot.go +++ b/azurerm/internal/services/web/resource_arm_function_app_slot.go @@ -264,6 +264,11 @@ func resourceArmFunctionAppSlot() *schema.Resource { string(web.FtpsOnly), }, false), }, + "pre_warmed_instance_count": { + Type: schema.TypeInt, + Optional: true, + ValidateFunc: validation.IntBetween(0, 10), + }, "cors": azure.SchemaWebCorsSettings(), }, }, @@ -823,6 +828,10 @@ func expandFunctionAppSlotSiteConfig(d *schema.ResourceData) (web.SiteConfig, er siteConfig.FtpsState = web.FtpsState(v.(string)) } + if v, ok := config["pre_warmed_instance_count"]; ok { + siteConfig.PreWarmedInstanceCount = utils.Int32(int32(v.(int))) + } + return siteConfig, nil } @@ -855,6 +864,10 @@ func flattenFunctionAppSlotSiteConfig(input *web.SiteConfig) []interface{} { result["http2_enabled"] = *input.HTTP20Enabled } + if input.PreWarmedInstanceCount != nil { + result["pre_warmed_instance_count"] = *input.PreWarmedInstanceCount + } + result["ip_restriction"] = flattenFunctionAppSlotIPRestriction(input.IPSecurityRestrictions) result["min_tls_version"] = string(input.MinTLSVersion) diff --git a/azurerm/internal/services/web/tests/resource_arm_function_app_slot_test.go b/azurerm/internal/services/web/tests/resource_arm_function_app_slot_test.go index d09617445c33e..36ebf0d9e4c25 100644 --- a/azurerm/internal/services/web/tests/resource_arm_function_app_slot_test.go +++ b/azurerm/internal/services/web/tests/resource_arm_function_app_slot_test.go @@ -10,7 +10,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -33,11 +32,6 @@ func TestAccAzureRMFunctionAppSlot_basic(t *testing.T) { } func TestAccAzureRMFunctionAppSlot_requiresImport(t *testing.T) { - if !features.ShouldResourcesBeImported() { - t.Skip("Skipping since resources aren't required to be imported") - return - } - data := acceptance.BuildTestData(t, "azurerm_function_app_slot", "test") resource.ParallelTest(t, resource.TestCase{ @@ -685,6 +679,26 @@ func testCheckAzureRMFunctionAppSlotExists(slot string) resource.TestCheckFunc { } } +func TestAccAzureRMFunctionAppSlot_preWarmedInstanceCount(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_function_app_slot", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMFunctionAppDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMFunctionAppSlot_preWarmedInstanceCount(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMFunctionAppSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.pre_warmed_instance_count", "1"), + ), + }, + data.ImportStep(), + }, + }) +} + func testAccAzureRMFunctionAppSlot_basic(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { @@ -747,8 +761,8 @@ resource "azurerm_function_app_slot" "import" { resource_group_name = azurerm_function_app_slot.test.resource_group_name app_service_plan_id = azurerm_function_app_slot.test.app_service_plan_id function_app_name = azurerm_function_app_slot.test.function_app_name - storage_account_name = azurerm_function_app_slot.test.name - storage_account_access_key = azurerm_function_app_slot.test.primary_access_key + storage_account_name = azurerm_function_app_slot.test.storage_account_name + storage_account_access_key = azurerm_function_app_slot.test.storage_account_access_key } `, template) } @@ -2035,3 +2049,57 @@ resource "azurerm_function_app_slot" "test" { } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomString, data.RandomInteger, data.RandomInteger, tlsVersion) } + +func testAccAzureRMFunctionAppSlot_preWarmedInstanceCount(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +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 = "elastic" + sku { + tier = "ElasticPremium" + size = "EP1" + } +} + +resource "azurerm_function_app" "test" { + name = "acctestFA-%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 + storage_connection_string = azurerm_storage_account.test.primary_connection_string +} + +resource "azurerm_function_app_slot" "test" { + name = "acctestFASlot-%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 + function_app_name = azurerm_function_app.test.name + storage_account_name = azurerm_storage_account.test.name + storage_account_access_key = azurerm_storage_account.test.primary_access_key + + site_config { + min_tls_version = "%s" + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomString) +} diff --git a/website/docs/r/function_app_slot.html.markdown b/website/docs/r/function_app_slot.html.markdown index ad5011716f4d1..8a50974e1e045 100644 --- a/website/docs/r/function_app_slot.html.markdown +++ b/website/docs/r/function_app_slot.html.markdown @@ -130,6 +130,8 @@ The following arguments are supported: * `ftps_state` - (Optional) State of FTP / FTPS service for this function app. Possible values include: `AllAllowed`, `FtpsOnly` and `Disabled`. +* `pre_warmed_instance_count` - (Optional) The number of pre-warmed instances for this function app. Only affects apps on the Premium plan. + * `cors` - (Optional) A `cors` block as defined below. * `ip_restriction` - (Optional) A [List of objects](/docs/configuration/attr-as-blocks.html) representing ip restrictions as defined below.