Pass list of objects into Terraform module as a parameter

I am using this main.tf module in my Terraform script to create an Azure Container App. I need to pass in a complex object with all the values needed to create a Container App.

In the main.tf file of this module, the complex object is iterated over and populates the secrets dynamic block. Notice that it will loop over the secrets list and populate each name/value pair.

resource "azurerm_container_app" "container_app" {
  for_each                     = {for app in var.container_apps: app.name => app}

  name                         = each.key
  ...
  template {
    dynamic "container" {
      ...
      }
    }
    ...
  }

  ...

  dynamic "secret" {
    for_each                     = each.value.secrets != null ? [each.value.secrets] : []
    content {
      name                       = secret.value.name
      value                      = secret.value.value
    }
  }
...

In the variables.tf file for the container_app module, the format of these parameters is specified. Notice that it wants a list of objects (with attributes name and value).

variable "container_apps" {
  description = "Specifies the container apps in the managed environment."
  type = list(object({
    name                           = string
    ...
    secrets                        = optional(list(object({
      name                         = string
      value                        = string
    })))
    ...
    template                       = object({
      containers                   = list(object({
        ...

I want to specify the list of secrets to pass. Here is how I am calling the module.

module "container_app" {
  source         = "./modules/container_app"
  location       = var.location
  ...
  container_apps = [ 
    {
      name = "api"
      ...
      configuration = {
        ...
      }
      secrets = [
        {
          name = "azure-openai-api-key",
          value = module.cognitive_services.azure_cognitive_services_key
        },
        {
          name = "container-registry-admin-secret",
          value = module.container_registry.container_registry_admin_password
        }
      ]
      ...
      template = {
        containers = [
          ...

My complex object includes variables, references to other module’s output, etc. Notice that the secrets object is a list of objects (with attributes name and value)

However, this results in an error when I try to apply the Terraform.

  ╷
  │ Error: Unsupported attribute
  │
  │   on modulescontainer_appmain.tf line 88, in resource "azurerm_container_app" 
  "container_app":
  │   88:       name                       = secret.value.name
  │     ├────────────────
  │     │ secret.value is list of object with 2 elements
  │
  │ Can't access attributes on a list of objects. Did you mean to access attribute "name" 
  for a specific element of the list, or across all elements of the list?
  ╵
  ╷
  │ Error: Unsupported attribute
  │
  │   on modulescontainer_appmain.tf line 89, in resource "azurerm_container_app" 
  "container_app":
  │   89:       value                      = secret.value.value
  │     ├────────────────
  │     │ secret.value is list of object with 2 elements
  │
  │ Can't access attributes on a list of objects. Did you mean to access attribute "value" 
  for a specific element of the list, or across all elements of the list?
  ╵ 

I don’t know how to pass in the correct list of object such that this module can then add those values as secrets in the Container App specification.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật