I have a working module where it will create Azure Storage account and another module will assign a role for the Azure Storage Account scope.
Here is my code:
> module "tf-state-storage" {
> source = "../terraform-resources/azure-tfsate-storage-account"
> storage_account_name = var.storage_account_name
> resource_group_name = module.tf-resource-group.name
> location = var.location
> tags = var.tags
> account_replication_type = var.account_replication_type
> account_tier = var.account_tier
> container_name = var.container_name
> }
>
> module "tfstate_role_assignment" {
> source = "../terraform-resources/azure-role-assignment"
> principal_id = module.user-assigned-identity.user_assinged_identity_principal_id
> role_name = "storage"
> scope_id = module.tf-state-storage.id
> principal_type = var.principal_type
> }
This was working fine, until I added count for the module tf-state-storage
Which is as shown below:
> module "tf-state-storage" {
> source = "../terraform-resources/azure-tfsate-storage-account"
> count = 5
> storage_account_name = element(var.storage_account_name, count.index)
> resource_group_name = module.tf-resource-group.name
> location = var.location
> tags = var.tags
> account_replication_type = var.account_replication_type
> account_tier = var.account_tier
> container_name = var.container_name
> }
>
> module "tfstate_role_assignment" {
> source = "../terraform-resources/azure-role-assignment"
> principal_id = module.user-assigned-identity.user_assinged_identity_principal_id
> role_name = "Storage"
> scope_id = module.tf-state-storage.id
> principal_type = var.principal_type
> }
Now I am having this attributes error where the count of total no of storage accounts needs to be passed for the proper or appropriate scope_id that’s being referred from the module tfstate_role_assignment
The error is:
â•·
│ Error: Unsupported attribute
│
│ on main.tf line 78, in module “tfstate_role_assignment”:
│ 78: scope_id = module.tf-state-storage.id
│ ├────────────────
│ │ module.tf-state-storage is a list of object
│
│ Can’t access attributes on a list of objects. Did you mean to access attribute “id” for a specific element of the list, or across all elements of the list?
╵
How can I fix this weird relationship here? Appreciate the help