Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Terraform在从VPC对等添加路由时不断更新aws_route_表_Terraform - Fatal编程技术网

Terraform在从VPC对等添加路由时不断更新aws_route_表

Terraform在从VPC对等添加路由时不断更新aws_route_表,terraform,Terraform,我已创建了一个aws\u vpc\u对等\u连接,以连接到我帐户中的vpc。我正在使用aws_route_table将路由应用到每个VPC的路由表,使用路由表部分中的变量设置路由 路由表正确地应用,但terraform希望在我每次应用之后都再次应用它。当数据从另一个模块提取时,其中一个vpc的vpc对等路由的网关id来自一个变量 resource "aws_route_table" "route-table" { vpc_id = "${aws_vpc.us-west-2-3.id}"

我已创建了一个
aws\u vpc\u对等\u连接
,以连接到我帐户中的vpc。我正在使用
aws_route_table
将路由应用到每个VPC的路由表,使用路由表部分中的变量设置路由

路由表正确地应用,但terraform希望在我每次应用之后都再次应用它。当数据从另一个模块提取时,其中一个vpc的vpc对等路由的网关id来自一个变量

resource "aws_route_table" "route-table" {
  vpc_id = "${aws_vpc.us-west-2-3.id}"

  route {
    cidr_block = "0.0.0.0/0"
    gateway_id = "${aws_internet_gateway.internet-gateway.id}"
  }

  route {
    cidr_block  = "10.12.0.0/16"
    gateway_id  = "${aws_vpc_peering_connection.usw2-1-usw2-3.id}"
  }

}
每次我
plan
apply
terraform想要更改
aws\u route\u表时

  ~ module.us-west-2-3.aws_route_table.route-table
      route.2485290482.cidr_block:                "10.12.0.0/16" => ""
      route.2485290482.egress_only_gateway_id:    "" => ""
      route.2485290482.gateway_id:                "" => ""
      route.2485290482.instance_id:               "" => ""
      route.2485290482.ipv6_cidr_block:           "" => ""
      route.2485290482.nat_gateway_id:            "" => ""
      route.2485290482.network_interface_id:      "" => ""
      route.2485290482.vpc_peering_connection_id: "pcx-0f3853c43363d28bb" => ""
      route.383599590.cidr_block:                 "" => "10.12.0.0/16"
      route.383599590.egress_only_gateway_id:     "" => ""
      route.383599590.gateway_id:                 "" => "pcx-0f3853c43363d28bb"
      route.383599590.instance_id:                "" => ""
      route.383599590.ipv6_cidr_block:            "" => ""
      route.383599590.nat_gateway_id:             "" => ""
      route.383599590.network_interface_id:       "" => ""
      route.383599590.vpc_peering_connection_id:  "" => ""
      route.4190671864.cidr_block:                "0.0.0.0/0" => "0.0.0.0/0"
      route.4190671864.egress_only_gateway_id:    "" => ""
      route.4190671864.gateway_id:                "igw-84caffe3" => "igw-84caffe3"
      route.4190671864.instance_id:               "" => ""
      route.4190671864.ipv6_cidr_block:           "" => ""
      route.4190671864.nat_gateway_id:            "" => ""
      route.4190671864.network_interface_id:      "" => ""
      route.4190671864.vpc_peering_connection_id: "" => ""

这是我应该报告的错误还是我做错了什么?

在第二个内联路由定义中,您指定的是网关id

网关id用于互联网访问。您想要使用的是vpc\u对等\u连接\u id

vpc_peering_connection_id  = "${aws_vpc_peering_connection.usw2-1-usw2-3.id}"
官方terraform文档提到,在混合gateway_id和nat_gateway_id时,您可能会陷入这一无限更新,我不会感到惊讶,在混合gateway_id和vpc_peering_连接时,情况也是如此:

关于gateway_id和nat_gateway_id的注意事项:AWS API对这两个属性非常宽容,可以使用指定为gateway id属性的nat id创建AWS_route_表资源。这将导致配置和状态文件之间的永久差异,因为API在返回的路由表中返回正确的参数。如果在aws_route_表资源中遇到持续差异,首先要检查的是是否指定了NAT ID而不是网关ID,反之亦然


资料来源:

非常感谢。Terraform在我的错误上走得这么远真是太神奇了。