Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
Aris van Ommeren committed May 5, 2020
1 parent 4d4ee48 commit b6964e1
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 8 deletions.
13 changes: 13 additions & 0 deletions azurerm/internal/services/web/resource_arm_function_app_slot.go
Expand Up @@ -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(),
},
},
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
Expand Down
Expand Up @@ -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"
)

Expand All @@ -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{
Expand Down Expand Up @@ -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" {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
2 changes: 2 additions & 0 deletions website/docs/r/function_app_slot.html.markdown
Expand Up @@ -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.
Expand Down

0 comments on commit b6964e1

Please sign in to comment.