Inappropriate value for attribute "cidr_blocks": element 0: string required

Trying to upgrade a module to V12. I am currently getting the above error. Question is, can i define a map list in the module rather than declaring as a variable ?

security_groups = [
module.ecs.asg_security_group_id,
aws_security_group.default_security_group.id,
aws_security_group.custom_security_group.id,
aws_security_group.pa_security_group.id,
aws_security_group.mashery_security_group.*.id,
]

If so, how can i go about this, many thanks

Hi @dannykitchen,

I’m not sure exactly how your question relates to the error message in the summary because the summary message is referring to cidr_blocks but your question is referring to security_groups. If you could share a little more detail about what you are doing (ideally, a full configuration, exactly what Terraform commands you ran, and what output you saw) then we might be able to help further.

With that said, the “element 0: string required” error message usually occurs when you have created a list of lists in a situation where a provider is expecting a list of strings. For example, if you were to write something like this:

cidr_blocks = [var.cidr_blocks]

If var.cidr_blocks were a list itself, e.g. ["192.168.0.0/16"], then this would evaluate like [["192.168.0.0/16"]], which would cause the error you saw because element zero of the outer list is itself a list, not a string.

Instead, that should be written like this:

cidr_blocks = var.cidr_blocks

If you need to combine multiple lists together to produce a value, you can use the concat function.

Apologies, wrong block

egress {
from_port = 0
to_port = 0
protocol = “-1”
cidr_blocks = [“0.0.0.0/0”]
}