Amazon web services Terraform:动态路由表路由,无法从字符串列表中检索元素
我在将路线转换为动态路线时遇到了一个问题。 默认情况下,我有3个可用性区域,每个区域都有自己的nat网关,当我尝试使用这些Amazon web services Terraform:动态路由表路由,无法从字符串列表中检索元素,amazon-web-services,terraform,terraform-provider-aws,Amazon Web Services,Terraform,Terraform Provider Aws,我在将路线转换为动态路线时遇到了一个问题。 默认情况下,我有3个可用性区域,每个区域都有自己的nat网关,当我尝试使用这些nat网关时,我收到了不同类型的错误 这是nat.tf的输出(返回>列表[字符串]) 这是aws_route_表的块 resource "aws_route_table" "route" { count = length(var.subnets) vpc_id
nat网关时,我收到了不同类型的错误
这是nat.tf
的输出(返回>列表[字符串])
这是aws_route_表的块
resource "aws_route_table" "route" {
count = length(var.subnets)
vpc_id = var.vpc_id
# Route Table For IPv4
dynamic "route" {
for_each = var.route_table_ipv4
content {
cidr_block = lookup(route.value, "cidrblock", "" )
gateway_id = lookup(route.value, "igw", "" )
instance_id = lookup(route.value, "instance", "" )
nat_gateway_id = compact(split(",", lookup(route.value, "nat", "")))
vpc_endpoint_id = lookup(route.value, "vpc_endpoint", "" )
local_gateway_id = lookup(route.value, "local_gateway", "" )
transit_gateway_id = lookup(route.value, "transit_gateway", "" )
network_interface_id = lookup(route.value, "network_interface", "" )
vpc_peering_connection_id = lookup(route.value, "vpc_peering", "" )
}
}
tags = var.map_tags
}
以下是错误消息:
Error: Invalid value for module argument
on main.tf line 211, in module "private_routing":
211: route_table_ipv4 = local.route_table_ipv4.private
The given value is not suitable for child module variable "route_table_ipv4"
defined at ../Resources/Network/Routings/variables.tf:107,1-28: element 0:
element "nat": string required.
Error: Incorrect attribute value type
on ../Resources/Network/Routings/main.tf line 28, in resource "aws_route_table" "route":
28: nat_gateway_id = compact(split(",", lookup(route.value, "nat", "")))
Inappropriate value for attribute "nat_gateway_id": string required.
我有什么问题?我做错了什么?
我尝试过很多选择,比如
元素(concat(查找(route.value,“nat”,“”),[“”),count.index)
元素(查找(route.value,“nat”),count.index)
compact(拆分(“,”,查找(route.value,“nat”,”)
这是主模块中的变量和声明方式
variable "route_table_ipv4" {
description = "The list of routes for IPv4 'CIDR' block(s)"
type = list(map(string))
default = null
}
. . . other modules . . .
route_table_ipv4 = local.route_table_ipv4.private
. . . other modules . . .
locals{
route_table_ipv4 = {
private = [
{
nat = module.gateways.nat_ids
cidrblock = "0.0.0.0/0"
}
]
}
}
我希望我的帖子也能对其他面临同样问题的人有所帮助,我希望不会太长,我尽了最大努力减少代码。期待您的评论和回答。互联网网关没有问题
,以防您发现我犯了一个打字错误我找到了解决方案
1-我已将变量的输入错误更改为任何
2-我使用连接到nat网关的输出,而不是在资源中,我只是拆分和计算索引
variable "route_table_ipv4" {
description = "The list of routes for IPv4 'CIDR' block(s)"
type = list(map(string))
default = null
}
. . . other modules . . .
route_table_ipv4 = local.route_table_ipv4.private
. . . other modules . . .
locals{
route_table_ipv4 = {
private = [
{
nat = module.gateways.nat_ids
cidrblock = "0.0.0.0/0"
}
]
}
}