You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Terraform aws_lb_listener模板default_action报错,请求解排查

问题原因及修复方案

核心问题

你遇到的错误本质是**fixed_response的写法不符合对应AWS Provider版本的语法要求**。Terraform 1.2.9搭配的AWS Provider如果是v3.x及以上版本,fixed_response需要以嵌套块的形式定义,而非你当前使用的map键值对格式。

另外代码里存在一个笔误:certificate_arn = "${aws_acm_certificate.acm.arm}"中的arm应为arn,该错误会导致后续无法正确引用证书ARN,需要一并修正。

修正后的代码

resource "aws_lb_listener" "HTTPS443" {
  load_balancer_arn = aws_lb.alb.arn
  port              = "443"
  protocol          = "HTTPS"
  ssl_policy        = "ELBSecurityPolicy-TLS-1-0-2015-04"
  certificate_arn   = aws_acm_certificate.acm.arn # 修正笔误并简化插值写法

  default_action {
    type = "fixed-response"

    # 将原map格式改为嵌套块格式
    fixed_response {
      content_type = "application/json"
      message_body = "Nothing to see here"
      status_code  = "200"
    }
  }
}

补充说明

  • Terraform 1.2.9支持直接引用资源属性(如aws_acm_certificate.acm.arn),无需使用${}插值语法,简化写法后更易读。
  • 确保你的AWS Provider版本符合语法要求:若使用v3.0及以上版本,必须用嵌套块形式定义fixed_response;若使用更旧的Provider版本则可能需要保留map格式,但建议升级到稳定版本以兼容Terraform 1.2.9。

内容的提问来源于stack exchange,提问作者igalsc

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 23:05:17