microsoft / azure-redcap-paas

Automated deployment of REDCap with Azure Blob storage as the storage back-end
MIT License
28 stars 53 forks source link

Terraform: Remove deprecated azurerm_app_service resource in favor of azurerm_linux_web_app & azurerm_windows_web_app #53

Open epopisces opened 8 months ago

epopisces commented 8 months ago

azurerm_app_service is deprecated in version 3.x of the azurerm provider. The recommended guidance is to use the new azurerm_linux_web_app & azurerm_windows_web_app resources. These can be implemented via parallel resources (one for linux, one for windows) enabled/disabled via count with a conditional based on the parent app service resource's type, like so:

resource "azurerm_linux_web_app" "redcap" {
  count                     = var.os_type == "Linux" ? 1 : 0
  ...
}

...
resource "azurerm_windows_web_app" "redcap" {
  count                     = var.os_type != "Linux" ? 1 : 0
  ...
}

Note this does (unfortunately) require all dependent resources to include the same conditional and also use a index, like so:

resource "azurerm_private_endpoint" "web_app" {
  ...

  private_service_connection {
    name                           = "example"
    private_connection_resource_id = var.os_type == "Linux" ? (
      azurerm_linux_web_app.redcap[0].id 
    ) : ( 
      azurerm_windows_web_app.redcap[0].id
    )
    subresource_names              = ["sites"]
    is_manual_connection           = false
  }
  ...

}
epopisces commented 8 months ago

If this template is only intended to support Linux, the deprecation path is even simpler: simply update azurerm_app_service to azurerm_linux_web_app and change the app_service_plan_id argument to service_plan_id, the other arguments should be fine.