I am porting a custom made deployment infrastructure to terraform. In that custom codebase there is something that says - fetch all available subnets from default region vpc but only those that have 20 or more available IPv4 addresses.
So I was experimenting with this code
data "aws_vpc" "main" {
default = true
}
data "aws_subnets" "vpcsubnets" {
filter {
name = "vpc-id"
values = [data.aws_vpc.main.id]
}
filter {
name = "default-for-az"
values = [true]
}
filter {
name = "state"
values = ["available"]
}
}
output "ids2" {
value = {
for k, v in data.aws_subnets.vpcsubnets : k => v if v.available_ip_address_count > 20
}
}
But I get errors like these
Error: Invalid reference
│
│ on main.tf line 51, in output "ids2":
│ 51: for k, vid in data.aws_subnets.vpcsubnets : k => v if v.available_ip_address_count > 20
│
│ A reference to a resource type must be followed by at least one attribute access, specifying the resource name.
Using Terraform 1.0.8 and aws provider 3.62