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_app_service_slot: auto_swap_slot_name support #4752

Merged
merged 1 commit into from
Oct 30, 2019
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
13 changes: 13 additions & 0 deletions azurerm/helpers/azure/app_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,11 @@ func SchemaAppServiceSiteConfig() *schema.Schema {
},

"cors": SchemaWebCorsSettings(),

"auto_swap_slot_name": {
Type: schema.TypeString,
Optional: true,
},
},
},
}
Expand Down Expand Up @@ -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
}

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

Expand Down
65 changes: 65 additions & 0 deletions azurerm/resource_arm_app_service_slot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

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