using terraform, i'm trying to include the count in the tags of my resource using count.index, but getting this error :
Error: Incorrect attribute value type │ │ on ..\modules\sn\ressources.tf line 16, in resource "aws_subnet" "prod_sn": │ 16: tags = var.sn_tags[count.index] │ ├──────────────── │ │ count.index is a number, known only after apply │ │ var.sn_tags is a list of string, known only after apply │ │ Inappropriate value for attribute "tags": map of string required.
vars.tf
variable "sn_tags" {
type = list (string)
default = ["aa", "bb"]
}
ressources.tf
resource "aws_subnet" "prod_sn" {
count = length(var.sn_cidr)
vpc_id = var.vpc_id
cidr_block = var.sn_cidr[count.index]
availability_zone = data.aws_availability_zones.azs.names[count.index]
tags = var.sn_tags[count.index]
}
main.tf
# Create Public Subnet on availability_zone "3a"
module "publicSn-a" {
source = "../modules/sn"
vpc_id = module.vpc.vpcId
sn_cidr = ["10.0.1.0/24", "10.0.2.0/24"]
sn_tags = ["prodPublicA","prodPublicB"]
}