【问题标题】:Problems in creating aws route table using terraform使用 terraform 创建 aws 路由表的问题
【发布时间】:2021-12-04 21:59:00
【问题描述】:

在 Mac 上使用 AWS 插件 v3.63.0 运行 terraform v1.0.9

按照 hashcorp 说明创建路由表 (https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route_table),但出现以下错误:

Error: Incorrect attribute value type
...
Inappropriate value for attribute "route": element 0: attributes "carrier_gateway_id", "destination_prefix_list_id", "egress_only_gateway_id",
│ "instance_id", "ipv6_cidr_block", "local_gateway_id", "nat_gateway_id", "network_interface_id", "transit_gateway_id", "vpc_endpoint_id", and
│ "vpc_peering_connection_id" are required.

这是我的 main.tf:

provider "aws" {
  region = "us-east-1"
}

resource "aws_vpc" "my-test-vpc" {
  cidr_block = "10.0.0.0/16"
  tags = {
    Name = "my-test-vpc"
  }
}

resource "aws_internet_gateway" "gw" {
  vpc_id = aws_vpc.my-test-vpc.id
}

resource "aws_route_table" "prod-route-table" {
  vpc_id = aws_vpc.my-test-vpc.id

  route = [
    {
      cidr_block = "0.0.0.0/0"
      gateway_id = aws_internet_gateway.gw.id
    }
  ]

  tags = {
    Name = "production"
  }
}

【问题讨论】:

  • IPV6 IP 是全球唯一的,因此默认情况下是公开的 - 当您尝试将常规互联网网关分配给 IPV6 CIDR 块时,它可能会出错;删除该块有效吗?该指南使用仅出口 IG,而不是常规 IG。
  • @ErmiyaEskandary - 它没有帮助
  • 所以删除整个 IPV6 CIDR 块并不能解决问题?如果是这样,请编辑您的问题以将其删除以包含 Minimal, Reproducible Example

标签: amazon-web-services terraform aws-route-table


【解决方案1】:

我遇到了类似的事情,但没有找到根本原因,所以这不是最好的答案,但是将路由移到它自己的显式资源中对我有用:

resource "aws_route_table" "prod-route-table" {
  vpc_id = aws_vpc.my-test-vpc.id

  tags = {
    Name = "production"
  }
}

resource "aws_route" "prod-route-igw" {
  route_table_id            = aws_route_table.prod-route-table.id
  destination_cidr_block    = "0.0.0.0/0"
  gateway_id                = aws_internet_gateway.gw.id
  depends_on                = [aws_route_table.prod-route-table]
}

【讨论】:

    【解决方案2】:

    非常简单。但是您似乎没有注意到您没有遵循语法。它总是 route {#config} 不像 route = { #config }

    【讨论】:

    • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 2020-05-14
    • 2021-08-21
    • 1970-01-01
    • 2020-08-05
    • 2017-10-02
    • 1970-01-01
    • 2021-12-14
    • 2021-01-01
    • 2021-06-06
    相关资源
    最近更新 更多