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_slot.site_config - support for auto_swap_slot_name #7859

Merged
merged 2 commits into from
Jul 24, 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
12 changes: 12 additions & 0 deletions azurerm/internal/services/web/resource_arm_function_app_slot.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ func resourceArmFunctionAppSlot() *schema.Resource {
ValidateFunc: validation.IntBetween(0, 10),
},
"cors": azure.SchemaWebCorsSettings(),
"auto_swap_slot_name": {
Type: schema.TypeString,
Optional: true,
},
},
},
},
Expand Down Expand Up @@ -832,6 +836,10 @@ func expandFunctionAppSlotSiteConfig(d *schema.ResourceData) (web.SiteConfig, er
siteConfig.PreWarmedInstanceCount = utils.Int32(int32(v.(int)))
}

if v, ok := config["auto_swap_slot_name"]; ok {
siteConfig.AutoSwapSlotName = utils.String(v.(string))
}

return siteConfig, nil
}

Expand Down Expand Up @@ -875,6 +883,10 @@ func flattenFunctionAppSlotSiteConfig(input *web.SiteConfig) []interface{} {

result["cors"] = azure.FlattenWebCorsSettings(input.Cors)

if input.AutoSwapSlotName != nil {
result["auto_swap_slot_name"] = *input.AutoSwapSlotName
}

results = append(results, result)
return results
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,27 @@ func TestAccAzureRMFunctionAppSlot_corsSettings(t *testing.T) {
},
})
}

func TestAccAzureRMFunctionAppSlot_autoSwap(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: testCheckAzureRMFunctionAppSlotDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMFunctionAppSlot_autoSwap(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMFunctionAppSlotExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.auto_swap_slot_name", "production"),
),
},
data.ImportStep(),
},
})
}

func TestAccAzureRMFunctionAppSlot_authSettings(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_function_app_slot", "test")

Expand Down Expand Up @@ -1172,6 +1193,61 @@ resource "azurerm_function_app_slot" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomString, data.RandomInteger, data.RandomInteger)
}

func testAccAzureRMFunctionAppSlot_autoSwap(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}

resource "azurerm_app_service_plan" "test" {
name = "acctestASP-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name

sku {
tier = "Standard"
size = "S1"
}
}

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_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_account_name = azurerm_storage_account.test.name
storage_account_access_key = azurerm_storage_account.test.primary_access_key
}

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 {
auto_swap_slot_name = "production"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomString, data.RandomInteger, data.RandomInteger)
}

func testAccAzureRMFunctionAppSlot_authSettings(data acceptance.TestData, tenantID string) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/app_service_slot.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ The following arguments are supported:

* `websockets_enabled` - (Optional) Should WebSockets be enabled?

* `auto_swap_slot_name` - (Optional) The name of the swap to automatically swap to during deployment
* `auto_swap_slot_name` - (Optional) The name of the slot to automatically swap to during deployment

---

Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/function_app_slot.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ The following arguments are supported:

* `app_service_plan_id` - (Required) The ID of the App Service Plan within which to create this Function App Slot.

* `function_app_name` - (Required) The name of the Function App within which to create the Function App Slot. Changing this forces a new resource to be created.

* `storage_account_name` - (Required) The backend storage account name which will be used by the Function App (such as the dashboard, logs).

* `storage_account_access_key` - (Required) The access key which will be used to access the backend storage account for the Function App.
Expand Down Expand Up @@ -140,6 +142,8 @@ The following arguments are supported:

* `ip_restriction` - (Optional) A [List of objects](/docs/configuration/attr-as-blocks.html) representing ip restrictions as defined below.

* `auto_swap_slot_name` - (Optional) The name of the slot to automatically swap to during deployment

---

A `cors` block supports the following:
Expand Down