Here are my variables –
variable "env" {
type =string
default = "env_dev"
}
variable "cidrs" {
type=map(list(string))
default = {
"env_dev" = ["10.10.0.0/16","10,0,0.0/8"]
"env_test" = ["10.102.20.0/23"]
}
variable "ports" {
type=map(list(string))
default = {
"env_dev" = ["5432","1521"]
"env_test" = ["3306"]
}
Ideally, the above variables should create 4 ingress rules for dev —
- “10.10.0.0/16”, 5432
- “10.10.0.0/16”, 1521
- “10,0,0.0/8” 5432
- “10,0,0.0/8” 1521
and one for test —
- “10.102.20.0/23” 3306
Finally, I would like to use aws_security_group to create the rules using the Dynamic block ( sample block — will populate after creating the final map variable)
resource "aws_security_group" "my-sg" {
vpc_id = var.vpc_id
name = "testing"
for_each = ....
dynamic = "ingress" {
content {
from_port = < *from the above variable*>
to_port = < *from the above variable* >
protocol = "tcp"
cidr_blocks = < *from the above variable* >
}
}
}
```
Thanks !