Reputation: 389
I've gone through the source code of CDKTF TerraformIterator, and the AWS Subnets to try and find a way to iterate over Subnet when setting for_each. I'm not sure how to do this as the iterator requires a list of strings and I don't see anything that would return subnet ids from that class. Here is some Python pseudo code:
public_subnets = Subnet(self, 'default-public',
for_each = public_subnet_iterator,
availability_zone_id = public_subnet_iterator.get_string('availability_zone'),
cidr_block = public_subnet_iterator.get_string('CIDR'),
vpc_id = default_vpc.id
tags = Tags.commons_with_name('default-public')
)
route_table = RouteTable(self, 'public-subnets',
vpc_id = default_vpc.id,
RouteTableRoute(
cidr_block = '0.0.0.0/0',
gateway_id = default_gateway.id
),
tags = Tags.commons_with_name('public-subnet-routing')
)
routable_subnets = TerraformIterator.fromList(public_subnets.?????)
RouteTableAssociation(self, 'public-subnet-routes',
for_each = routable_subnets,
etc...
)
How can I iterate over the subnets to generate these route table associations?
Upvotes: 0
Views: 276
Reputation: 11921
This is currently not supported in CDKTF, but will likely change in the upcoming version 0.16. See https://github.com/hashicorp/terraform-cdk/issues/2024 and https://github.com/hashicorp/terraform-cdk/pull/2739 for more context. Until it's supported you would need to use an escape hatch to make it work or if the publicSubnetIterator
is using a static list you could also use a for loop.
Upvotes: 1