terraform-provider-azurerm icon indicating copy to clipboard operation
terraform-provider-azurerm copied to clipboard

azurerm_container_app env blocks plan uses index instead of key

Open nickwilliams-ee opened this issue 6 months ago • 2 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

Community Note

  • Please vote on this issue by adding a :thumbsup: 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.12.1

AzureRM Provider Version

4.30.0

Affected Resource(s)/Data Source(s)

azurerm_container_app

Terraform Configuration Files

resource "azurerm_resource_group" "example" {
  name     = "example-resources"
  location = "West Europe"
}

resource "azurerm_container_app" "example" {
  name                         = "example-app"
  container_app_environment_id = azurerm_container_app_environment.example.id
  resource_group_name          = azurerm_resource_group.example.name
  revision_mode                = "Single"

  template {
    container {
      name   = "examplecontainerapp"
      image  = "mcr.microsoft.com/k8se/quickstart:latest"
      cpu    = 0.25
      memory = "0.5Gi"

      env {
         name = "A"
         value = "A-val"
      }

      env {
         name = "B"
         value = "B-val"
      }
    }
  }
}

Debug Output/Panic Output

N/A

Expected Behaviour

  • Adding a new env block should result in a single change in the plan - the addition of a env var
  • Removing an env should result in a single change in the plan - the destruction of the env var

Actual Behaviour

It seems env blocks are being tracked by index, so adding or removing an env block causes a plan that manipulates all env blocks.

Image

Steps to Reproduce

  1. Create a container app with 2 env blocks
  2. Add a new env block
  3. The plan shows all env blocks which makes evaluating the plan difficult / impossible

Important Factoids

No response

References

No response

nickwilliams-ee avatar May 29 '25 01:05 nickwilliams-ee

Hi @nickwilliams-ee thanks for opening this issue. Per the provided Steps to Reproduce, I got the following results. I assume everything working fine. From the screenshot information provided, it seems that all three env blocks have changed, could you please check again?

Step1: Create an azurerm_container_app with two env blocks by the following config.

terraform {
  required_providers {
    azurerm = {
      version = "4.30.0" 
    }
  }
}

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "example" {
  name     = "example-resources-29743"
  location = "West Europe"
}

resource "azurerm_container_app_environment" "example" {
  name                = "acctest-CAEnv29743"
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_resource_group.example.location
}


resource "azurerm_container_app" "example" {
  name                         = "example-app-29743"
  container_app_environment_id = azurerm_container_app_environment.example.id
  resource_group_name          = azurerm_resource_group.example.name
  revision_mode                = "Single"

  template {
    container {
      name   = "examplecontainerapp"
      image  = "mcr.microsoft.com/k8se/quickstart:latest"
      cpu    = 0.25
      memory = "0.5Gi"

      env {
         name = "A"
         value = "A-val"
      }

      env {
         name = "B"
         value = "B-val"
      }   
    }
  }
}

Step2: Add a new env block as follows.

env {
         name = "C"
         value = "C-val"
      }

Step3: Terraform plan.

Image

sinbai avatar May 30 '25 08:05 sinbai

I also have this issue. I often want to keep related env blocks together so we don't always just add a new one to the bottom of the list. I can imagine some people may want to order them alphabetically too but if an env isn't added as the last block, it will cause this domino effect. The same goes for removing a block that isn't the last env variable.

It wasn't included in your response @sinbai but I assume you added the env block "C" to the bottom of the blocks under "A" and "B" hence why it looks correct. If you added the "C" env block between "A" and "B" then it won't look correct. You could also remove the "A" env block to reproduce the same kind of thing where it will look like A --> changed to B and then B was deleted.

katelewis13 avatar Jun 17 '25 06:06 katelewis13

This issue is really frustrating in day-to-day use. Every time a single env variable changes, Terraform thinks the whole list changed, which creates massive plan noise and unnecessary revisions.

It feels like something that should be relatively straightforward to fix (matching env blocks by name instead of list index), and resolving it would have a huge positive impact for users. This kind of improvement really stands out — it makes working with Container Apps via Terraform so much smoother.

Appreciate all the work on the provider, but I hope this one gets prioritized — it’s a small change with a big user-experience payoff.

gamoudis avatar Nov 06 '25 17:11 gamoudis