vpc 和 vpc 对等模块之间的 Terraform 状态冲突
Terraform state conflict between vpc and vpc-peering modules
我正在为我的公司 aws 基础设施使用 terraform 和 terragrunt,一般结构是这样的,我有两个主文件夹,一个用于模块,另一个用于环境和使用 terragrunt 将模块采购到环境文件夹,一个模块用于一般的 vpc 基础设施,我有单独的 vpc-peering 模块,我在环境文件夹中为 vpc 和 vpc-peering 创建了单独的文件夹,所以它们在 s3 上有不同的 terraform 状态,问题是 vpc-peering 正在创建路由表另外,当我想在 vpc 模块上应用一些更改时,它会删除从 vpc-peering 模块创建的记录,有没有办法将路由表注入 vpc 模块?我知道我可以将 vpc-peering 模块移动到 vpc 中并同时拥有两个模块,但是重写所有内容需要相当长的时间,我很想知道任何其他方式。
他们不应该同时创建路由表。 VPC 模块应该创建路由表,VPC 对等模块应该向这些路由表添加路由。这里的技巧是不在 aws_route_table
资源中创建任何路由,而是将它们全部创建为单独的 aws_route
资源。根据 aws_route
documentation 中的注释:
Terraform currently provides both a standalone Route resource and a
Route Table resource with routes defined in-line. At this time you
cannot use a Route Table with in-line routes in conjunction with any
Route resources. Doing so will cause a conflict of rule settings and
will overwrite rules.
因此,为了在多个模块中定义路由,您需要为所有路由定义使用 aws_route
资源。
我不确定您是否使用 git 作为 terraform 的源代码,如果是,那么您可以将模块保存在单独的 git 存储库中并为路由调用模块 table如你所愿。
例如。 :
resouces "aws_route" "public_igw_route" {
source = "git@github.com:user/infra-modules.git//aws-route"
}
我正在为我的公司 aws 基础设施使用 terraform 和 terragrunt,一般结构是这样的,我有两个主文件夹,一个用于模块,另一个用于环境和使用 terragrunt 将模块采购到环境文件夹,一个模块用于一般的 vpc 基础设施,我有单独的 vpc-peering 模块,我在环境文件夹中为 vpc 和 vpc-peering 创建了单独的文件夹,所以它们在 s3 上有不同的 terraform 状态,问题是 vpc-peering 正在创建路由表另外,当我想在 vpc 模块上应用一些更改时,它会删除从 vpc-peering 模块创建的记录,有没有办法将路由表注入 vpc 模块?我知道我可以将 vpc-peering 模块移动到 vpc 中并同时拥有两个模块,但是重写所有内容需要相当长的时间,我很想知道任何其他方式。
他们不应该同时创建路由表。 VPC 模块应该创建路由表,VPC 对等模块应该向这些路由表添加路由。这里的技巧是不在 aws_route_table
资源中创建任何路由,而是将它们全部创建为单独的 aws_route
资源。根据 aws_route
documentation 中的注释:
Terraform currently provides both a standalone Route resource and a Route Table resource with routes defined in-line. At this time you cannot use a Route Table with in-line routes in conjunction with any Route resources. Doing so will cause a conflict of rule settings and will overwrite rules.
因此,为了在多个模块中定义路由,您需要为所有路由定义使用 aws_route
资源。
我不确定您是否使用 git 作为 terraform 的源代码,如果是,那么您可以将模块保存在单独的 git 存储库中并为路由调用模块 table如你所愿。
例如。 :
resouces "aws_route" "public_igw_route" {
source = "git@github.com:user/infra-modules.git//aws-route"
}