Azure / terraform-azure-container-apps

A Terraform module to deploy a container app in Azure
https://github.com/Azure/terraform-azure-container-apps
36 stars 23 forks source link

Can't access attributes on a list of objects. Did you mean to access an attribute for a specific element of the list, or across all elements of the list? #3

Closed sammyxd2305 closed 1 year ago

sammyxd2305 commented 1 year ago

Is there an existing issue for this?

Greenfield/Brownfield provisioning

greenfield

Terraform Version

3.51.0

Module Version

newest

AzureRM Provider Version

newest

Affected Resource(s)/Data Source(s)

azurerm_container_app

Terraform Configuration Files

dynamic "volume" {
      for_each = each.value.template.volume == null ? [] : [each.value.template.volume]

      content {
        name         = volume.value.name
        storage_name = volume.value.storage_name
        storage_type = volume.value.storage_type
      }
    }

tfvars variables values

volume = [{
          name         = "test",
          storage_name = "test"
          storage_type = "AzureFile"
        }]

Debug Output/Panic Output

│ Error: Unsupported attribute
│
│   on ..\_modules\environment_v1\_modules\container-apps\main.tf line 121, in resource "azurerm_container_app" "container_app":
│  121:         name         = volume.value[each.value.template.volume.key].name
│     ├────────────────
│     │ each.value.template.volume is list of object with 1 element
│
│ Can't access attributes on a list of objects. Did you mean to access an attribute for a specific element of the list, or across all elements of the list?
╵
╷
│ Error: Unsupported attribute
│
│   on ..\_modules\environment_v1\_modules\container-apps\main.tf line 122, in resource "azurerm_container_app" "container_app":
│  122:         storage_name = volume.value[each.value.template.volume.key].storage_name
│     ├────────────────
│     │ each.value.template.volume is list of object with 1 element
│
│ Can't access attributes on a list of objects. Did you mean to access an attribute for a specific element of the list, or across all elements of the list?
╵
╷
│ Error: Unsupported attribute
│
│   on ..\_modules\environment_v1\_modules\container-apps\main.tf line 123, in resource "azurerm_container_app" "container_app":
│  123:         storage_type = volume.value[each.value.template.volume.key].storage_type
│     ├────────────────
│     │ each.value.template.volume is list of object with 1 element
│
│ Can't access attributes on a list of objects. Did you mean to access an attribute for a specific element of the list, or across all elements of the list?

Expected Behaviour

add volume to container

Actual Behaviour

error

Steps to Reproduce

terraform apply

Important Factoids

No response

References

Solution to the Problem for me: dynamic "volume" { for_each = each.value.template.volume == null ? [] : [each.value.template.volume]

  content {
    name         = volume.value[volume.key].name
    storage_name = volume.value[volume.key].storage_name
    storage_type = volume.value[volume.key].storage_type
  }
}

(Added volume.key)