This Docker, Azure, and Terraform article will show how to use Terraform to deploy an Azure Web App for Containers using a Docker Hub image.
Azure Web Apps for Containers allow us to deploy applications already packaged into a Docker image directory to an Azure Web App.
The deployment works by specifying a container registry in the configuration where the image can be downloaded from. The image can be hosted on a private or a public container registry.
In the case of Docker Hub and this article, we will show how to use a public image that doesn’t; require authentication.
Code
The following code creates a Linux service plan and a Web Application. The part that requires attention is the Application_Stack and App_Settings.
To change the Docker image, change the docker_image_name value.
the App_Settings is needed and cannot be removed.
resource "azurerm_service_plan" "appservice" {
name = "Linux"
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
os_type = "Linux"
sku_name = "P1v2"
}
resource "azurerm_linux_web_app" "webapp" {
name = "WebApp"
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
service_plan_id = azurerm_service_plan.appservice.id
site_config {
always_on = "true"
application_stack {
docker_image_name = "nginx:latest"
docker_registry_url = "https://index.docker.io/"
}
}
app_settings = {
"DOCKER_ENABLE_CI" = "true"
}
}