【发布时间】:2021-01-09 07:39:59
【问题描述】:
我在将路线转换为动态路线时遇到了问题。
默认情况下,我有 3 个可用区域,每个区域都有自己的 nat 网关,当我尝试使用这些 nat gateways 时,我收到了不同类型的错误。
这是nat.tf的输出(返回>列表[字符串])
output "nat_ids" {
description = "The id of created nat gateway"
value = aws_nat_gateway.nat.*.id
}
这里是aws_route_table的块
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.
我的问题是什么?我做错了什么? 我尝试了很多选项,例如
element(concat(lookup(route.value, "nat", "" ), [""]), count.index)
element(lookup(route.value, "nat"), count.index)
compact(split(",", lookup(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"
}
]
}
}
我希望我的帖子也能对遇到同样问题的其他人有所帮助,我希望它不会太长,我尽量减少代码。期待您的 cmets 和答案。 internet gateway 是没有问题的
【问题讨论】:
标签: amazon-web-services terraform terraform-provider-aws