Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_function_app - support for daily_memory_time_quota #6100

Merged
merged 2 commits into from
Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions azurerm/internal/services/web/resource_arm_function_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ func resourceArmFunctionApp() *schema.Resource {
Default: false,
},

"daily_memory_time_quota": {
Type: schema.TypeInt,
Optional: true,
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like if the value of DailyMemoryTimeQuota is set to 0 or a negative value, then the quota will be turned off. I know schema.TypeInt will default to a value of 0 if not provided. Do we want to explicitly set a default value here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that should be fine - since the quota itself only affects functions inside a consumption plan?


"site_config": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
},
}
Expand Down Expand Up @@ -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)
Expand All @@ -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,
},
}
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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" {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/function_app.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down