Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
1 task done
sammyxd2305 opened this issue Jun 23, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@sammyxd2305
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants