From a59eb5606f18bdcde873f7a9ae1c01daf096b37f Mon Sep 17 00:00:00 2001 From: Austin Cheung Date: Thu, 12 Mar 2020 16:36:38 -0700 Subject: [PATCH] add daily_memory_time_quota option to azurerm_function_app --- .../services/web/resource_arm_function_app.go | 10 +++ .../tests/resource_arm_function_app_test.go | 70 +++++++++++++++++++ website/docs/r/function_app.html.markdown | 2 + 3 files changed, 82 insertions(+) diff --git a/azurerm/internal/services/web/resource_arm_function_app.go b/azurerm/internal/services/web/resource_arm_function_app.go index 6b5cefe30b6c..9ee43c4051ad 100644 --- a/azurerm/internal/services/web/resource_arm_function_app.go +++ b/azurerm/internal/services/web/resource_arm_function_app.go @@ -174,6 +174,11 @@ func resourceArmFunctionApp() *schema.Resource { Default: false, }, + "daily_memory_time_quota": { + Type: schema.TypeInt, + Optional: true, + }, + "site_config": { Type: schema.TypeList, Optional: true, @@ -323,6 +328,7 @@ func resourceArmFunctionAppCreate(d *schema.ResourceData, meta interface{}) erro enabled := d.Get("enabled").(bool) clientAffinityEnabled := d.Get("client_affinity_enabled").(bool) httpsOnly := d.Get("https_only").(bool) + dailyMemoryTimeQuota := d.Get("daily_memory_time_quota").(int) t := d.Get("tags").(map[string]interface{}) appServiceTier, err := getFunctionAppServiceTier(ctx, appServicePlanID, meta) if err != nil { @@ -347,6 +353,7 @@ func resourceArmFunctionAppCreate(d *schema.ResourceData, meta interface{}) erro Enabled: utils.Bool(enabled), ClientAffinityEnabled: utils.Bool(clientAffinityEnabled), HTTPSOnly: utils.Bool(httpsOnly), + DailyMemoryTimeQuota: utils.Int32(int32(dailyMemoryTimeQuota)), SiteConfig: &siteConfig, }, } @@ -413,6 +420,7 @@ func resourceArmFunctionAppUpdate(d *schema.ResourceData, meta interface{}) erro enabled := d.Get("enabled").(bool) clientAffinityEnabled := d.Get("client_affinity_enabled").(bool) httpsOnly := d.Get("https_only").(bool) + dailyMemoryTimeQuota := d.Get("daily_memory_time_quota").(int) t := d.Get("tags").(map[string]interface{}) appServiceTier, err := getFunctionAppServiceTier(ctx, appServicePlanID, meta) @@ -437,6 +445,7 @@ func resourceArmFunctionAppUpdate(d *schema.ResourceData, meta interface{}) erro Enabled: utils.Bool(enabled), ClientAffinityEnabled: utils.Bool(clientAffinityEnabled), HTTPSOnly: utils.Bool(httpsOnly), + DailyMemoryTimeQuota: utils.Int32(int32(dailyMemoryTimeQuota)), SiteConfig: &siteConfig, }, } @@ -576,6 +585,7 @@ func resourceArmFunctionAppRead(d *schema.ResourceData, meta interface{}) error d.Set("enabled", props.Enabled) d.Set("default_hostname", props.DefaultHostName) d.Set("https_only", props.HTTPSOnly) + d.Set("daily_memory_time_quota", props.DailyMemoryTimeQuota) d.Set("outbound_ip_addresses", props.OutboundIPAddresses) d.Set("possible_outbound_ip_addresses", props.PossibleOutboundIPAddresses) d.Set("client_affinity_enabled", props.ClientAffinityEnabled) diff --git a/azurerm/internal/services/web/tests/resource_arm_function_app_test.go b/azurerm/internal/services/web/tests/resource_arm_function_app_test.go index 80029b1d2cda..3819a4d15a83 100644 --- a/azurerm/internal/services/web/tests/resource_arm_function_app_test.go +++ b/azurerm/internal/services/web/tests/resource_arm_function_app_test.go @@ -344,6 +344,34 @@ func TestAccAzureRMFunctionApp_httpsOnly(t *testing.T) { }) } +func TestAccAzureRMFunctionApp_dailyMemoryTimeQuota(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_function_app", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMFunctionAppDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMFunctionApp_consumptionPlan(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMFunctionAppExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "daily_memory_time_quota", "0"), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMFunctionApp_dailyMemoryTimeQuota(data, 1000), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMFunctionAppExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "daily_memory_time_quota", "1000"), + ), + }, + data.ImportStep(), + }, + }) +} + func TestAccAzureRMFunctionApp_consumptionPlan(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_function_app", "test") @@ -1470,6 +1498,48 @@ resource "azurerm_function_app" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomInteger) } +func testAccAzureRMFunctionApp_dailyMemoryTimeQuota(data acceptance.TestData, dailyMemoryTimeQuota int) 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 = "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 + daily_memory_time_quota = %d +} +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomInteger, dailyMemoryTimeQuota) +} + func testAccAzureRMFunctionApp_consumptionPlan(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { diff --git a/website/docs/r/function_app.html.markdown b/website/docs/r/function_app.html.markdown index 40708ca2f4e8..82bf2ab04e52 100644 --- a/website/docs/r/function_app.html.markdown +++ b/website/docs/r/function_app.html.markdown @@ -121,6 +121,8 @@ The following arguments are supported: * `version` - (Optional) The runtime version associated with the Function App. Defaults to `~1`. +* `daily_memory_time_quota` - (Optional) The amount of memory in gigabyte-seconds that your application is allowed to consume per day. Setting this value only affects function apps under the consumption plan. Defaults to `0`. + * `site_config` - (Optional) A `site_config` object as defined below. * `identity` - (Optional) An `identity` block as defined below.