【问题标题】:aws_elb terraform error failed to load root config moduleaws_elb terraform 错误无法加载根配置模块
【发布时间】:2025-12-01 08:00:02
【问题描述】:

这是 main.tf 中 aws_elb 的代码块。

resource "aws_elb" "terraformelb" {
  name = "terraformelb"
  subnets         = ["${aws_subnet.public_subnet.id}"]
  security_groups = ["${aws_security_group.web_sg.id}"]
  instances       = ["${aws_instance.web_*.id}"]
  listener {
    instance_port     = 80
    instance_protocol = "http"
    lb_port           = 80
    lb_protocol       = "http"
  }
}

我遵循了 terraform 语法,但仍然出现错误

Failed to load root config module: Error loading C:\Users\snadella001\Downloads\Terraform\repo\main.tf: Error reading config for aws_elb[terraform-elb]: parse error at 1:21: expected expression but found "."

【问题讨论】:

    标签: amazon-web-services amazon-elb terraform


    【解决方案1】:

    错误消息是针对资源terraform-elb(名称中的减号)

    但是你的资源名称是terraformelb

    您需要确保名称相同。

    【讨论】:

    • 我认为我的文件之前没有保存。我保存了文件并运行了 terraform plan,但仍然出现相同的错误。无法加载根配置模块:加载 C:\Users\snadella001\Downloads\Terraform\repo\main.tf 时出错:读取 aws_elb[terraformelb] 的配置时出错:在 1:21 解析错误:预期表达式但找到了“。”
    【解决方案2】:

    看起来你的实例部分是错误的,它应该看起来像这样,我猜(看不到你的代码的其余部分):

    instances = ["${aws_instance.web.*.id}"]

    【讨论】:

      最近更新 更多