Reputation: 2489
I try deploy an Azure web app for containers. My terraform code looks like this:
resource "azurerm_linux_web_app" "example" {
name = "test123-webapp"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
service_plan_id = azurerm_service_plan.example.id
site_config {
linux_fx_version = "DOCKER|mcr.microsoft.com/appsvc/staticsite:latest"
container_registry_use_managed_identity = true
always_on = true
}
app_settings = {
"DOCKER_REGISTRY_SERVER_URL" = "https://${azurerm_container_registry.example.login_server}"
"DOCKER_REGISTRY_SERVER_USERNAME" = azurerm_container_registry.example.admin_username
"DOCKER_REGISTRY_SERVER_PASSWORD" = azurerm_container_registry.example.admin_password
}
}
With this code, I get an error:
│ Error: Value for unconfigurable attribute
│
│ with azurerm_linux_web_app.example,
│ on webapp.tf line 35, in resource "azurerm_linux_web_app" "example":
│ 35: linux_fx_version = "DOCKER|mcr.microsoft.com/appsvc/staticsite:latest"
│
│ Can't configure a value for "site_config.0.linux_fx_version": its value will be decided automatically based on the result of applying this configuration.
I couldn't find much documentation on terraform code. When I do manually on the portal, I see the configuration as below:
"siteProperties": {
"metadata": null,
"properties": [
{
"name": "LinuxFxVersion",
"value": "DOCKER|mcr.microsoft.com/appsvc/staticsite:latest"
},
{
"name": "WindowsFxVersion",
"value": null
}
],
I have tried removing 'DOCKER|' prefix but same error.
My tf version is Terraform v1.9.3 and azurerm is v3.112.0.
Any idea why I get this error on my terraform code?
Upvotes: 2
Views: 499
Reputation: 1250
The app service assumes your container is listening on port 80, use app_settings
to map the port.
resource "azurerm_linux_web_app" "webapp" {
name = "myapp"
resource_group_name = azurerm_resource_group.rg.name
location = "uksouth"
service_plan_id = azurerm_service_plan.plan.id
site_config {
always_on = false
application_stack {
docker_image_name = "myapp:0.0.1"
docker_registry_url = "https://index.docker.io"
docker_registry_username = var.docker_registry_username
docker_registry_password = var.docker_registry_password
}
}
}
Upvotes: 0
Reputation: 8018
You need to use an azurerm_app_service resource to deploy a web app for containers if you are using 3.11
and earlier versions.
After upgraded it to the latest version releases, azurerm_app_service
is further converted as azurerm_linux_web_app
for Linux Os type.
In order to deploy a web app for containers with azurerm 3.11
version releases, use azurerm_app_service
as shown below.
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.111.0"
}
}
}
provider "azurerm"{
features{}
subscription_id = "xxxx"
}
resource "azurerm_resource_group" "example" {
name = "xxx"
location = "West Europe"
}
resource "azurerm_service_plan" "example" {
name = "examplejah"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
os_type = "Linux"
sku_name = "P1v2"
}
resource "azurerm_container_registry" "example" {
name = "ahRegistry1j"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
sku = "Premium"
admin_enabled = true
}
resource "azurerm_app_service" "backend" {
name = "jahservice12new"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
app_service_plan_id = azurerm_service_plan.example.id
app_settings = {
DOCKER_REGISTRY_SERVER_URL = azurerm_container_registry.example.login_server
DOCKER_REGISTRY_SERVER_USERNAME = azurerm_container_registry.example.admin_username
DOCKER_REGISTRY_SERVER_PASSWORD = azurerm_container_registry.example.admin_password
}
site_config {
always_on = "true"
# define the images to used for you application
linux_fx_version = "DOCKER|${azurerm_container_registry.example.login_server}"
}
identity {
type = "SystemAssigned"
}
}
Refer blog for the similar deployment for dockerised web app.
Deployment succeeded:
If you want to deploy a container app with latest version (4.0) releases, you can use azurerm_container_app provider as given.
Upvotes: 0