Search code examples
azureterraform-provider-azureazure-container-apps

Terraform property for specifying the plan in Azure Container Apps Environment


How to specify plan type = Consumption and Dedicated workload profiles for Azure Container Apps Environment using terraform 3.49.0. I am using below snippet:


# main.tf
resource "azurerm_container_app_environment" "aca_env" {
    for_each = { for aca_env in var.aca_envs : aca_env.name => aca_env}
  name = each.value.name
  ...
}

# .tfvars
aca_envs = [
  {
    name                 = "myacaenv"
    resource_group_name  = "myrg"
    location             = "West Europe"
    subnet_id            = "mysubnet"
    internal_load_balancer_enabled = true
    tags                 = {}
    roles = []
  }
]

enter image description here


Solution

  • EDIT March 2024

    The latest terraform version (3.97.1) now support workload profile (see documentation):

    resource "azurerm_container_app_environment" "example" {
      name                       = "my-environment"
      location                   = azurerm_resource_group.example.location
      resource_group_name        = azurerm_resource_group.example.name
      log_analytics_workspace_id = azurerm_log_analytics_workspace.example.id
      workload_profile {
        name                  = "Consumption"
        workload_profile_type = "Consumption"
        minimum_count         = 0
        maximum_count         = 1
      }
    }
    

    Original POST

    Terraform does not support it yet (see related issue on github).

    You could use the azapi provider to deploy a container app with a preview plan:

    terraform {
      required_providers {
        azapi = {
          source  = "Azure/azapi"
        }
      }
    }
    
    resource "azapi_resource" "aca_env" {
      type      = "Microsoft.App/managedEnvironments@2022-11-01-preview"
      parent_id = azurerm_resource_group.rg.id
      location  = azurerm_resource_group.rg.location
      name      = "my-aca-env-name"
      body   = jsonencode({
        properties = {
          appLogsConfiguration = {
            ...
          }
          workloadProfiles = [
            {
              name = "workload-profile-name"
              workloadProfileType = "workload-profile-type"
            }
          ]
          ...
        }
     })
    }
    

    Bicep/ARM documentation for container app environment can be found here .