Terraform:“inputMap”参数的值无效:lookup() 需要地图作为第一个参数
Posted
技术标签:
【中文标题】Terraform:“inputMap”参数的值无效:lookup() 需要地图作为第一个参数【英文标题】:Terraform : Invalid value for "inputMap" parameter: lookup() requires a map as the first argument 【发布时间】:2022-01-12 11:49:14 【问题描述】:我尝试通过 terraform 为 alertmanager 设置 lb,但在代码方面遇到了一些困难。你能帮忙吗?在那里你可以找到来自 terraform 的代码: 我之前使用我的代码来创建没有 cognito 模块的 lb,但是在我添加 cognito auth 之后我不能再使用它了。
带有警报管理器的磅:
source = "../../modules/aws-lb"
vpc_id = module.vpc.id
default_security_group_id = module.vpc.default_security_group_id
tags = local.tags
prefix = "$var.environment-euc1"
target_groups =
alertmanager =
connect = "HTTP:9093"
target_type = "ip"
health_check =
path = "/-/healthy"
matcher = 200
listeners =
"HTTP:80" =
actions =
default =
type = "redirect"
"HTTPS:443" =
certificates_arns = [module.certificate_lb.arn]
actions =
default = [
type = "forward"
group = "alertmanager"
,
type = "authenticate-cognito"
authenticate_cognito =
user_pool_arn = module.aws_cognito_user_pool.arn
user_pool_client_id = module.aws_cognito_user_pool.id["alertmanager"]
user_pool_domain = module.aws_cognito_user_pool.domain
]
```
Error from terraform output:
│ Error: Invalid function argument
│
│ on ../../modules/aws-lb/lb.tf line 25, in resource "aws_lb_listener" "listener":
│ 25: type = lookup(default_action.value, "type", "forward")
│ ├────────────────
│ │ default_action.value is tuple with 2 elements
│
│ Invalid value for "inputMap" parameter: lookup() requires a map as the first argument.
on ../../modules/aws-lb/lb.tf line 26, in resource "aws_lb_listener" "listener":
│ 26: target_group_arn = lookup(default_action.value, "type", "forward") == "forward" ? aws_lb_target_group.tg[default_action.value.group].id : null
│ ├────────────────
│ │ default_action.value is tuple with 2 elements
│
│ Invalid value for "inputMap" parameter: lookup() requires a map as the first argument.
If you need more details, I can add.
【问题讨论】:
【参考方案1】:听众:
resource "aws_lb_listener" "listener"
for_each = var.listeners
load_balancer_arn = aws_lb.lb.id
port = split(":", each.key)[1]
protocol = split(":", each.key)[0]
ssl_policy = lookup(each.value, "certificates_arns", null) == null ? null : lookup(each.value, "ssl_policy", "ELBSecurityPolicy-FS-1-2-Res-2019-08")
certificate_arn = length(lookup(each.value, "certificates_arns", [])) > 0 ? each.value["certificates_arns"][0] : null
dynamic "default_action"
for_each = "default" = each.value["actions"]["default"]
content
type = lookup(default_action.value, "type", "forward")
target_group_arn = lookup(default_action.value, "type", "forward") == "forward" ? aws_lb_target_group.tg[default_action.value.group].id : null
dynamic "redirect"
for_each = toset(lookup(default_action.value, "type", "forward") == "redirect" ? ["default"] : [])
content
port = "443"
protocol = "HTTPS"
status_code = "HTTP_301"
dynamic "authenticate_cognito"
for_each = toset(lookup(default_action.value, "type", "forward") == "authenticate-cognito" ? each.value["authenticate_cognito"] : [])
content
user_pool_arn = authenticate_cognito.value["user_pool_arn"]
user_pool_client_id = authenticate_cognito.value["user_pool_client_id"]
user_pool_domain = authenticate_cognito.value["user_pool_domain"]
【讨论】:
以上是关于Terraform:“inputMap”参数的值无效:lookup() 需要地图作为第一个参数的主要内容,如果未能解决你的问题,请参考以下文章
ClassCastException:javax.swing.plaf.FontUIResource 无法转换为 javax.swing.InputMap