diff --git a/azurerm/helpers/azure/app_service.go b/azurerm/helpers/azure/app_service.go index 1e3cbcef6b44..e18ca77bb6e5 100644 --- a/azurerm/helpers/azure/app_service.go +++ b/azurerm/helpers/azure/app_service.go @@ -483,6 +483,11 @@ func SchemaAppServiceSiteConfig() *schema.Schema { }, "cors": SchemaWebCorsSettings(), + + "auto_swap_slot_name": { + Type: schema.TypeString, + Optional: true, + }, }, }, } @@ -1520,6 +1525,10 @@ func ExpandAppServiceSiteConfig(input interface{}) (*web.SiteConfig, error) { siteConfig.Cors = &expand } + if v, ok := config["auto_swap_slot_name"]; ok { + siteConfig.AutoSwapSlotName = utils.String(v.(string)) + } + return siteConfig, nil } @@ -1640,6 +1649,10 @@ func FlattenAppServiceSiteConfig(input *web.SiteConfig) []interface{} { result["cors"] = FlattenWebCorsSettings(input.Cors) + if input.AutoSwapSlotName != nil { + result["auto_swap_slot_name"] = *input.AutoSwapSlotName + } + return append(results, result) } diff --git a/azurerm/resource_arm_app_service_slot_test.go b/azurerm/resource_arm_app_service_slot_test.go index b901280f216f..01ff6bc3a57f 100644 --- a/azurerm/resource_arm_app_service_slot_test.go +++ b/azurerm/resource_arm_app_service_slot_test.go @@ -1541,6 +1541,32 @@ func TestAccAzureRMAppServiceSlot_httpBlobStorageLogs(t *testing.T) { }) } +func TestAccAzureRMAppServiceSlot_autoSwap(t *testing.T) { + resourceName := "azurerm_app_service_slot.test" + ri := tf.AccRandTimeInt() + config := testAccAzureRMAppServiceSlot_autoSwap(ri, testLocation()) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAppServiceSlotExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "site_config.0.auto_swap_slot_name", "production"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func testCheckAzureRMAppServiceSlotDestroy(s *terraform.State) error { client := testAccProvider.Meta().(*ArmClient).Web.AppServicesClient @@ -3808,3 +3834,42 @@ resource "azurerm_app_service_slot" "test" { } `, rInt, location, rInt, rInt, rInt) } + +func testAccAzureRMAppServiceSlot_autoSwap(rInt int, location string) string { + return fmt.Sprintf(` +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_app_service" "test" { + name = "acctestAS-%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}" +} + +resource "azurerm_app_service_slot" "test" { + name = "acctestASSlot-%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}" + app_service_name = "${azurerm_app_service.test.name}" + + site_config { + auto_swap_slot_name = "production" + } +} +`, rInt, location, rInt, rInt, rInt) +} diff --git a/website/docs/r/app_service_slot.html.markdown b/website/docs/r/app_service_slot.html.markdown index e477c6c95f7d..4f98f07a3170 100644 --- a/website/docs/r/app_service_slot.html.markdown +++ b/website/docs/r/app_service_slot.html.markdown @@ -230,6 +230,8 @@ 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 + --- A `cors` block supports the following: