简体   繁体   English

terraform-将路线添加到多个路线表中

[英]terraform - add route to multiple route tables aws

I need to add the same route to multiple route tables in AWS. 我需要将同一路由添加到AWS中的多个路由表。 I want to use terraform for this. 我想为此使用terraform。 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. 但是我想为用户指定为列表的每个route_table_id添加路由。 Is this possible? 这可能吗?

Terraform resources allow you to loop through them using the count meta parameter . Terraform资源使您可以使用count元参数遍历它们。

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. 其中route_tables是路由表ID的列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM