Have a yaml file as below, cannot create the prefix list. Please help to fix the error
Rules:
- Cidrs:
- Cidr: 192.168.1.0/32
Description: "Test"
- Cidr: 192.168.1.10/32
Description: "Test1"
- Ports:
- FromPort: 80
ToPort: 80
IpProtocol: tcp
trying to use iterate the yaml files using local block as below
locals {
config-extended = yamldecode(file("test-extended.yaml"))
item = flatten([
for Rules in local.config-extended : [
for Ports in Rules.Ports : {
FromPort = Ports.FromPort
ToPort = Ports.ToPort
IpProtocol = Ports.IpProtocol
}
]
])
}
resource "aws_vpc" "testing" {
cidr_block = "10.0.0.0/16"
tags = {
"Name" = "testing"
}
}
resource "aws_ec2_managed_prefix_list" "test-pl" {
name = "test-pl"
address_family = "IPv4"
max_entries = 7
}
resource "aws_ec2_managed_prefix_list_entry" "entry" {
for_each = {
for rule in local.item : item.Rules => rule
}
cidr = each.value.Cidrs.Cidr
description = each.value.Cidrs.Description
prefix_list_id = aws_ec2_managed_prefix_list.test-pl.id
}
resource "aws_security_group" "using-prefix-list" {
name = "using-prefix-list"
vpc_id = aws_vpc.testing.id
description = "Allow inbound traffic using Prefix List"
ingress {
description = "Allow inbound traffic from the prefix list"
from_port = 80
to_port = 80
protocol = "tcp"
prefix_list_ids = [aws_ec2_managed_prefix_list.test-pl.id]
}
tags = {
Name = "using-prefix-list"
}
}
When try to test for clearing the Prefix list part I get the below error
terraform plan
╷
│ Error: Unsupported attribute
│
│ on testing.tf line 12, in locals:
│ 12: for Ports in Rules.Ports : {
│
│ This value does not have any attributes.