Reputation: 1567
I everyone.
I am trying to use terraform to create a azure app service for my docker images, but apparently this resource get created for windows by default even if my app_service_plan
is configured to be for a linux environment.
My configuration are as follow:
resource "azurerm_app_service_plan" "ASP-name" {
location = var.location
name = "ASP-name"
resource_group_name = <resource-group>
is_xenon = false
kind = "Linux"
maximum_elastic_worker_count = 1
per_site_scaling = false
reserved = true
sku {
capacity = 1
size = "P1v2"
tier = "PremiumV2"
}
}
resource "azurerm_app_service" "app-name" {
app_service_plan_id = azurerm_app_service_plan.ASP-name.id
location = var.location
name = "app-name"
resource_group_name = <resource-group>
app_settings = {
ASPNETCORE_ENVIRONMENT = "Production"
"DOCKER_REGISTRY_SERVER_PASSWORD" = "value"
"DOCKER_REGISTRY_SERVER_URL" = "value"
"DOCKER_REGISTRY_SERVER_USERNAME" = "value"
}
client_affinity_enabled = false
client_cert_enabled = false
enabled = true
}
Can please somebody tell me what am I doing wrong?
Upvotes: 1
Views: 5389
Reputation: 81
As the ressource azurerm_app_service
is now depricated in the TF provider azurerm
since v3.0 and will be remove in v4.0, the acceppted answer is not applicable anymore, because the new replacement resource azurerm_linux_web_app
doesn't provide the linux_fx_version
attribute.
Instead you need to set the full docker image URL inside azurerm_linux_web_app
-> site_config
-> application_stack
-> docker_image
Here is an example provided using the azurerm_container_registry
data source.
resource "azurerm_linux_web_app" "my-web-app" {
name = var.web-app-name
resource_group_name = azurerm_resource_group.my-resource-group.name
location = azurerm_resource_group.my-resource-group.location
service_plan_id = azurerm_service_plan.my-service-plan.id
site_config {
application_stack {
docker_image = "${data.azurerm_container_registry.my-container-registry.login_server}/my-container-name"
docker_image_tag = "latest"
}
}
app_settings = {
DOCKER_REGISTRY_SERVER_URL = data.azurerm_container_registry.my-container-registry.login_server
DOCKER_REGISTRY_SERVER_USERNAME = data.azurerm_container_registry.my-container-registry.admin_username
DOCKER_REGISTRY_SERVER_PASSWORD = data.azurerm_container_registry.my-container-registry.admin_password
}
}
data "azurerm_container_registry" "my-container-registry" {
name = var.docker-registry-name
resource_group_name = var.docker-registry-resource-group
}
Upvotes: 5
Reputation: 28294
This sample provisions a Linux App Service that runs a single Docker container. You need to provide your docker image with linux_fx_version
.
resource "azurerm_app_service_plan" "ASP-name" {
location = var.location
name = "ASP-name"
resource_group_name = <resource-group>
kind = "Linux"
maximum_elastic_worker_count = 1
per_site_scaling = false
reserved = true
sku {
capacity = 1
size = "P1v2"
tier = "PremiumV2"
}
}
resource "azurerm_app_service" "app-name" {
app_service_plan_id = azurerm_app_service_plan.ASP-name.id
location = var.location
name = "app-name"
resource_group_name = <resource-group>
site_config {
app_command_line = ""
linux_fx_version = "DOCKER|appsvcsample/python-helloworld:latest"
}
app_settings = {
"DOCKER_REGISTRY_SERVER_PASSWORD" = "value"
"DOCKER_REGISTRY_SERVER_URL" = "value"
"DOCKER_REGISTRY_SERVER_USERNAME" = "value"
}
client_affinity_enabled = false
client_cert_enabled = false
enabled = true
}
Upvotes: 4