aws_route_table_association
每次我运行计划/应用时,都会强制重新创建两个资源:
Terraform will perform the following actions:
<= module.mon.data.aws_subnet_ids.snetid
id: <computed>
ids.#: <computed>
tags.%: "1"
tags.Name: "zencopl-mon-*"
vpc_id: "vpc-0xxxxxxxxxxxxxxf"
-/+ module.mon.aws_route_table_association.snet[0] (new resource required)
id: "rtbassoc-058a3a92f42c51c9b" => <computed> (forces new resource)
route_table_id: "rtb-05401d41b7281d81f" => "rtb-05401d41b7281d81f"
subnet_id: "subnet-032a4ee6fc6ebe945" => "${data.aws_subnet_ids.snetid.ids[count.index]}" (forces new resource)
-/+ module.mon.aws_route_table_association.snet[1] (new resource required)
id: "rtbassoc-09858f67c89412e90" => <computed> (forces new resource)
route_table_id: "rtb-05401d41b7281d81f" => "rtb-05401d41b7281d81f"
subnet_id: "subnet-0bd026945b213219d" => "${data.aws_subnet_ids.snetid.ids[count.index]}" (forces new resource)
看起来,这是因为我定义了数据源来获取子网 ID:
data "aws_subnet_ids" "snetid" {
vpc_id = "${var.vpc_ids[var.idx]}"
depends_on = [ "aws_subnet.snets" ]
tags = {
Name = "${var.vpc_names[var.idx]}-${var.inst_role}-*"
}
}
然后像这样使用:
locals {
a_zones = ["${slice(data.aws_availability_zones.azs.names,0,2)}"]
}
#
resource "aws_route_table_association" "snet" {
count = "${length(local.a_zones)}"
route_table_id = "${aws_route_table.rtb.id}"
subnet_id = "${data.aws_subnet_ids.snetid.ids[count.index]}"
depends_on = [ "aws_subnet.snets" ]
}
#
module "mon" {
source = "../../modules/core-network"
idx = "0"
inst_role = "mon"
vpc_names = "${module.vpc.vpc_names}"
vpc_ids = "${module.vpc.vpc_ids}"
......
......
}
我无法找出哪里出了问题(或者是不是一个错误)。我尝试使用,
lifecycle { ignore_changes = [ .... ]}
但无法弄清楚应该忽略什么。虽然它没有造成任何实际问题(从部署方面来看),但却造成了很多混乱,我真的很想修复它。有人能指出我做错了什么或遗漏了什么吗?提前谢谢!!
—桑