Terraform删除路由表,然后在第二次运行时将其添加(无更改)。错误或我缺少什么吗?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Terraform删除路由表,然后在第二次运行时将其添加(无更改)。错误或我缺少什么吗?相关的知识,希望对你有一定的参考价值。
如您所见,下面我将两次应用相同的代码(不做任何更改)。第一次删除表路由。第二次重新创建它们。
这种行为使我发疯。每次更改网络时,都需要运行terraform两次以显示路由表。
非常欢迎在此问题上发表意见。
$ terraform apply
aws_vpc.vpc: Refreshing state... (ID: [REDACTED])
aws_route_table.public_route: Refreshing state... (ID: [REDACTED])
aws_route.peer_private_1: Refreshing state... (ID: [REDACTED])
aws_route.billing_private_1: Refreshing state... (ID: [REDACTED])
aws_route.billing_public_1: Refreshing state... (ID: [REDACTED])
aws_route_table_association.route_table_pub_1: Refreshing state... (ID: [REDACTED])
aws_route.rt_public_1b: Refreshing state... (ID: [REDACTED])
aws_route.local_public_1: Refreshing state... (ID: [REDACTED])
aws_route.rt_public_1a: Refreshing state... (ID: [REDACTED])
aws_route_table.private_route_1: Refreshing state... (ID: [REDACTED])
aws_route_table_association.route_table_priv_1: Refreshing state... (ID: [REDACTED])
aws_route.rt_private_1a: Refreshing state... (ID: [REDACTED])
aws_route.local_private_1: Refreshing state... (ID: [REDACTED])
aws_route.rt_private_1b: Refreshing state... (ID: [REDACTED])
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
~ update in-place
Terraform will perform the following actions:
~ module.vpc_network.aws_route_table.private_route_1
route.#: "4" => "1"
route.1.cidr_block: "" => "[REDACTED]"
route.1.egress_only_gateway_id: "" => ""
route.1.gateway_id: "" => "[REDACTED]"
route.1.instance_id: "" => ""
route.1.ipv6_cidr_block: "" => ""
route.1.nat_gateway_id: "" => ""
route.1.network_interface_id: "" => ""
route.1.vpc_peering_connection_id: "" => ""
route.2.cidr_block: "[REDACTED]" => ""
route.2.egress_only_gateway_id: "" => ""
route.2.gateway_id: "" => ""
route.2.instance_id: "" => ""
route.2.ipv6_cidr_block: "" => ""
route.2.nat_gateway_id: "[REDACTED]" => ""
route.2.network_interface_id: "" => ""
route.2.vpc_peering_connection_id: "" => ""
route.3.cidr_block: "[REDACTED]" => ""
route.3.egress_only_gateway_id: "" => ""
route.3.gateway_id: "" => ""
route.3.instance_id: "" => ""
route.3.ipv6_cidr_block: "" => ""
route.3.nat_gateway_id: "" => ""
route.3.network_interface_id: "" => ""
route.3.vpc_peering_connection_id: "[REDACTED]" => ""
route.4.cidr_block: "[REDACTED]" => ""
route.4.egress_only_gateway_id: "" => ""
route.4.gateway_id: "" => ""
route.4.instance_id: "" => ""
route.4.ipv6_cidr_block: "" => ""
route.4.nat_gateway_id: "" => ""
route.4.network_interface_id: "" => ""
route.4.vpc_peering_connection_id: "[REDACTED]" => ""
route.5.cidr_block: "[REDACTED]" => ""
route.5.egress_only_gateway_id: "" => ""
route.5.gateway_id: "" => ""
route.5.instance_id: "" => ""
route.5.ipv6_cidr_block: "" => ""
route.5.nat_gateway_id: "" => ""
route.5.network_interface_id: "" => ""
route.5.vpc_peering_connection_id: "[REDACTED]" => ""
~ module.vpc_network.aws_route_table.public_route
route.#: "4" => "1"
route.3.cidr_block: "[REDACTED]" => ""
route.3.egress_only_gateway_id: "" => ""
route.3.gateway_id: "" => ""
route.3.instance_id: "" => ""
route.3.ipv6_cidr_block: "" => ""
route.3.nat_gateway_id: "" => ""
route.3.network_interface_id: "" => ""
route.3.vpc_peering_connection_id: "[REDACTED]" => ""
route.6.cidr_block: "[REDACTED]" => "[REDACTED]"
route.6.egress_only_gateway_id: "" => ""
route.6.gateway_id: "[REDACTED]" => "[REDACTED]"
route.6.instance_id: "" => ""
route.6.ipv6_cidr_block: "" => ""
route.6.nat_gateway_id: "" => ""
route.6.network_interface_id: "" => ""
route.6.vpc_peering_connection_id: "" => ""
route.4.cidr_block: "[REDACTED]" => ""
route.4.egress_only_gateway_id: "" => ""
route.4.gateway_id: "" => ""
route.4.instance_id: "" => ""
route.4.ipv6_cidr_block: "" => ""
route.4.nat_gateway_id: "" => ""
route.4.network_interface_id: "" => ""
route.4.vpc_peering_connection_id: "[REDACTED]" => ""
route.5.cidr_block: "[REDACTED]" => ""
route.5.egress_only_gateway_id: "" => ""
route.5.gateway_id: "" => ""
route.5.instance_id: "" => ""
route.5.ipv6_cidr_block: "" => ""
route.5.nat_gateway_id: "" => ""
route.5.network_interface_id: "" => ""
route.5.vpc_peering_connection_id: "[REDACTED]" => ""
Plan: 0 to add, 2 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
module.vpc_network.aws_route_table.private_route_1: Modifying... (ID: [REDACTED])
route.#: "4" => "1"
route.1.cidr_block: "" => "[REDACTED]"
route.1.egress_only_gateway_id: "" => ""
route.1.gateway_id: "" => "[REDACTED]"
route.1.instance_id: "" => ""
route.1.ipv6_cidr_block: "" => ""
route.1.nat_gateway_id: "" => ""
route.1.network_interface_id: "" => ""
route.1.vpc_peering_connection_id: "" => ""
route.2.cidr_block: "[REDACTED]" => ""
route.2.egress_only_gateway_id: "" => ""
route.2.gateway_id: "" => ""
route.2.instance_id: "" => ""
route.2.ipv6_cidr_block: "" => ""
route.2.nat_gateway_id: "[REDACTED]" => ""
route.2.network_interface_id: "" => ""
route.2.vpc_peering_connection_id: "" => ""
route.3.cidr_block: "[REDACTED]" => ""
route.3.egress_only_gateway_id: "" => ""
route.3.gateway_id: "" => ""
route.3.instance_id: "" => ""
route.3.ipv6_cidr_block: "" => ""
route.3.nat_gateway_id: "" => ""
route.3.network_interface_id: "" => ""
route.3.vpc_peering_connection_id: "[REDACTED]" => ""
route.4.cidr_block: "[REDACTED]" => ""
route.4.egress_only_gateway_id: "" => ""
route.4.gateway_id: "" => ""
route.4.instance_id: "" => ""
route.4.ipv6_cidr_block: "" => ""
route.4.nat_gateway_id: "" => ""
route.4.network_interface_id: "" => ""
route.4.vpc_peering_connection_id: "[REDACTED]" => ""
route.5.cidr_block: "[REDACTED]" => ""
route.5.egress_only_gateway_id: "" => ""
route.5.gateway_id: "" => ""
route.5.instance_id: "" => ""
route.5.ipv6_cidr_block: "" => ""
route.5.nat_gateway_id: "" => ""
route.5.network_interface_id: "" => ""
route.5.vpc_peering_connection_id: "[REDACTED]" => ""
module.vpc_network.aws_route_table.private_route_2: Modifying... (ID: [REDACTED])
route.#: "4" => "1"
route.1.cidr_block: "" => "[REDACTED]"
route.1.egress_only_gateway_id: "" => ""
route.1.gateway_id: "" => "[REDACTED]"
route.1.instance_id: "" => ""
route.1.ipv6_cidr_block: "" => ""
route.1.nat_gateway_id: "" => ""
route.1.network_interface_id: "" => ""
route.1.vpc_peering_connection_id: "" => ""
route.2.cidr_block: "[REDACTED]" => ""
route.2.egress_only_gateway_id: "" => ""
route.2.gateway_id: "" => ""
route.2.instance_id: "" => ""
route.2.ipv6_cidr_block: "" => ""
route.2.nat_gateway_id: "[REDACTED]" => ""
route.2.network_interface_id: "" => ""
route.2.vpc_peering_connection_id: "" => ""
route.3.cidr_block: "[REDACTED]" => ""
route.3.egress_only_gateway_id: "" => ""
route.3.gateway_id: "" => ""
route.3.instance_id: "" => ""
route.3.ipv6_cidr_block: "" => ""
route.3.nat_gateway_id: "" => ""
route.3.network_interface_id: "" => ""
route.3.vpc_peering_connection_id: "[REDACTED]" => ""
route.4.cidr_block: "[REDACTED]" => ""
route.4.egress_only_gateway_id: "" => ""
route.4.gateway_id: "" => ""
route.4.instance_id: "" => ""
route.4.ipv6_cidr_block: "" => ""
route.4.nat_gateway_id: "" => ""
route.4.network_interface_id: "" => ""
route.4.vpc_peering_connection_id: "[REDACTED]" => ""
route.5.cidr_block: "[REDACTED]" => ""
route.5.egress_only_gateway_id: "" => ""
route.5.gateway_id: "" => ""
route.5.instance_id: "" => ""
route.5.ipv6_cidr_block: "" => ""
route.5.nat_gateway_id: "" => ""
route.5.network_interface_id: "" => ""
route.5.vpc_peering_connection_id: "[REDACTED]" => ""
module.vpc_network.aws_route_table.public_route: Modifying... (ID: [REDACTED])
route.#: "4" => "1"
route.3.cidr_block: "[REDACTED]" => ""
route.3.egress_only_gateway_id: "" => ""
route.3.gateway_id: "" => ""
route.3.instance_id: "" => ""
route.3.ipv6_cidr_block: "" => ""
route.3.nat_gateway_id: "" => ""
route.3.network_interface_id: "" => ""
route.3.vpc_peering_connection_id: "[REDACTED]" => ""
route.6.cidr_block: "[REDACTED]" => "[REDACTED]"
route.6.egress_only_gateway_id: "" => ""
route.6.gateway_id: "[REDACTED]" => "[REDACTED]"
route.6.instance_id: "" => ""
route.6.ipv6_cidr_block: "" => ""
route.6.nat_gateway_id: "" => ""
route.6.network_interface_id: "" => ""
route.6.vpc_peering_connection_id: "" => ""
route.4.cidr_block: "[REDACTED]" => ""
route.4.egress_only_gateway_id: "" => ""
route.4.gateway_id: "" => ""
route.4.instance_id: "" => ""
route.4.ipv6_cidr_block: "" => ""
route.4.nat_gateway_id: "" => ""
route.4.network_interface_id: "" => ""
route.4.vpc_peering_connection_id: "[REDACTED]" => ""
route.5.cidr_block: "[REDACTED]" => ""
route.5.egress_only_gateway_id: "" => ""
route.5.gateway_id: "" => ""
route.5.instance_id: "" => ""
route.5.ipv6_cidr_block: "" => ""
route.5.nat_gateway_id: "" => ""
route.5.network_interface_id: "" => ""
route.5.vpc_peering_connection_id: "[REDACTED]" => ""
module.vpc_network.aws_route_table.public_route: Modifications complete after 1s (ID: [REDACTED])
module.vpc_network.aws_route_table.private_route_1: Modifications complete after 1s (ID: [REDACTED])
module.vpc_network.aws_route_table.private_route_2: Modifications complete after 1s (ID: [REDACTED])
Apply complete! Resources: 0 added, 5 changed, 0 destroyed.
$ terraform apply
aws_route_table.public_route: Refreshing state... (ID: [REDACTED])
aws_route.peer_private_1: Refreshing state... (ID: [REDACTED])
aws_vpc_peering_connection_accepter.peer: Refreshing state... (ID: [REDACTED])
aws_route.peer_public_1: Refreshing state... (ID: [REDACTED])
aws_route.billing_private_1: Refreshing state... (ID: [REDACTED])
aws_route.billing_public_1: Refreshing state... (ID: [REDACTED])
aws_route_table_association.route_table_pub_1: Refreshing state... (ID: [REDACTED])
aws_route.rt_public_1a: Refreshing state... (ID: [REDACTED])
aws_route.rt_public_1b: Refreshing state... (ID: [REDACTED])
aws_route.local_public_1: Refreshing state... (ID: [REDACTED])
aws_route_table.private_route_1: Refreshing state... (ID: [REDACTED])
aws_route_table_association.route_table_priv_1: Refreshing state... (ID: [REDACTED])
aws_route.local_private_1: Refreshing state... (ID: [REDACTED])
aws_route.rt_private_1a: Refreshing state... (ID: [REDACTED])
aws_route.rt_private_1b: Refreshing state... (ID: [REDACTED])
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
~ update in-place
Terraform will perform the following actions:
~ module.vpc_network.aws_route_table.private_route_1
route.1.cidr_block: "" => "[REDACTED]"
route.1.egress_only_gateway_id: "" => ""
route.1.gateway_id: "" => "[REDACTED]"
route.1.instance_id: "" => ""
route.1.ipv6_cidr_block: "" => ""
route.1.nat_gateway_id: "" => ""
route.1.network_interface_id: "" => ""
route.1.vpc_peering_connection_id: "" => ""
route.2.cidr_block: "[REDACTED]" => ""
route.2.egress_only_gateway_id: "" => ""
route.2.gateway_id: "" => ""
route.2.instance_id: "" => ""
route.2.ipv6_cidr_block: "" => ""
route.2.nat_gateway_id: "[REDACTED]" => ""
route.2.network_interface_id: "" => ""
route.2.vpc_peering_connection_id: "" => ""
+ module.vpc_peering.aws_route.local_private_1
id: <computed>
destination_cidr_block: "[REDACTED]"
destination_prefix_list_id: <computed>
egress_only_gateway_id: <computed>
gateway_id: <computed>
instance_id: <computed>
instance_owner_id: <computed>
nat_gateway_id: <computed>
network_interface_id: <computed>
origin: <computed>
route_table_id: "[REDACTED]"
state: <computed>
vpc_peering_connection_id: "[REDACTED]"
+ module.vpc_peering.aws_route.local_public_1
id: <computed>
destination_cidr_block: "[REDACTED]"
destination_prefix_list_id: <computed>
egress_only_gateway_id: <computed>
gateway_id: <computed>
instance_id: <computed>
instance_owner_id: <computed>
nat_gateway_id: <computed>
network_interface_id: <computed>
origin: <computed>
route_table_id: "[REDACTED]"
state: <computed>
vpc_peering_connection_id: "[REDACTED]"
+ module.vpc_peering_billing.aws_route.rt_private_1a
id: <computed>
destination_cidr_block: "[REDACTED]"
destination_prefix_list_id: <computed>
egress_only_gateway_id: <computed>
gateway_id: <computed>
instance_id: <computed>
instance_owner_id: <computed>
nat_gateway_id: <computed>
network_interface_id: <computed>
origin: <computed>
route_table_id: "[REDACTED]"
state: <computed>
vpc_peering_connection_id: "[REDACTED]"
+ module.vpc_peering_billing.aws_route.rt_private_1b
id: <computed>
destination_cidr_block: "[REDACTED]"
destination_prefix_list_id: <computed>
egress_only_gateway_id: <computed>
gateway_id: <computed>
instance_id: <computed>
instance_owner_id: <computed>
nat_gateway_id: <computed>
network_interface_id: <computed>
origin: <computed>
route_table_id: "[REDACTED]"
state: <computed>
vpc_peering_connection_id: "[REDACTED]"
+ module.vpc_peering_billing.aws_route.rt_public_1a
id: <computed>
destination_cidr_block: "[REDACTED]"
destination_prefix_list_id: <computed>
egress_only_gateway_id: <computed>
gateway_id: <computed>
instance_id: <computed>
instance_owner_id: <computed>
nat_gateway_id: <computed>
network_interface_id: <computed>
origin: <computed>
route_table_id: "[REDACTED]"
state: <computed>
vpc_peering_connection_id: "[REDACTED]"
+ module.vpc_peering_billing.aws_route.rt_public_1b
id: <computed>
destination_cidr_block: "[REDACTED]"
destination_prefix_list_id: <computed>
egress_only_gateway_id: <computed>
gateway_id: <computed>
instance_id: <computed>
instance_owner_id: <computed>
nat_gateway_id: <computed>
network_interface_id: <computed>
origin: <computed>
route_table_id: "[REDACTED]"
state: <computed>
vpc_peering_connection_id: "[REDACTED]"
Plan: 4 to add, 1 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value:
module.vpc_peering_billing.aws_route.rt_public_1a: Creating...
destination_cidr_block: "" => "[REDACTED]"
destination_prefix_list_id: "" => "<computed>"
egress_only_gateway_id: "" => "<computed>"
gateway_id: "" => "<computed>"
instance_id: "" => "<computed>"
instance_owner_id: "" => "<computed>"
nat_gateway_id: "" => "<computed>"
network_interface_id: "" => "<computed>"
origin: "" => "<computed>"
route_table_id: "" => "[REDACTED]"
state: "" => "<computed>"
vpc_peering_connection_id: "" => "[REDACTED]"
module.vpc_peering_billing.aws_route.rt_public_1b: Creating...
destination_cidr_block: "" => "[REDACTED]"
destination_prefix_list_id: "" => "<computed>"
egress_only_gateway_id: "" => "<computed>"
gateway_id: "" => "<computed>"
instance_id: "" => "<computed>"
instance_owner_id: "" => "<computed>"
nat_gateway_id: "" => "<computed>"
network_interface_id: "" => "<computed>"
origin: "" => "<computed>"
route_table_id: "" => "[REDACTED]"
state: "" => "<computed>"
vpc_peering_connection_id: "" => "[REDACTED]"
module.vpc_network.aws_route_table.private_route_1: Modifying... (ID: [REDACTED])
route.1.cidr_block: "" => "[REDACTED]"
route.1.egress_only_gateway_id: "" => ""
route.1.gateway_id: "" => "[REDACTED]"
route.1.instance_id: "" => ""
route.1.ipv6_cidr_block: "" => ""
route.1.nat_gateway_id: "" => ""
route.1.network_interface_id: "" => ""
route.1.vpc_peering_connection_id: "" => ""
route.2.cidr_block: "[REDACTED]" => ""
route.2.egress_only_gateway_id: "" => ""
route.2.gateway_id: "" => ""
route.2.instance_id: "" => ""
route.2.ipv6_cidr_block: "" => ""
route.2.nat_gateway_id: "[REDACTED]" => ""
route.2.network_interface_id: "" => ""
route.2.vpc_peering_connection_id: "" => ""
module.vpc_peering.aws_route.local_public_1: Creating...
destination_cidr_block: "" => "[REDACTED]"
destination_prefix_list_id: "" => "<computed>"
egress_only_gateway_id: "" => "<computed>"
gateway_id: "" => "<computed>"
instance_id: "" => "<computed>"
instance_owner_id: "" => "<computed>"
nat_gateway_id: "" => "<computed>"
network_interface_id: "" => "<computed>"
origin: "" => "<computed>"
route_table_id: "" => "[REDACTED]"
state: "" => "<computed>"
vpc_peering_connection_id: "" => "[REDACTED]"
module.vpc_peering_billing.aws_route.rt_public_1b: Creation complete after 0s (ID: [REDACTED])
module.vpc_peering.aws_route.local_public_1: Creation complete after 0s (ID: [REDACTED])
module.vpc_peering_billing.aws_route.rt_public_1a: Creation complete after 0s (ID: [REDACTED])
module.vpc_network.aws_route_table.private_route_1: Modifications complete after 0s (ID: [REDACTED])
module.vpc_peering_billing.aws_route.rt_private_1b: Creating...
destination_cidr_block: "" => "[REDACTED]"
destination_prefix_list_id: "" => "<computed>"
egress_only_gateway_id: "" => "<computed>"
gateway_id: "" => "<computed>"
instance_id: "" => "<computed>"
instance_owner_id: "" => "<computed>"
nat_gateway_id: "" => "<computed>"
network_interface_id: "" => "<computed>"
origin: "" => "<computed>"
route_table_id: "" => "[REDACTED]"
state: "" => "<computed>"
vpc_peering_connection_id: "" => "[REDACTED]"
module.vpc_peering_billing.aws_route.rt_private_1a: Creating...
destination_cidr_block: "" => "[REDACTED]"
destination_prefix_list_id: "" => "<computed>"
egress_only_gateway_id: "" => "<computed>"
gateway_id: "" => "<computed>"
instance_id: "" => "<computed>"
instance_owner_id: "" => "<computed>"
nat_gateway_id: "" => "<computed>"
network_interface_id: "" => "<computed>"
origin: "" => "<computed>"
route_table_id: "" => "[REDACTED]"
state: "" => "<computed>"
vpc_peering_connection_id: "" => "[REDACTED]"
module.vpc_peering.aws_route.local_private_1: Creating...
destination_cidr_block: "" => "[REDACTED]"
destination_prefix_list_id: "" => "<computed>"
egress_only_gateway_id: "" => "<computed>"
gateway_id: "" => "<computed>"
instance_id: "" => "<computed>"
instance_owner_id: "" => "<computed>"
nat_gateway_id: "" => "<computed>"
network_interface_id: "" => "<computed>"
origin: "" => "<computed>"
route_table_id: "" => "[REDACTED]"
state: "" => "<computed>"
vpc_peering_connection_id: "" => "[REDACTED]"
module.vpc_peering.aws_route.local_private_1: Creation complete after 0s (ID: [REDACTED])
module.vpc_peering_billing.aws_route.rt_private_1b: Creation complete after 0s (ID: [REDACTED])
module.vpc_peering_billing.aws_route.rt_private_1a: Creation complete after 0s (ID: [REDACTED])
Apply complete! Resources: 4 added, 1 changed, 0 destroyed.
答案
只需将路由部分从aws_route_table的创建中移出,那么以后所有aws_route的创建(例如vpc_peering)都不会与在aws_route_table外部创建的路由冲突原代码:
# Create crt with nat
resource "aws_route_table" "tf_portal_private_crt"
count = length(data.aws_availability_zones.available.names)
vpc_id = aws_vpc.tf_portal_vpc.id
route
//associated subnet can reach everywhere
cidr_block = "0.0.0.0/0"
//CRT uses this nat to reach internet
nat_gateway_id = aws_nat_gateway.tf_portal_nat.id
tags =
Name = "$var.portal_private_crt_name_$count.index + 1"
新代码:
# Create crt with nat
resource "aws_route_table" "tf_portal_private_crt"
count = length(data.aws_availability_zones.available.names)
vpc_id = aws_vpc.tf_portal_vpc.id
tags =
Name = "$var.portal_private_crt_name_$count.index + 1"
resource "aws_route" "tf_portal_private"
count = length(data.aws_availability_zones.available.names)
route_table_id = element(aws_route_table.tf_portal_private_crt.*.id, count.index)
destination_cidr_block = "0.0.0.0/0"
nat_gateway_id = aws_nat_gateway.tf_portal_nat.id
以上是关于Terraform删除路由表,然后在第二次运行时将其添加(无更改)。错误或我缺少什么吗?的主要内容,如果未能解决你的问题,请参考以下文章