Skip to content

Terraform apply fails for azurerm_container_app even though resource exists in state #31540

@VenuPentyala22

Description

@VenuPentyala22

Is there an existing issue for this?

  • I have searched the existing issues

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave comments along the lines of "+1", "me too" or "any updates", they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment and review the contribution guide to help.

Terraform Version

1.14.3

AzureRM Provider Version

4.47.0

Affected Resource(s)/Data Source(s)

azurerm_container_app

Terraform Configuration Files

resource "azurerm_container_app" "app" {
  name                         = app_name
  container_app_environment_id = container_app_environment_id
  resource_group_name          = rg
  revision_mode                = "Single"

  workload_profile_name = "Consumption"

  registry {
    server   = server_name
    identity = data.azurerm_user_assigned_identity.app.id
  }

.....

}

Debug Output/Panic Output

│ Error: a resource with the ID "/subscriptions/***/resourceGroups/rg/providers/Microsoft.App/containerApps/containerapp" already exists - to be managed via Terraform this resource needs to be imported into the State. Please see the resource documentation for "azurerm_container_app" for more information
│ 
│   with module.container_app.azurerm_container_app.app,
│   on .terraform/modules/container_app/azure/modules/container-app/main.tf line 1, in resource "azurerm_container_app" "app":
│    1: resource "azurerm_container_app" "app" {

Expected Behaviour

Terraform should consistently manage existing Azure Container Apps without failing.

Terraform state should be retained across deployments.

Manual deletion of resources should not be required.

Resources should not be recreated or orphaned between runs.

Actual Behaviour

terraform apply fails stating the Container App already exists.

The resource is present in the Terraform state at the time of failure.

Current workaround is to manually delete:

The Azure Container App

The associated Private DNS record

After deletion, the next deployment succeeds, but the issue reoccurs on subsequent deployments.

Steps to Reproduce

Deploy an Azure Container App using Terraform.

Run a subsequent terraform apply.

Terraform fails with an error stating the resource already exists and must be imported into state.

Important Factoids

No response

References

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions