【问题标题】:The module root could not be found. There is nothing to output找不到模块根目录。没有什么可以输出
【发布时间】:2017-06-14 11:30:55
【问题描述】:

在我的 Terraform 根目录中运行 terraform output 我得到:

The module root could not be found. There is nothing to output.

我有以下文件:

iam.tf:

resource "aws_iam_user" "a_user" {
  name = "a_user"
}

output.tf:

data "aws_caller_identity" "current" {}

output "account_id" {
  value = "${data.aws_caller_identity.current.account_id}"
}

这个https://www.terraform.io/docs/modules/index.html 说:

Root module That is the current working directory when you run terraform apply or get, holding the Terraform configuration files. It is itself a valid module.

知道为什么会出现错误消息以及如何修复吗?

【问题讨论】:

    标签: terraform


    【解决方案1】:

    Terraform 引用 root module 来自 terraform.tfstate 文件。

    此文件包含来自.tf 文件以及output variables 的有关您最后已知状态的所有信息。

    第一次执行terraform apply命令进入当前目录后生成。

    只需运行terraform apply ,然后terraform output 将显示您的输出变量。

    【讨论】:

      【解决方案2】:

      你没有在上面添加你的模块配置,但是假设你有一个模块文件,那么你必须告诉 terraform 源。如果源是与 iam.tf 和 output.tf 位于同一位置的名为 example 的子目录,那么您必须按如下方式添加模块,然后从 output.tf 和 iam.tf 所在的目录运行 terraform apply:

      module "consul" {
        source = "./example"
      
      }
      

      如果您的输出是远程位置(例如 github),则源必须如下所示

      module "consul" {
        source = "github.com/some-git.git"
      
      }
      

      然后你必须运行“terraform get”来下载你的模块。然后“terraform apply”应用模块,然后“terraform output”列出您在上面指定的输出

      【讨论】:

        【解决方案3】:

        问题是你没有添加你的模块配置文件。一起来的东西

        module "test_module" {
          source = "./test_module"
        }
        

        您必须确保模块配置存在并且来源有效。要获得输出,您需要一个在运行 terraform apply 后创建的状态文件。看起来您要么没有,要么状态文件中没有输出。

        【讨论】:

          猜你喜欢
          • 2021-06-29
          • 2012-01-21
          • 2022-12-07
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-04-20
          • 2014-07-14
          • 2013-12-16
          相关资源
          最近更新 更多