Azure App Service (Web Apps) Active Slot

This page shows how to write Terraform for App Service (Web Apps) Active Slot and write them securely.

azurerm_app_service_active_slot (Terraform)

The Active Slot in App Service (Web Apps) can be configured in Terraform with the resource name azurerm_app_service_active_slot. The following sections describe 7 examples of how to use the resource and its parameters.

Example Usage from GitHub

swap_app.tf#L4
resource "azurerm_app_service_active_slot" "SwapActiveSlot" {
    resource_group_name   = "RG04-westus2-20200127"
    app_service_name      = "AppService-westus2-20200127"
    app_service_slot_name = "AppServiceSlot1-westus2-20200127"
}
swap.tf#L10
resource "azurerm_app_service_active_slot" "slotDemoActiveSlot" {
    resource_group_name   = "slotDemoResourceGroup"
    app_service_name      = "slotAppService"
    app_service_slot_name = "slotappServiceSlotOne"
main.tf#L1
resource "azurerm_app_service_active_slot" "example" {
  resource_group_name   = module.resource_group.azurerm_resource_group.example.name
  app_service_name      = module.app_service.azurerm_app_service.example.name
  app_service_slot_name = module.service_slot.azurerm_app_service_slot.example.name
main.tf#L7
resource "azurerm_app_service_active_slot" "this" {
  app_service_name      = var.app_service_name
  app_service_slot_name = var.app_service_slot_name
  resource_group_name   = var.resource_group_name

  dynamic "timeouts" {
main.tf#L8
resource "azurerm_app_service_active_slot" "this" {
  for_each              = var.appservice_slots_swap
  resource_group_name   = data.azurerm_resource_group.this.name
  app_service_name      = lookup(data.terraform_remote_state.appservice.outputs.app_service_map, each.value["app_service_key"], null)
  app_service_slot_name = lookup(data.terraform_remote_state.appservice.outputs.app_service_slot_map, each.value["app_service_slot_key"], null)
  }
main.tf#L7
resource "azurerm_app_service_active_slot" "this" {
  app_service_name      = var.app_service_name
  app_service_slot_name = var.app_service_slot_name
  resource_group_name   = var.resource_group_name

  dynamic "timeouts" {
webapp.tf#L43
resource "azurerm_app_service_active_slot" "active_slot" {
    resource_group_name   = azurerm_resource_group.rg_name.name
    app_service_name      = azurerm_app_service.app_service.name
    app_service_slot_name = azurerm_app_service_slot.app_service_slot.name
}

Review your Terraform file for Azure best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

Explanation in Terraform Registry

Promotes an App Service Slot to Production within an App Service. -> Note: When using Slots - the app_settings, connection_string and site_config blocks on the azurerm_app_service resource will be overwritten when promoting a Slot using the azurerm_app_service_active_slot resource.

Tips: Best Practices for The Other Azure App Service (Web Apps) Resources

In addition to the azurerm_app_service, Azure App Service (Web Apps) has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.

risk-label

azurerm_app_service

Ensure your App Service is accessible via HTTPS only

It is better to configure the App Service to be accessible via HTTPS only. By default, both HTTP and HTTPS are available.

risk-label

azurerm_function_app

Ensure to enable authentication to prevent anonymous request being accepted

It is better to enable authentication to prevent anonymous requests and ensure all communications in the application are authenticated.

Review your Azure App Service (Web Apps) settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

Azure Resource Manager Example

Azure Resource Manager code does not have the related resource.

Frequently asked questions

What is Azure App Service (Web Apps) Active Slot?

Azure App Service (Web Apps) Active Slot is a resource for App Service (Web Apps) of Microsoft Azure. Settings can be wrote in Terraform.

Where can I find the example code for the Azure App Service (Web Apps) Active Slot?

For Terraform, the jeffan18/Terraform-code-Azure-App.Services, Ridha-ELGHOUL/slotDemo-terraform and VentsislavDinev/en_sample source code examples are useful. See the Terraform Example section for further details.

security-icon

Automate config file reviews on your commits

Fix issues in your infrastructure as code with auto-generated patches.