如何terraform导入VPC的AWS默认路由表?

Pyr*_*bie 3 terraform terraform-provider-aws

此处的文档: https: //www.terraform.io/docs/providers/aws/r/default_route_table.html声称您可以使用 VPC id 导入默认路由表。

当我尝试这样做时,出现以下错误:

$ terraform import 'aws_default_route_table.aws-vpc' vpc-12345678

Error: resource aws_default_route_table doesn't support import
Run Code Online (Sandbox Code Playgroud)

我尝试使用路由表 ID 本身,以防文档不准确,但我得到了相同的错误。

我成功导入了路由表所属的VPC,并再次尝试导入路由表,但没有成功。

对于上下文 - 我需要导入默认路由表的原因是为 VPN 网关启用路由传播,如下所示:

resource aws_default_route_table aws-vpc {
  default_route_table_id = var.aws_default_route_table_id
  route {
    cidr_block = "0.0.0.0/0"
    gateway_id = var.aws_internet_gateway_id
  }
  propagating_vgws = [
    aws_vpn_gateway.aws-vpn-gw.id
  ]
}
Run Code Online (Sandbox Code Playgroud)

我是否遗漏了一些东西,或者真的不可能将现有的默认路由表导入到 terraform 中?

Pyr*_*bie 7

我跳得太快到导入部分了。在同一文档https://www.terraform.io/docs/providers/aws/r/default_route_table.html的开头有这样的子句:

The aws_default_route_table behaves differently from normal resources, in that Terraform does not create this resource, but instead attempts to "adopt" it into management. We can do this because each VPC created has a Default Route Table that cannot be destroyed, and is created with a single route.
Run Code Online (Sandbox Code Playgroud)

所以,TL;DR你不能导入,但你可以尝试创建一个现有的路由表,terraform将“采用”它,效果将与导入现有资源相同。