Cannot deploy an Azure container app created via Terraform with VS2022

Simone Coppini 1 Reputation point
2023-05-05T06:53:40.84+00:00

Hi everyone, I think there is a bug in VS 2022, but l am not able to report the problem on developer community.

I created with Terrafrom the following Azure resources:

  • A docker container registry
  • A User-managed identity
  • A log analytics workspace
  • A Container app environment
  • A container app

I also createad manually a second container app that is inside the same enviroment I created with terraform.

I can successfully publish my VS project to the container app I created manually.

But it fails if I try to publish the VS project to the container app I created with terraform.

I try to give you more details.

resource "azurerm_container_app" "portal_api" {
  name                         = "${var.env_prefix}-portal-ca-westeu"
  container_app_environment_id = azurerm_container_app_environment.portal_cae.id
  resource_group_name          = azurerm_resource_group.rg_portal.name
  revision_mode                = "Single"

identity {
    type         = "UserAssigned"
    identity_ids = [ azurerm_user_assigned_identity.docker_id.id ]
  }
  
secret {
    name  = azurerm_container_registry.docker_cr.admin_username
    value = azurerm_container_registry.docker_cr.admin_password
  }
  
registry {
    server   = azurerm_container_registry.docker_cr.login_server
    identity = azurerm_user_assigned_identity.docker_id.id
  }
  
template {
    min_replicas = 1
    max_replicas = 1
    
container {
      name   = "${var.env_prefix}-portal-ci-westeu"
      image  = "xxxx.azurecr.io/yyyy:latest"
      cpu    = 0.5
      memory = "1Gi"
    }
  }
  
ingress {
    allow_insecure_connections = false
    external_enabled           = true
    target_port                = 80
    
traffic_weight {
      percentage = 100
    }
  }
  
tags = {
    Source = "${var.iac}"
  }
  
lifecycle {
    ignore_changes = [ 
      template[0].container[0].image,
      ingress.traffic_weight
    ]
  }
}

The container app generated seems to be exctly the same of the container app I created manually. The secret was not necessary because of the managed identity. I added it for trying to resolve my problem.

I remember you that the container environment is the same.

Now I try to publish the project in the container app created via Terraform. I get this error:

bt4Qt.png

The logs in output windows does not report anything interesting, anything different respect when I publish the project successfully in the other app.

Last thing that can be useful:
From the message I understand that the problem is in the registry. But

  1. Both publish profile use the same registry, the one I created with terraform.
  2. In any case, the image is correctly published in the registry, even if I get the error. The real thing is that when I get the error the image app in the app container does not change!
  3. I can publish correctly the image to the registry

Ah, last important thing:
If I edit and deploy new revision from Azure portal, everything works correctly. The container app seems have no problem.

It’s first time I using container app, and firt time I am creating the via terraform. So I hope I wrote everything.

Thank you

EDIT:

Here the last rows of the output windows:

Pushing image to the container app
========== Build: 3 succeeded, 0 failed, 2 up-to-date, 0 skipped ==========
========== Build started at 9:23 AM and took 02:34,887 minutes ==========
========== Publish: 1 succeeded, 0 failed, 0 skipped ==========
========== Publish started at 9:23 AM and took 02:34,887 minutes ==========

Waiting for container app to be ready...
The push refers to repository [xxxx.azurecr.io/yyyy]
d2a444b28773: Preparing
5f70bf18a086: Preparing
8c9001948539: Preparing
fd11bc2248c6: Preparing
9afe16093224: Preparing
2e665bc92a8b: Preparing
5a8a15f6e841: Preparing
ed7b0ef3bf5b: Preparing
5a8a15f6e841: Waiting
ed7b0ef3bf5b: Waiting
8c9001948539: Layer already exists
9afe16093224: Layer already exists
5f70bf18a086: Layer already exists
fd11bc2248c6: Layer already exists
d2a444b28773: Layer already exists
ed7b0ef3bf5b: Layer already exists
5a8a15f6e841: Layer already exists
2e665bc92a8b: Layer already exists
20230503072624: digest: sha256:xxxx size: 1996
Container app is ready.

It seems everything was ok… And it is the same output I receive when I publish on the app container I created manually

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,604 questions
Azure Container Apps
Azure Container Apps
An Azure service that provides a general-purpose, serverless container platform.
265 questions
{count} votes