Reputation: 201
I need to add the same route to multiple route tables in AWS. I want to use terraform for this. For a single table I can use something like:
resource "aws_route" "route" {
route_table_id = "${var.routetableid}"
destination_cidr_block = "${var.destcidrblock}"
instance_id = "${aws_instance.vpn.id}"
}
However I'd like to add the route for every route_table_id that's specified by the user as a list. Is this possible?
Upvotes: 1
Views: 4175
Reputation: 56947
Terraform resources allow you to loop through them using the count meta parameter.
In your case you could do something like this:
variable "route_tables" { type = "list" }
resource "aws_route" "route" {
count = "${length(var.route_tables)}"
route_table_id = "${element(var.route_tables, count.index)}"
destination_cidr_block = "${var.destcidrblock}"
instance_id = "${aws_instance.vpn.id}"
}
Where route_tables
is a list of route table ids.
Upvotes: 4